tv42 opened a new issue, #8909:
URL: https://github.com/apache/arrow-datafusion/issues/8909

   ### Describe the bug
   
   Datafusion evaluates `CASE ... WHEN ... THEN` expressions even for non-true 
branches, and bubbles up runtime errors from them.
   
   This is wrong because the `CASE` could be explicitly protecting against the 
divide-by-zero case, and differs from other sql engines.
   
   ### To Reproduce
   
   ```console
   ❯ SELECT CASE 1 WHEN 2 THEN 42/0 END;
   Optimizer rule 'simplify_expressions' failed
   caused by
   Arrow error: Divide by zero error
   ```
   
   
   ### Expected behavior
   
   I expected the `CASE` to evaluate to `NULL`, as none of its `WHEN` branches 
were true and it did not have an `ELSE`.
   
   Compare to SQLite:
   
   ```console
   sqlite> .nullvalue NULL
   sqlite> SELECT CASE 1 WHEN 2 THEN 42/0 END;
   NULL
   ```
   
   Compare to Postgres:
   
   ```console
   postgres=# \pset null 'NULL'
   Null display is "NULL".
   postgres=# SELECT CASE 1 WHEN 2 THEN 42/0 END;
    case
   ------
    NULL
   (1 row)
   ```
   
   ### 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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to