[
https://issues.apache.org/jira/browse/CALCITE-4258?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17196900#comment-17196900
]
Ruben Q L edited comment on CALCITE-4258 at 9/16/20, 11:32 AM:
---------------------------------------------------------------
First of all, SqlToRelConverter transforms {{1 IS DISTINCT FROM NULL}} into the
following (equivalent) expression:
{code}
AND(
OR(IS NOT NULL(1), IS NOT NULL(null:INTEGER)),
IS NOT TRUE(=(1, null))
)
{code}
This will be our "original expression". The type of this whole expression is
BOOLEAN NOT NULL.
After CALCITE-4159, {{RexSimplify#simplifyAnd}} returns different things for
the 2nd term of the AND:
- before:
{code}
AND(
true,
IS NOT TRUE(null:BOOLEAN)
)
{code}
- after, due to the introduction of {{isEffectivelyNotNull}} inside
{{RexSimplify#simplifyIs2}}:
{code}
AND(
true,
null:BOOLEAN
)
{code}
In both cases, the first term ({{true}}), gets simplified (removed), so we keep
only the second one.
Before, {{IS NOT TRUE(null:BOOLEAN)}} had a BOOLEAN NOT NULL type, which
matches the type of the original expression.
After, {{null:BOOLEAN}} has a BOOLEAN type (notice the absence of NOT NULL).
The problem is that, even though we are using
{{RexSimplify#simplifyPreservingType}}, it seems that trying to cast
{{null:BOOLEAN}} to the original expression's type (BOOLEAN NOT NULL) has no
effect at all (which seems reasonable), so we end up returning BOOLEAN whereas
the original type was BOOLEAN NOT NULL.
This leads to the {{AssertionError}}.
was (Author: rubenql):
First of all, SqlToRelConverter transforms {{1 IS DISTINCT FROM NULL}} into the
following (equivalent) expression:
{code}
AND(
OR(IS NOT NULL(1), IS NOT NULL(null:INTEGER)),
IS NOT TRUE(=(1, null))
)
{code}
This will be our "original expression". The type of this whole expression is
BOOLEAN NOT NULL.
{{RexSimplify#simplifyAnd}} returns different things after CALCITE-4159
- before:
{code}
AND(
true,
IS NOT TRUE(null:BOOLEAN)
)
{code}
- after, due to the introduction of {{isEffectivelyNotNull}} inside
{{RexSimplify#simplifyIs2}}:
{code}
AND(
true,
null:BOOLEAN
)
{code}
In both cases, the first term ({{true}}), gets simplified (removed), so we keep
only the second one.
Before, {{IS NOT TRUE(null:BOOLEAN)}} had a BOOLEAN NOT NULL type, which
matches the type of the original expression.
After, {{null:BOOLEAN}} has a BOOLEAN type (notice the absence of NOT NULL).
The problem is that, even though we are using
{{RexSimplify#simplifyPreservingType}}, it seems that trying to cast
{{null:BOOLEAN}} to the original expression's type (BOOLEAN NOT NULL) has no
effect at all (which seems reasonable), so we end up returning BOOLEAN whereas
the original type was BOOLEAN NOT NULL.
This leads to the {{AssertionError}}.
> SqlToRelConverter: SELECT 1 IS [NOT] DISTINCT FROM NULL fails with
> AssertionError
> ---------------------------------------------------------------------------------
>
> Key: CALCITE-4258
> URL: https://issues.apache.org/jira/browse/CALCITE-4258
> Project: Calcite
> Issue Type: Bug
> Components: core
> Reporter: Ruben Q L
> Priority: Major
>
> Problem can be reproduced with the following tests (in
> core\src\test\resources\sql\misc.iq):
> {code}
> # [CALCITE-4258]
> SELECT 1 IS DISTINCT FROM NULL;
> +--------+
> | EXPR$0 |
> +--------+
> | true |
> +--------+
> (1 row)
> !ok
> # [CALCITE-4258]
> SELECT 1 IS NOT DISTINCT FROM NULL;
> +--------+
> | EXPR$0 |
> +--------+
> | false |
> +--------+
> (1 row)
> !ok
> {code}
> These tests fail with:
> {code}
> > java.lang.AssertionError: Conversion to relational algebra failed to
> > preserve datatypes:
> > validated type:
> > RecordType(BOOLEAN NOT NULL EXPR$0) NOT NULL
> > converted type:
> > RecordType(BOOLEAN EXPR$0) NOT NULL
> > rel:
> > LogicalProject(EXPR$0=[null:BOOLEAN])
> > LogicalValues(tuples=[[{ 0 }]])
> 44a47,109
> > at
> > org.apache.calcite.sql2rel.SqlToRelConverter.checkConvertedType(SqlToRelConverter.java:466)
> > at
> > org.apache.calcite.sql2rel.SqlToRelConverter.convertQuery(SqlToRelConverter.java:581)
> > at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:242)
> > at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:208)
> ...
> {code}
> These queries used to work fine until recently, so this regression must have
> occurred not so long ago.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)