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


##########
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:
   Emm, This code runs in CSE phase, instead of the statement execution phase. 
It stands to reason that there should be no impact on execution, but are you 
referring specifically to the scenario where you use `datafusion-cli` to run 
statements? This function will only be invoked on `Eq` when the hash value of 
the node is the same, and the frequency should not be high, and the normalized 
comparison should be the same time complexity as the original node direct 
comparison.



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