peter-toth commented on code in PR #13315:
URL: https://github.com/apache/datafusion/pull/13315#discussion_r1843848953
##########
datafusion/expr/src/expr.rs:
##########
@@ -1674,6 +1674,69 @@ impl Expr {
}
}
+impl Normalizeable for Expr {
+ fn can_normalize(&self) -> bool {
+ #[allow(clippy::match_like_matches_macro)]
+ match self {
+ Expr::BinaryExpr(BinaryExpr {
+ op:
+ _op @ (Operator::Plus
+ | Operator::Multiply
+ | Operator::BitwiseAnd
+ | Operator::BitwiseOr
+ | Operator::BitwiseXor
+ | Operator::Eq
+ | Operator::NotEq),
+ ..
+ }) => true,
+ _ => false,
+ }
+ }
+}
+
+impl NormalizeEq for Expr {
+ fn normalize_eq(&self, other: &Self) -> bool {
+ match (self, other) {
+ (
+ Expr::BinaryExpr(BinaryExpr {
+ left: self_left,
+ op: self_op,
+ right: self_right,
+ }),
+ Expr::BinaryExpr(BinaryExpr {
+ left: other_left,
+ op: other_op,
+ right: other_right,
+ }),
+ ) => {
+ if self_op != other_op {
+ return false;
+ }
+
+ if matches!(
+ self_op,
+ Operator::Plus
+ | Operator::Multiply
+ | Operator::BitwiseAnd
+ | Operator::BitwiseOr
+ | Operator::BitwiseXor
+ | Operator::Eq
+ | Operator::NotEq
+ ) {
+ (self_left.normalize_eq(other_left)
+ && self_right.normalize_eq(other_right))
+ || (self_left.normalize_eq(other_right)
+ && self_right.normalize_eq(other_left))
+ } else {
+ self_left.normalize_eq(other_left)
+ && self_right.normalize_eq(other_right)
+ }
+ }
+ (_, _) => self == other,
Review Comment:
Yeah, that is not easy to handle now, but IMO this PR looks great without
that as well.
Actually, I'm working on something that stores and updates certain
statistics and properties (like the hash) of tree nodes automatically during
transformations. I think once the hashes of a node's children will be cheap we
can use it to sort the children and call `normalize_eq()` on the pairs.
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]