zhuliquan opened a new pull request, #13235: URL: https://github.com/apache/datafusion/pull/13235
## Which issue does this PR close? ## Rationale for this change I notice that some expressions are semantically equivalent. (i.g. `a + b` and `b + a` is equivalent). I think their expressions can be optimized in CSE (i.e. common subexper eliminate) process. For example: we can optimize below logical plan. before: ```text Filter: (test.a + test.b) * (test.b + test.a) = Int32(30) TableScan: test ``` after: ```text Projection: test.a, test.b, test.c Filter: __common_expr_1 * __common_expr_1 = Int32(30) Projection: test.a + test.b AS __common_expr_1, test.a, test.b, test.c TableScan: test ``` In example, we extract common expr `test.a + test.b`, as `test.a + test.b` is equal to `test.b + test.a` semantically. ## What changes are included in this PR? 1. adding code of normalizing node before CSE in function `extract_common_nodes`. 2. adding trait `NormalizeNode` and implement this trait for enum `Expr`. 3. adding some normalize rule for some specific `BinaryExpr` (including `Plus` / `Multi` / `BitsetAnd` / `BitsetOr` / `BitsetXor` / `Gt` / `GtEq` / `Eq` / `NotEq` expressions) ## Are these changes tested? yes, I add below test cases. 1. test_normalize_add_expression 2. test_normalize_multi_expression 4. test_normalize_bitset_and_expression 5. test_normalize_bitset_or_expression 6. test_normalize_bitset_xor_expression 7. test_normalize_gt_expression 8. test_normalize_gte_expression 9. test_normalize_eq_expression 10. test_normalize_ne_expression ## Are there any user-facing changes? No -- 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: github-unsubscr...@datafusion.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org For additional commands, e-mail: github-h...@datafusion.apache.org