jayzhan211 commented on code in PR #13315:
URL: https://github.com/apache/datafusion/pull/13315#discussion_r1835961051
##########
datafusion/expr/src/expr.rs:
##########
@@ -1666,6 +1666,69 @@ impl Expr {
}
}
+impl NormalizeNode for Expr {
+ fn enable_normalized(&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,
+ }
+ }
+
+ fn normalize(&self) -> Expr {
+ match self {
+ Expr::BinaryExpr(BinaryExpr {
+ ref left,
+ ref op,
+ ref right,
+ }) => {
+ let normalized_left = left.normalize();
+ let normalized_right = right.normalize();
+ let new_binary = if matches!(
+ op,
+ Operator::Plus
+ | Operator::Multiply
+ | Operator::BitwiseAnd
+ | Operator::BitwiseOr
+ | Operator::BitwiseXor
+ | Operator::Eq
+ | Operator::NotEq
+ ) {
+ let (l_expr, r_expr) =
+ if format!("{normalized_left}") <
format!("{normalized_right}") {
Review Comment:
Will this slowdown the query? How about check equality for (left, right) and
(right, left) to determine the order?
##########
datafusion/expr/src/expr.rs:
##########
@@ -1666,6 +1666,69 @@ impl Expr {
}
}
+impl NormalizeNode for Expr {
+ fn enable_normalized(&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,
+ }
+ }
+
+ fn normalize(&self) -> Expr {
+ match self {
+ Expr::BinaryExpr(BinaryExpr {
+ ref left,
+ ref op,
+ ref right,
+ }) => {
+ let normalized_left = left.normalize();
+ let normalized_right = right.normalize();
+ let new_binary = if matches!(
+ op,
+ Operator::Plus
+ | Operator::Multiply
+ | Operator::BitwiseAnd
+ | Operator::BitwiseOr
+ | Operator::BitwiseXor
+ | Operator::Eq
+ | Operator::NotEq
+ ) {
+ let (l_expr, r_expr) =
+ if format!("{normalized_left}") <
format!("{normalized_right}") {
Review Comment:
Will this slowdown the query? How about checking the equality for (left,
right) and (right, left) to determine the order?
--
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]