fix: correct WEEK interval literal duration in calciteLiteralToDruidLiteral (#18665) - #19906
Open
waterWang wants to merge 1 commit into
Open
fix: correct WEEK interval literal duration in calciteLiteralToDruidLiteral (#18665)#19906waterWang wants to merge 1 commit into
waterWang wants to merge 1 commit into
Conversation
…iteral (apache#18665) Calcite has a known quirk where WEEK interval literals are stored as 1 hour in the INTERVAL_DAY_TIME family. This causes `INTERVAL 1 WEEK` to resolve to PT1H (1 hour) instead of P7D (7 days). Detect the WEEK qualifier in the SqlIntervalQualifier and convert the millisecond value to 7 days (multiply by 7 * 24).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes #18665
INTERVAL 1 WEEKin SQL resolves toPT1H(1 hour) instead ofP7D(7 days).Returns
1970-01-01T01:00:00.000Zinstead of1970-01-08T00:00:00.000Z.Root Cause
Calcite has a known quirk where WEEK interval literals are stored as 1 hour in the
INTERVAL_DAY_TIMEfamily. TheINTERVAL 1 WEEKliteral'sRexLiteral.value()returns3600000(1 hour in ms) instead of604800000(7 days in ms).Fix
In
calciteLiteralToDruidLiteral, detect theWEEKqualifier on theSqlIntervalQualifierand multiply the stored millisecond value by 7 × 24 to convert from the incorrect 1-hour representation to the correct 7-day duration.Impact
All
INTERVAL N WEEKexpressions now correctly resolve to N weeks instead of N hours.The fix applies to all contexts where
INTERVAL_DAY_TIMEliterals are converted to Druid expressions: timestamp arithmetic (+/-),TIMESTAMPDIFF, and other interval-using operations.Verification