peter-toth commented on code in PR #13315:
URL: https://github.com/apache/datafusion/pull/13315#discussion_r1837816221
##########
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:
Yeah, I share the concerns of @jayzhan211. Also, the other case in this
method contains `.clone()` of `Expr`, which can be also costly.
I wonder if we could implement and use something like `fn
eq_normalized(&self, other: &Self) -> bool` instead of the current `fn
normalize(&self) -> Expr`.
--
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]