zhuliquan commented on code in PR #13315:
URL: https://github.com/apache/datafusion/pull/13315#discussion_r1838514684


##########
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:
   Oh, I got it. Thanks for @peter-toth @jayzhan211 suggestion. I improve this 
code as below
   
https://github.com/apache/datafusion/blob/dda0848b14c9d773bbbbec7ff0477d969e6262f7/datafusion/expr/src/expr.rs#L1697-L1738



-- 
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]

Reply via email to