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-6581] Incorrect INTERVAL math for WEEK and QUARTER #3968

Merged
merged 1 commit into from
Sep 19, 2024

Conversation

gianm
Copy link
Contributor

@gianm gianm commented Sep 15, 2024

WEEK and QUARTER intervals were incorrectly treated like HOUR and MONTH respectively. This patch fixes the handling, and adds unit tests.

This patch also renames the two "fillIntervalValueArray" methods to "fillDayIntervalValueArray" (for INTERVAL_DAY_TIME type intervals) and "fillYearMonthIntervalValueArray" (for INTERVAL_YEAR_MONTH type intervals) to make it more clear which one is which.

@gianm gianm force-pushed the fix-week-quarter-math branch 2 times, most recently from b0650a9 to 4997c2e Compare September 15, 2024 03:41
@@ -746,7 +746,8 @@ private int[] evaluateIntervalLiteralAsQuarter(
checkLeadFieldInRange(typeSystem, sign, quarter, TimeUnit.QUARTER, pos);

// package values up for return
return fillIntervalValueArray(sign, ZERO, quarter);
final BigDecimal months = quarter.multiply(BigDecimal.valueOf(3));
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 think quarters should be convertible to seconds, they do not have a fixed length

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They are being converted to 3 months here, since QUARTER is treated as a kind of YEAR-MONTH interval.

Copy link
Contributor

Choose a reason for hiding this comment

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

sorry, I misread the JIRA issue

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, ok!

/**
* Tests {@link SqlParserUtil}.
*/
public class SqlParserUtilTest {
Copy link
Member

Choose a reason for hiding this comment

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

SqlParserIntervalQualifierTest?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I figured that at some point, this test file might be expanded to include more tests for SqlParserUtil, so I named it after the main class itself. However, please let me know if it's considered better to scope the test files more narrowly.

Copy link
Member

Choose a reason for hiding this comment

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

It seems that the impact is not great.
I think we can add JavaDoc to let subsequent contributors know what this test file is for.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've added some additional javadoc.

@mihaibudiu
Copy link
Contributor

Can you add a couple of end-to-end tests, either to SqlOperatorTest, or to one of the *.iq files?

@caicancai
Copy link
Member

Can you add a couple of end-to-end tests, either to SqlOperatorTest, or to one of the *.iq files?

+1

@gianm
Copy link
Contributor Author

gianm commented Sep 18, 2024

Can you add a couple of end-to-end tests, either to SqlOperatorTest, or to one of the *.iq files?

Sure, I've added a test to sql/misc.iq.

WEEK and QUARTER intervals were incorrectly treated like HOUR and MONTH
respectively. This patch fixes the handling, and adds unit tests.

This patch also renames the two "fillIntervalValueArray" methods to
"fillDayIntervalValueArray" (for INTERVAL_DAY_TIME type intervals) and
"fillYearMonthIntervalValueArray" (for INTERVAL_YEAR_MONTH type intervals)
to make it more clear which one is which.
Copy link

sonarcloud bot commented Sep 18, 2024

@gianm
Copy link
Contributor Author

gianm commented Sep 19, 2024

Committing; thank you for the reviews.

@gianm gianm merged commit 204ae1f into apache:main Sep 19, 2024
19 checks passed
@gianm gianm deleted the fix-week-quarter-math branch September 19, 2024 15:56
@mihaibudiu
Copy link
Contributor

Don't forget to mark the jira case as closed and to record the actual commit

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