alamb opened a new issue #1693:
URL: https://github.com/apache/arrow-datafusion/issues/1693


   **Is your feature request related to a problem or challenge? Please describe 
what you are trying to do.**
   In certain situations , IOx is likely going to make predicates that look 
like the following
   
   ```sql
   CASE 
     WHEN col IS NULL THEN '' 
     ELSE col 
   END
   ```
   that basically map `null` to the empty string
   
   When applying them to certain specialized chunks (or row groups) we will 
know there are no NULLs in the `col` or all NULLs and thus we will end up 
rewriting it to something like
   
   ```sql
   CASE 
     WHEN true THEN '' 
     ELSE col 
   END
   ```
   
   Also in general, when applying other simplifications / constant folding I 
can imagine other situations where CASE can be folded such as 
   
   ```sql
   CASE
     WHEN extract(day) from now() = 0 THEN 'Monday'
     WHEN extract(day) from now() = 1 THEN 'Tuesday'
     WHEN extract(day) from now() = 2 THEN 'Wednesday'
     WHEN extract(day) from now() = 3 THEN 'Monday'
     ...
     ELSE 'other day'
   END
   ```
   
   So I think it is worth adding into DataFusion generally
   
   **Describe the solution you'd like**
   I would like to add cases to the rewrite rules here:
   
https://github.com/apache/arrow-datafusion/blob/03075d5f4b3fdfd8f82144fcd409418832a4bf69/datafusion/src/optimizer/simplify_expressions.rs#L440-L454
   
   Some rules I can think of are:
   1. When there is a literal `true` in the `cases` preceded by 0 or 1 literal 
falses or nulls, use that.
   2. When all the cases are false, --> the otherwise
   
   **Additional context**
   See https://github.com/influxdata/influxdb_iox/pull/3557 for more details


-- 
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]


Reply via email to