Skip to content

[CALCITE-7562] SqlToRel misses CAST in case IN expression without type coercion#4972

Open
snuyanzin wants to merge 1 commit into
apache:mainfrom
snuyanzin:calcite7562
Open

[CALCITE-7562] SqlToRel misses CAST in case IN expression without type coercion#4972
snuyanzin wants to merge 1 commit into
apache:mainfrom
snuyanzin:calcite7562

Conversation

@snuyanzin
Copy link
Copy Markdown
Contributor

Jira Link

CALCITE-7562

Changes Proposed

The PRs adds back (was removed at CALCITE-6435) ensureType for IN in case of different type family and turned off type coercion

* and the IN-to-OR expansion produces comparisons with mismatched types
* (e.g., DATE = CHAR).
*/
private RexNode ensureComparisonTypes(RexNode node) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

does this produce the same result as type coercion would?
Why not the leastRestrictive type?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yes, same result, before the fix it didn't

Why not the leastRestrictive type?

  1. follow the approach that was before CALCITE-6435
  2. in case of no leastRestrictive it will fail with NPE which is not user friednly
    in case of cast failure the error message will contain more helpful error description

@sonarqubecloud
Copy link
Copy Markdown

Copy link
Copy Markdown
Contributor

@mihaibudiu mihaibudiu left a comment

Choose a reason for hiding this comment

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

I actually like type coercion, I don't understand why you would have NO type coercion.
Skipping type coercion makes it much more complicated to understand the semantics of the program. The validator makes some assumptions about what programs are legal and why, and the consumers of the program produced by the validator may make different assumptions (e.g., do you cast int to char or vice-versa when comparing the two?). With explicit casts everywhere there are no assumptions.

This PR introduces a little more coercion even when the users ask for no coercion, so I think it's good.

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.

2 participants