alamb commented on code in PR #9692:
URL: https://github.com/apache/arrow-datafusion/pull/9692#discussion_r1530663287
##########
datafusion/optimizer/src/simplify_expressions/expr_simplifier.rs:
##########
@@ -1482,6 +1590,22 @@ impl<'a, S: SimplifyInfo> TreeNodeRewriter for
Simplifier<'a, S> {
}
}
+// TODO: We might not need this after defer pattern for Box is stabilized.
https://github.com/rust-lang/rust/issues/87121
Review Comment:
👍
##########
datafusion/optimizer/src/simplify_expressions/expr_simplifier.rs:
##########
@@ -1473,7 +1465,123 @@ impl<'a, S: SimplifyInfo> TreeNodeRewriter for
Simplifier<'a, S> {
negated: false,
};
- return Ok(Transformed::yes(Expr::InList(merged_inlist)));
+ Transformed::yes(Expr::InList(merged_inlist))
+ }
+
+ // Simplify expressions that is guaranteed to be true or false to
a literal boolean expression
Review Comment:
👨🍳 👌 -- very nice
##########
datafusion/optimizer/src/simplify_expressions/inlist_simplifier.rs:
##########
@@ -97,121 +95,3 @@ impl TreeNodeRewriter for ShortenInListSimplifier {
Ok(Transformed::no(expr))
}
}
-
-pub(super) struct InListSimplifier {}
-
-impl InListSimplifier {
- pub(super) fn new() -> Self {
- Self {}
- }
-}
-
-impl TreeNodeRewriter for InListSimplifier {
- type Node = Expr;
-
- fn f_up(&mut self, expr: Expr) -> Result<Transformed<Expr>> {
- // Simplify expressions that is guaranteed to be true or false to a
literal boolean expression
- //
- // Rules:
- // If both expressions are `IN` or `NOT IN`, then we can apply
intersection or union on both lists
- // Intersection:
- // 1. `a in (1,2,3) AND a in (4,5) -> a in (), which is false`
- // 2. `a in (1,2,3) AND a in (2,3,4) -> a in (2,3)`
- // 3. `a not in (1,2,3) OR a not in (3,4,5,6) -> a not in (3)`
- // Union:
- // 4. `a not int (1,2,3) AND a not in (4,5,6) -> a not in
(1,2,3,4,5,6)`
- // # This rule is handled by `or_in_list_simplifier.rs`
- // 5. `a in (1,2,3) OR a in (4,5,6) -> a in (1,2,3,4,5,6)`
- // If one of the expressions is `IN` and another one is `NOT IN`, then
we apply exception on `In` expression
- // 6. `a in (1,2,3,4) AND a not in (1,2,3,4,5) -> a in (), which
is false`
- // 7. `a not in (1,2,3,4) AND a in (1,2,3,4,5) -> a = 5`
- // 8. `a in (1,2,3,4) AND a not in (5,6,7,8) -> a in (1,2,3,4)`
- if let Expr::BinaryExpr(BinaryExpr { left, op, right }) = expr.clone()
{
Review Comment:
Removing this `expr.clone()` is 👍
--
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]