Lordworms commented on code in PR #13128:
URL: https://github.com/apache/datafusion/pull/13128#discussion_r1818194880
##########
datafusion/optimizer/src/simplify_expressions/utils.rs:
##########
@@ -341,3 +355,49 @@ pub fn distribute_negation(expr: Expr) -> Expr {
_ => Expr::Negative(Box::new(expr)),
}
}
+
Review Comment:
I'll refactor that
##########
datafusion/optimizer/src/simplify_expressions/expr_simplifier.rs:
##########
@@ -835,40 +835,38 @@ impl<'a, S: SimplifyInfo> TreeNodeRewriter for
Simplifier<'a, S> {
left,
op: Or,
right,
- }) if expr_contains(&left, &right, Or) => Transformed::yes(*left),
+ }) if expr_contains(&left, &right, Or)? => Transformed::yes(*left),
// A OR (..A..) --> (..A..)
Expr::BinaryExpr(BinaryExpr {
left,
op: Or,
right,
- }) if expr_contains(&right, &left, Or) => Transformed::yes(*right),
+ }) if expr_contains(&right, &left, Or)? =>
Transformed::yes(*right),
// A OR (A AND B) --> A
Expr::BinaryExpr(BinaryExpr {
left,
op: Or,
right,
- }) if is_op_with(And, &right, &left) => Transformed::yes(*left),
+ }) if is_op_with(And, &right, &left)? => Transformed::yes(*left),
// (A AND B) OR A --> A
Expr::BinaryExpr(BinaryExpr {
left,
op: Or,
right,
- }) if is_op_with(And, &left, &right) => Transformed::yes(*right),
+ }) if is_op_with(And, &left, &right)? => Transformed::yes(*right),
// Eliminate common factors in conjunctions e.g
// (A AND B) OR (A AND C) -> A AND (B OR C)
Expr::BinaryExpr(BinaryExpr {
left,
op: Or,
right,
- }) if has_common_conjunction(&left, &right) => {
+ }) if has_common_conjunction(&left, &right)? => {
Review Comment:
I checked postgresql and duckdb, they seems to merge the volatile expressions

<img width="945" alt="image"
src="https://github.com/user-attachments/assets/1b838b93-04e2-40ed-8bf5-4e225df0c7a1">
##########
datafusion/optimizer/src/simplify_expressions/expr_simplifier.rs:
##########
@@ -835,40 +835,38 @@ impl<'a, S: SimplifyInfo> TreeNodeRewriter for
Simplifier<'a, S> {
left,
op: Or,
right,
- }) if expr_contains(&left, &right, Or) => Transformed::yes(*left),
+ }) if expr_contains(&left, &right, Or)? => Transformed::yes(*left),
// A OR (..A..) --> (..A..)
Expr::BinaryExpr(BinaryExpr {
left,
op: Or,
right,
- }) if expr_contains(&right, &left, Or) => Transformed::yes(*right),
+ }) if expr_contains(&right, &left, Or)? =>
Transformed::yes(*right),
// A OR (A AND B) --> A
Expr::BinaryExpr(BinaryExpr {
left,
op: Or,
right,
- }) if is_op_with(And, &right, &left) => Transformed::yes(*left),
+ }) if is_op_with(And, &right, &left)? => Transformed::yes(*left),
// (A AND B) OR A --> A
Expr::BinaryExpr(BinaryExpr {
left,
op: Or,
right,
- }) if is_op_with(And, &left, &right) => Transformed::yes(*right),
+ }) if is_op_with(And, &left, &right)? => Transformed::yes(*right),
// Eliminate common factors in conjunctions e.g
// (A AND B) OR (A AND C) -> A AND (B OR C)
Expr::BinaryExpr(BinaryExpr {
left,
op: Or,
right,
- }) if has_common_conjunction(&left, &right) => {
+ }) if has_common_conjunction(&left, &right)? => {
Review Comment:
Sure
--
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]