Skip to content

Commit

Permalink
ok
Browse files Browse the repository at this point in the history
  • Loading branch information
andicuko committed Jun 20, 2024
1 parent 6d30ca3 commit eaa8636
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
19 changes: 11 additions & 8 deletions src/data_type/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1945,14 +1945,17 @@ pub fn extract_year() -> impl Function {
}

pub fn extract_epoch() -> impl Function {
Polymorphic::from((
Pointwise::univariate(data_type::DateTime::default(), DataType::integer(), |a| {
(a.and_utc().timestamp() as i64).into()
}),
Pointwise::univariate(data_type::Duration::default(), DataType::integer(), |a| {
(a.num_seconds()).into()
}),
))
Polymorphic::default()
.with(PartitionnedMonotonic::univariate(
data_type::DateTime::default(),
|a| {
(a.and_utc().timestamp() as i64).clamp(<i64 as Bound>::min(), <i64 as Bound>::max())
},
))
.with(PartitionnedMonotonic::univariate(
data_type::Duration::default(),
|a| (a.num_seconds()).clamp(<i64 as Bound>::min(), <i64 as Bound>::max()),
))
}

pub fn extract_month() -> impl Function {
Expand Down
11 changes: 7 additions & 4 deletions src/dialect_translation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -628,8 +628,8 @@ macro_rules! relation_to_query_tranlator_trait_constructor {
Millisecond
);

fn extract_week(&self, expr: &expr::Expr)-> ast::Expr {
let ast_expr=self.expr(expr);
fn extract_week(&self, expr: &expr::Expr) -> ast::Expr {
let ast_expr = self.expr(expr);
extract_builder(ast_expr, ast::DateTimeField::Week(None))
}

Expand Down Expand Up @@ -897,8 +897,11 @@ fn unary_op_builder(op: ast::UnaryOperator, expr: ast::Expr) -> ast::Expr {
}

fn extract_builder(expr: ast::Expr, datetime_field: ast::DateTimeField) -> ast::Expr {
ast::Expr::Extract { field: datetime_field, expr: Box::new(expr) }
}
ast::Expr::Extract {
field: datetime_field,
expr: Box::new(expr),
}
}

pub struct RelationWithTranslator<'a, T: RelationToQueryTranslator>(pub &'a Relation, pub T);

Expand Down

0 comments on commit eaa8636

Please sign in to comment.