[ 
https://issues.apache.org/jira/browse/CALCITE-6741?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Mihai Budiu resolved CALCITE-6741.
----------------------------------
    Fix Version/s: 1.39.0
       Resolution: Fixed

Fixed in 
https://github.com/apache/calcite/commit/b970e522544aa4cc065cd486d1229ca72bd7f204
Thank you for the review [~nobigo]

> The type of a comparison is nullable when either operand is nullable
> --------------------------------------------------------------------
>
>                 Key: CALCITE-6741
>                 URL: https://issues.apache.org/jira/browse/CALCITE-6741
>             Project: Calcite
>          Issue Type: Bug
>          Components: core
>    Affects Versions: 1.38.0
>            Reporter: Mihai Budiu
>            Assignee: Mihai Budiu
>            Priority: Minor
>              Labels: pull-request-available
>             Fix For: 1.39.0
>
>
> This function converts an expression into another expression which does not 
> have the same type.
> The function convertInToOr has the following JavaDoc:
> {code:java}
> /* Converts "x IN (1, 2, ...)" to "x=1 OR x=2 OR ..." */
> {code}
> This is unsound when x is not nullable and the list contains NULL.
> The "in" expression can never evaluate to NULL in that case, whereas the 
> converted expression can.
> As an example, consider this test case, which is a simplified version of a 
> test from Sql Logic Test:
> {code:sql}
> SELECT CASE WHEN 1 NOT IN ( NULL, COUNT(*) ) THEN 1 END
> {code}
> The plan produced for this query is as follows:
> {code}
>     LogicalProject(EXPR$0=[CASE(CAST(AND(null, <>(1, $0))):BOOLEAN NOT NULL, 
> 1, null:INTEGER)]), id = 202
>       LogicalAggregate(group=[{}], agg#0=[COUNT()]), id = 200
>         LogicalValues(tuples=[[{ 0 }]]), id = 160
> {code}
> Notice that there's a CAST(AND ...): BOOLEAN NOT NULL. Unfortunately the AND 
> expression as written is nullable, so this cast is unsound.
> I am thinking that the correct expansion should use IS_NOT_DISTINCT_FROM 
> instead of EQUALS.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to