You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2021/10/25 09:53:29 UTC
[GitHub] [arrow-datafusion] rdettai commented on a change in pull request #1153: Generic constant expression evaluation
rdettai commented on a change in pull request #1153:
URL: https://github.com/apache/arrow-datafusion/pull/1153#discussion_r735394479
##########
File path: datafusion/src/optimizer/constant_folding.rs
##########
@@ -111,13 +118,17 @@ impl OptimizerRule for ConstantFolding {
}
}
-struct ConstantRewriter<'a> {
+/// Simplifies Exprs by applying algebriac transformation rules
+///
+/// For example
+/// `false && col` --> `col` for boolean types
+struct Simplifier<'a> {
Review comment:
```Rust
/// `false && col` --> `col` where `col` is a boolean types
```
Shouldn't that be: `true && col` --> `col` 😃
##########
File path: datafusion/src/optimizer/constant_folding.rs
##########
@@ -840,4 +794,38 @@ mod tests {
assert_eq!(actual, expected);
}
+
+ fn cast_to_int64_expr(expr: Expr) -> Expr {
+ Expr::Cast {
+ expr: expr.into(),
+ data_type: DataType::Int64,
+ }
+ }
+
+ #[test]
+ fn now_less_than_timestamp() {
+ let table_scan = test_table_scan().unwrap();
+
+ let ts_string = "2020-09-08T12:05:00+00:00";
+ let time = chrono::Utc.timestamp_nanos(1599566400000000000i64);
+
+ // now() < cast(to_timestamp(...) as int) + 5000000000
+ let plan = LogicalPlanBuilder::from(table_scan)
+ .filter(
+ now_expr()
+ .lt(cast_to_int64_expr(to_timestamp_expr(ts_string)) + lit(50000)),
+ )
+ .unwrap()
+ .build()
+ .unwrap();
+
+ // TODO constant folder hould be able to run again and fold
Review comment:
Why is it the `Simplifier` and not the `ConstEvaluator` that that fills in `now()` ? From a naive perspective, it looks more like an evaluation than an algebraic simplification 😃.
If we generalize a `ScalarFunction` can be const-evaluated if it has volatility in `{Immutable, Stable}` and all its arguments can be evaluated (including if it has 0 argument like `now()`)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org