You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "alamb (via GitHub)" <gi...@apache.org> on 2025/09/16 11:15:48 UTC

[I] Simplify `CASE WHEN false THEN ...` [datafusion]

alamb opened a new issue, #17590:
URL: https://github.com/apache/datafusion/issues/17590

   ### Is your feature request related to a problem or challenge?
   
   ### Is your feature request related to a problem or challenge?
   
   
   One form of Case statements look like
   ```sql
   CASE 
     WHEN <expr> THEN <expr>
     WHEN <expr> THEN <expr>
     ...
      ELSE
   END
   ```
   
   As suggested by @geoffreyclaude  in https://github.com/apache/datafusion/issues/17448#issuecomment-3293549174
   
   
   Any `WHEN false` will never execute and thus can be removed from the
   
   For example
   ```sql
   CASE 
     WHEN false THEN 1  -- never executed
     ELSE 2  
   END
   ```
   
   Could be simplified to 
   
   ```sql
   2
   ```
   
   Likewise
   
   ```sql
   CASE 
     WHEN x=y THEN 1 
     WHEN false THEN 2  -- never executed
     ELSE 3  
   END
   ```
   
   Could be simplified to 
   
   ```sql
   CASE 
     WHEN x=y THEN 1 
     ELSE 3  
   END
   ```
   
   
   ### Describe the solution you'd like
   
   I would like to implement the simplification above
   
   
   
   ### Describe alternatives you've considered
   
   I think we can just extend the existing rules for CASE simplification here:
   
   https://github.com/apache/datafusion/blob/ec4413e7d7b41c381c98eda909e5ab650be4c5e5/datafusion/optimizer/src/simplify_expressions/expr_simplifier.rs#L1398-L1400
   
   An example is In https://github.com/apache/datafusion/pull/17450 where @EeshanBembi implemented a new CASE simplification
   
   
   ### Additional context
   
   _No response_¯
   
   ### Describe the solution you'd like
   
   _No response_
   
   ### Describe alternatives you've considered
   
   _No response_
   
   ### Additional context
   
   _No response_


-- 
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-unsubscribe@datafusion.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [I] Simplify `CASE WHEN false THEN ...` [datafusion]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb closed issue #17590: Simplify `CASE WHEN false THEN ...`
URL: https://github.com/apache/datafusion/issues/17590


-- 
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-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [I] Simplify `CASE WHEN false THEN ...` [datafusion]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on issue #17590:
URL: https://github.com/apache/datafusion/issues/17590#issuecomment-3297922071

   Since this is well specified and has an example PR I think it is a good first issue


-- 
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-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [I] Simplify `CASE WHEN false THEN ...` [datafusion]

Posted by "SidChaudhary7 (via GitHub)" <gi...@apache.org>.
SidChaudhary7 commented on issue #17590:
URL: https://github.com/apache/datafusion/issues/17590#issuecomment-3299505982

   take


-- 
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-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org