[ 
https://issues.apache.org/jira/browse/CALCITE-6741?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17907250#comment-17907250
 ] 

xiong duan edited comment on CALCITE-6741 at 12/20/24 1:12 AM:
---------------------------------------------------------------

I get it. We add the condition when unknownAsUnknow and unknowAsFalse. We need 
to know the value $0 if we think unknown as true. (This is on the premise that 
$0 is non-nullable)


was (Author: nobigo):
I get it. We add the condition when unknownAsUnknow and unknowAsFalse. We need 
to know the value $0 if we think unknown as true.

> Incorrect type inference in AbstractTypeCoercion.commonTypeForBinaryComparison
> ------------------------------------------------------------------------------
>
>                 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
>
> 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