Skip to content

[CALCITE-5130] AssertionError: "Conversion to relational algebra failed to preserve datatypes" when union VARCHAR literal and CAST(null AS INTEGER)#2803

Merged
mihaibudiu merged 1 commit intoapache:mainfrom
yingyuwang:CALCITE-5130
Dec 27, 2023

Conversation

@yingyuwang
Copy link
Contributor

In AbstractTypeCoercion#promoteToVarChar() return resultType with nullability if any of the types being promoted are nullable.

…ed to preserve datatypes" when union VARCHAR literal and CAST(null AS INTEGER)

In AbstractTypeCoercion#promoteToVarChar() return resultType with nullability
if any of the types being promoted are nullable.
Copy link
Member

@libenchao libenchao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yingyuwang LGTM, Thanks for pr.

sql("select (select 1+2 from (values true)) tt from (values(true)) union values '2'")
.type("RecordType(VARCHAR NOT NULL TT) NOT NULL");
.type("RecordType(VARCHAR TT) NOT NULL");
// union with star
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this change expected?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I found is Calcite seems to add isNullable=true when there is a sub query, for example we have:

    sql("select 1 from (values 1)")
        .type("RecordType(INTEGER NOT NULL EXPR$0) NOT NULL"); // isNullable=false for EXPR$0 when not query from subquery
    sql("select (select 1 from (values 1))")    
        .type("RecordType(INTEGER EXPR$0) NOT NULL"); // isNullable=true for EXPR$0 when query from subquery

So before the change, isNullable=true is lost at promoteToVarChar() for this test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants