Skip to content

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

Merged
snuyanzin merged 1 commit into
apache:mainfrom
snuyanzin:calcite7562
Jun 5, 2026
Merged

[CALCITE-7562] SqlToRel misses CAST in case IN expression without type coercion#4972
snuyanzin merged 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

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.

@mihaibudiu mihaibudiu added the LGTM-will-merge-soon Overall PR looks OK. Only minor things left. label Jun 1, 2026
@snuyanzin
Copy link
Copy Markdown
Contributor Author

I don't understand why you would have NO type coercion.

Looks like historical reasoning, there is still a number of tests in Flink failing if I blindly enable them. So for now enabling coercion in Flink requires discuss in ML first and may be fixing all the failing cases which is in todo list however not with high priority

@snuyanzin
Copy link
Copy Markdown
Contributor Author

rebased to the latest main

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented Jun 5, 2026

@mihaibudiu
Copy link
Copy Markdown
Contributor

I approved, feel free to merge anytime

@snuyanzin snuyanzin merged commit deb4805 into apache:main Jun 5, 2026
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

LGTM-will-merge-soon Overall PR looks OK. Only minor things left.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants