richox opened a new issue, #13885: URL: https://github.com/apache/datafusion/issues/13885
### Describe the bug some queries containing `case when .. ELSE NULL end` produces incorrect results. ### To Reproduce preparing test table: ```sql $ datafusion-cli DataFusion CLI v43.0.0 > create table t1(s string); 0 row(s) fetched. Elapsed 0.003 seconds. > insert t1 (s) values ('aaa'), ('bbb'); +-------+ | count | +-------+ | 2 | +-------+ 1 row(s) fetched. Elapsed 0.002 seconds. > select * from t1; +-----+ | s | +-----+ | aaa | | bbb | +-----+ 2 row(s) fetched. Elapsed 0.001 seconds. ``` query: ```sql > select case when (NULL and (s = 'aaa')) then 'unreachable!' else null end from t1; +-------------------------------------------------------------------------------+ | CASE WHEN NULL AND t1.s = Utf8("aaa") THEN Utf8("unreachable!") ELSE NULL END | +-------------------------------------------------------------------------------+ | | | | +-------------------------------------------------------------------------------+ 2 row(s) fetched. Elapsed 0.002 seconds. > select case when (NULL and (s = 'aaa')) then s else 'always here!' end from t1; +-------------------------------------------------------------------------------+ | CASE WHEN NULL AND t1.s = Utf8("aaa") THEN t1.s ELSE Utf8("always here!") END | +-------------------------------------------------------------------------------+ | always here! | | always here! | +-------------------------------------------------------------------------------+ 2 row(s) fetched. Elapsed 0.001 seconds. > select case when (NULL and (s = 'aaa')) then s else null end from t1; +---------------------------------------------------------------+ | CASE WHEN NULL AND t1.s = Utf8("aaa") THEN t1.s ELSE NULL END | +---------------------------------------------------------------+ | aaa | <- BUGGY, should be NULL | | +---------------------------------------------------------------+ 2 row(s) fetched. Elapsed 0.001 seconds. ``` ### Expected behavior ```sql select case when (NULL and (s = 'aaa')) then s else null end from t1; ``` the above query should always output nulls, since the only WHEN condition is always null (not true) ### 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-unsubscr...@datafusion.apache.org.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org For additional commands, e-mail: github-h...@datafusion.apache.org