[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 Dec 27, 2023
Conversation
…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.
libenchao
approved these changes
May 13, 2022
Member
libenchao
left a comment
There was a problem hiding this comment.
@yingyuwang LGTM, Thanks for pr.
chunweilei
reviewed
May 19, 2022
| 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 |
Contributor
There was a problem hiding this comment.
Is this change expected?
Contributor
Author
There was a problem hiding this comment.
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.
8a5cf83 to
cf7f71b
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In AbstractTypeCoercion#promoteToVarChar() return resultType with nullability if any of the types being promoted are nullable.