You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "findepi (via GitHub)" <gi...@apache.org> on 2025/01/28 19:57:44 UTC

[I] Invalid query result when searched CASE has nullable condition and boolean result [datafusion]

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

   ### Describe the bug
   
   Invalid query result when searched CASE has nullable condition and boolean result
   
   ### To Reproduce
   
   ```sql
   SELECT c, CASE WHEN c > 0 THEN true END
   FROM (VALUES (1), (0), (-1), (NULL)) AS t(c)
   ORDER BY c;
   ```
   
   This returns in DF
   ```
   +------+-------------------------------------------------+
   | c    | CASE WHEN t.c > Int64(0) THEN Boolean(true) END |
   +------+-------------------------------------------------+
   | -1   | false                                           |
   | 0    | false                                           |
   | 1    | true                                            |
   | NULL | NULL                                            |
   +------+-------------------------------------------------+
   ```
   
   ### Expected behavior
   
   This query should never returns a `false` value.
   
   PostgreSQL
   
   ```
   postgres=# SELECT c, CASE WHEN c > 0 THEN true END
   FROM (VALUES (1), (0), (-1), (NULL)) AS t(c)
   ORDER BY c;
    c  | case
   ----+------
    -1 |
     0 |
     1 | t
       |
   ```
   
   Trino
   ```
   trino> SELECT c, CASE WHEN c > 0 THEN true END
       -> FROM (VALUES (1), (0), (-1), (NULL)) AS t(c)
       -> ORDER BY c;
     c   | _col1
   ------+-------
      -1 | NULL
       0 | NULL
       1 | true
    NULL | NULL
   ```
   
   ### 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] Invalid query result when searched CASE has nullable condition and boolean result [datafusion]

Posted by "findepi (via GitHub)" <gi...@apache.org>.
findepi closed issue #14343: Invalid query result when searched CASE has nullable condition and boolean result
URL: https://github.com/apache/datafusion/issues/14343


-- 
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] Invalid query result when searched CASE has nullable condition and boolean result [datafusion]

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

   It seems the initial plan is constructed correctly, but some optimizer is "too smart", simplifying CASE over-eagerly.


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