alamb commented on code in PR #17743:
URL: https://github.com/apache/datafusion/pull/17743#discussion_r2379533628
##########
datafusion/optimizer/src/simplify_expressions/expr_simplifier.rs:
##########
@@ -1471,6 +1508,56 @@ impl<S: SimplifyInfo> TreeNodeRewriter for
Simplifier<'_, S> {
// Do a first pass at simplification
out_expr.rewrite(self)?
}
+ // CASE
+ // WHEN X THEN true
+ // WHEN Y THEN true
+ // WHEN Z THEN false
+ // ...
+ // ELSE true
+ // END
+ //
+ // --->
+ //
+ // NOT(CASE
+ // WHEN X THEN false
+ // WHEN Y THEN false
+ // WHEN Z THEN true
+ // ...
+ // ELSE false
+ // END)
+ //
+ // Note: the rationale for this rewrite is that the case can then
be further
Review Comment:
That is a great example, maybe we can add it to the comments (as a follow on
PR)
##########
datafusion/optimizer/src/simplify_expressions/expr_simplifier.rs:
##########
@@ -1447,7 +1480,11 @@ impl<S: SimplifyInfo> TreeNodeRewriter for
Simplifier<'_, S> {
when_then_expr,
else_expr,
}) if !when_then_expr.is_empty()
- && when_then_expr.len() < 3 // The rewrite is O(n²) so limit
to small number
+ // The rewrite is O(n²) in general so limit to small number of
when-thens that can be true
+ && (when_then_expr.len() < 3 // small number of input whens
+ // or all thens are literal bools and a small number of
them are true
Review Comment:
Makes sense -- let's keep the check then
--
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]