Skip to content

[CALCITE-5921] SqlOperatorFixture.checkFails and checkAggFails don't check runtime failure#3412

Closed
herunkang2018 wants to merge 2 commits intoapache:mainfrom
herunkang2018:CALCITE-5921
Closed

[CALCITE-5921] SqlOperatorFixture.checkFails and checkAggFails don't check runtime failure#3412
herunkang2018 wants to merge 2 commits intoapache:mainfrom
herunkang2018:CALCITE-5921

Conversation

@herunkang2018
Copy link
Copy Markdown
Contributor

No description provided.

// input to extract for a particular input type.
String INVALID_EXTRACT_UNIT_CONVERTLET_ERROR =
"Extract.*from.*type data is not supported";
"Was not expecting value.*for enumeration.*in this context";
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.

This is to fix SqlOperatorTest.testExtractIntervalDayTime, the full error message is Was not expecting value 'DOY' for enumeration 'org.apache.calcite.avatica.util.TimeUnit' in this context.

I think the previous error message was wrong before, because I find that the exception check logic is introduced by CALCITE-1987 in 2017, and has remained unchanged, and the previous error message is introduced by CALCITE-4885 in 2021.

@sonarqubecloud
Copy link
Copy Markdown

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 1 Code Smell

100.0% 100.0% Coverage
19.0% 19.0% Duplication

SqlValidator validator = factory.createValidator();
SqlNode n = parseAndValidate(validator, sql);
assertNotNull(n);
tester.checkFails(factory, sap, expectedError, true);
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.

the last parameter to this call should be "runtime" and not "true"

Copy link
Copy Markdown
Contributor Author

@herunkang2018 herunkang2018 Oct 15, 2023

Choose a reason for hiding this comment

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

IMO the line 160 checks the runtime is true, so this line uses true is ok.

SqlValidator validator = factory.createValidator();
SqlNode n = parseAndValidate(validator, sql);
assertNotNull(n);
tester.checkAggFails(factory, expr, inputValues, expectedError, true);
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.

same here

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.

There is something more deeply broken in the implementation of checkFails.
You can write a test that will fail when called with checkScalarExact (by throwing an exception), but will also fail when called with checkFails (because it doesn't throw an exception)! It looks like the testing code for checkFails takes a different path through execution than the code for checkScalarExact. I am still trying to figure out where the two executions diverge, they seem to apply different optimizations to the expression.

So while indeed 5990 introduced a regression, it looks like there are several other problems that this change is surfacing. One of them seems to be that Calcite always implemented casts wrong, by not checking for overflow. Only some simplification code seems to trigger exceptions.

@mihaibudiu
Copy link
Copy Markdown
Contributor

Please consider #3471 instead of this PR, it fixes a few extra things.

@rubenada rubenada closed this Oct 25, 2023
@rubenada
Copy link
Copy Markdown
Contributor

Closing this one in favor of #3471

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.

3 participants