Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CALCITE-6091] Char that in array or map is truncated if CASE WHEN statement contains null #3501

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

JiajunBernoulli
Copy link
Contributor

No description provided.

* <a href="https://issues.apache.org/jira/browse/CALCITE-6091">[CALCITE-6091]
* Char that in array or map is truncated in CASE WHEN statement</a>.
*/
@Test void testTruncatedCharInCaseWhen() {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't understand how this test relates to the change in the code.
The code is about nullability, but this test does not have any null values.
But the issue is about the type inference across cases in a case statement.
This would suggest that the bug is actually in leastRestrictive, which doesn't handle properly nullable types?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mihaibudiu , Thanks for your review.

I change the JIRA summary because https://issues.apache.org/jira/browse/CALCITE-4603 has been resolved.
I just add the case if types has null.

Copy link
Contributor

Choose a reason for hiding this comment

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

Where do these new tests use null values?
Will these tests pass if you remove your fixes? If yes, then these tests are not sufficient.

@JiajunBernoulli JiajunBernoulli changed the title [CALCITE-6091] Char that in array is truncated in CASE WHEN statement [CALCITE-6091] Char that in array or map is truncated if CASE WHEN statement contains null Nov 4, 2023
Copy link

sonarcloud bot commented Nov 4, 2023

Please retry analysis of this Pull-Request directly on SonarCloud.

fixture.check("select case "
+ "when true then array('abc') "
+ "when false then array('d') "
+ "else null "
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mihaibudiu
Here is null value.

When we omit else, it is also null.

If I remove my fix, the test will failed.

Copy link
Contributor

Choose a reason for hiding this comment

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

The type produced CHAR(3) NOT NULL ARRAY suggests that the expression is simplified before type inference.
If the expression wasn't simplified the type should be VARCHAR ARRAY.
But probably the simplification is done after type inference, so that's why this test works.

fixture.check("select case "
+ "when true then array('abc') "
+ "when false then array('d') "
+ "else null "
Copy link
Contributor

Choose a reason for hiding this comment

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

The type produced CHAR(3) NOT NULL ARRAY suggests that the expression is simplified before type inference.
If the expression wasn't simplified the type should be VARCHAR ARRAY.
But probably the simplification is done after type inference, so that's why this test works.

isNullable |= type.isNullable();
}
final RelDataType type =
leastRestrictive(
Util.transform(types,
Util.transform(notNullTypes,
Copy link
Contributor

Choose a reason for hiding this comment

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

My feeling was that leastRestrictive should be fixed instead to deal correctly with the NULL type.
So this solution is fine, but if leastRestrictive can be made more general, other users could benefit.

Copy link

github-actions bot commented Dec 9, 2024

This pull request has been marked as stale due to 30 days of inactivity. It will be closed in 90 days if no further activity occurs. If you think that’s incorrect or this pull request requires a review, please simply write any comment. If closed, you can revive the PR at any time and @mention a reviewer or discuss it on the [email protected] list. Thank you for your contributions.

@github-actions github-actions bot added the stale label Dec 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants