houqp commented on a change in pull request #1066:
URL: https://github.com/apache/arrow-datafusion/pull/1066#discussion_r721055690
##########
File path: datafusion/src/physical_plan/expressions/cast.rs
##########
@@ -95,6 +95,24 @@ impl PhysicalExpr for CastExpr {
}
}
+impl CastExpr {
+ pub(crate) fn cast_scalar_default_options(
+ scalar: ScalarValue,
+ cast_type: &DataType,
+ ) -> Result<ScalarValue> {
+ CastExpr::cast_scalar_type(scalar, cast_type,
&DEFAULT_DATAFUSION_CAST_OPTIONS)
+ }
+ pub(crate) fn cast_scalar_type(
Review comment:
nitpick, perhaps these can be implemented as simple pub(crate) functions
like the `cast_column` function below? Any reason why we want to make it a
struct method?
##########
File path: datafusion/src/physical_plan/functions.rs
##########
@@ -1428,6 +1460,423 @@ where
})
}
+pub(crate) fn create_immutable_impl(
Review comment:
looks like lots of duplication between this and `create_physical_fun`,
would be good to refactor and reuse the code so they don't get out of sync.
##########
File path: datafusion/src/optimizer/tokomak/rules/simplification.rs
##########
@@ -0,0 +1,181 @@
+use crate::error::DataFusionError;
+
+use super::super::{Tokomak, TokomakExpr};
+
+use super::utils::*;
+use egg::{rewrite as rw, *};
+
+pub fn add_simplification_rules(optimizer: &mut Tokomak) {
+ for rule in rules() {
+ optimizer.add_rule(rule)
+ }
+}
+
+fn rules() -> Vec<Rewrite<TokomakExpr, ()>> {
+ let a: Var = "?a".parse().unwrap();
+ let b: Var = "?b".parse().unwrap();
+ let c: Var = "?c".parse().unwrap();
+ let d: Var = "?d".parse().unwrap();
+ let x: Var = "?x".parse().unwrap();
+ vec![
+ rw!("commute-add"; "(+ ?x ?y)" => "(+ ?y ?x)"),
+ rw!("commute-mul"; "(* ?x ?y)" => "(* ?y ?x)"),
+ rw!("commute-and"; "(and ?x ?y)" => "(and ?y ?x)"),
+ rw!("commute-or"; "(or ?x ?y)" => "(or ?y ?x)"),
+ rw!("commute-eq"; "(= ?x ?y)" => "(= ?y ?x)"),
+ rw!("commute-neq"; "(<> ?x ?y)" => "(<> ?y ?x)"),
+ rw!("converse-gt"; "(> ?x ?y)" => "(< ?y ?x)"),
+ rw!("converse-gte"; "(>= ?x ?y)" => "(<= ?y ?x)"),
+ rw!("converse-lt"; "(< ?x ?y)" => "(> ?y ?x)"),
+ rw!("converse-lte"; "(<= ?x ?y)" => "(>= ?y ?x)"),
+ rw!("add-0"; "(+ ?x 0)" => "?x"),
+ rw!("add-assoc"; "(+ (+ ?a ?b) ?c)" => "(+ ?a (+ ?b ?c))"),
+ rw!("minus-0"; "(- ?x 0)" => "?x"),
Review comment:
missing mul-0 and 0-div?
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]