You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@druid.apache.org by "waterWang (via GitHub)" <gi...@apache.org> on 2026/08/06 16:23:16 UTC
[PR] fix: correct WEEK interval literal duration in calciteLiteralToDruidLiteral (#18665) (druid)
waterWang opened a new pull request, #19906:
URL: https://github.com/apache/druid/pull/19906
### Description
Fixes #18665
`INTERVAL 1 WEEK` in SQL resolves to `PT1H` (1 hour) instead of `P7D` (7 days).
```sql
SELECT MILLIS_TO_TIMESTAMP(0) + INTERVAL 1 WEEK
```
Returns `1970-01-01T01:00:00.000Z` instead of `1970-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_TIME` family. The `INTERVAL 1 WEEK` literal's `RexLiteral.value()` returns `3600000` (1 hour in ms) instead of `604800000` (7 days in ms).
### Fix
In `calciteLiteralToDruidLiteral`, detect the `WEEK` qualifier on the `SqlIntervalQualifier` and 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 WEEK` expressions now correctly resolve to N weeks instead of N hours.
The fix applies to all contexts where `INTERVAL_DAY_TIME` literals are converted to Druid expressions: timestamp arithmetic (`+`/`-`), `TIMESTAMPDIFF`, and other interval-using operations.
### Verification
```sql
SELECT MILLIS_TO_TIMESTAMP(0) + INTERVAL 1 WEEK
-- Before: 1970-01-01T01:00:00.000Z
-- After: 1970-01-08T00:00:00.000Z
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] fix: correct WEEK interval literal duration in calciteLiteralToDruidLiteral (#18665) (druid)
Posted by "github-actions[bot] (via GitHub) via commits" <co...@druid.apache.org>.
github-actions[bot] closed pull request #19906: fix: correct WEEK interval literal duration in calciteLiteralToDruidLiteral (#18665)
URL: https://github.com/apache/druid/pull/19906
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] fix: correct WEEK interval literal duration in calciteLiteralToDruidLiteral (#18665) (druid)
Posted by "github-actions[bot] (via GitHub) via commits" <co...@druid.apache.org>.
github-actions[bot] commented on PR #19906:
URL: https://github.com/apache/druid/pull/19906#issuecomment-6646028843
This pull request/issue has been closed due to lack of activity. If you think that
is incorrect, or the pull request requires review, you can revive the PR at any time.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] fix: correct WEEK interval literal duration in calciteLiteralToDruidLiteral (#18665) (druid)
Posted by "FrankChen021 (via GitHub)" <gi...@apache.org>.
FrankChen021 commented on PR #19906:
URL: https://github.com/apache/druid/pull/19906#issuecomment-5217078096
this problem is supposed to be fixed by #19370 , but looks like it was not fix
can you add some test cases in this PR?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] fix: correct WEEK interval literal duration in calciteLiteralToDruidLiteral (#18665) (druid)
Posted by "FrankChen021 (via GitHub)" <gi...@apache.org>.
FrankChen021 commented on code in PR #19906:
URL: https://github.com/apache/druid/pull/19906#discussion_r3735950561
##########
sql/src/main/java/org/apache/druid/sql/calcite/expression/Expressions.java:
##########
@@ -371,7 +373,14 @@ public static DruidLiteral calciteLiteralToDruidLiteral(
retVal = new DruidLiteral(ExpressionType.DOUBLE, number == null ? null : number.doubleValue());
} else if (SqlTypeFamily.INTERVAL_DAY_TIME == sqlTypeName.getFamily()) {
// Calcite represents DAY-TIME intervals in milliseconds.
- final long milliseconds = ((Number) RexLiteral.value(rexNode)).longValue();
+ long milliseconds = ((Number) RexLiteral.value(rexNode)).longValue();
+ // Calcite has a known quirk where WEEK interval literals are stored as 1 hour in the
+ // INTERVAL_DAY_TIME family (see https://github.com/apache/druid/issues/18665).
+ // Detect the WEEK qualifier and convert the value to 7 days.
+ final SqlIntervalQualifier intervalQualifier = rexNode.getType().getIntervalQualifier();
+ if (intervalQualifier != null && intervalQualifier.getStartUnit() == TimeUnit.WEEK) {
+ milliseconds = milliseconds * 7 * 24;
Review Comment:
[P1] Avoid rescaling already-correct WEEK literals
This branch uses Calcite 1.41, which already converts WEEK intervals to millisecond values. A narrow probe produced 604800000 for INTERVAL '1' WEEK; multiplying by 7 * 24 changes it to 101606400000 ms, making existing quoted and unquoted WEEK expressions 168 times too large. Apply the workaround only to the pre-1.38 representation or remove it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] fix: correct WEEK interval literal duration in calciteLiteralToDruidLiteral (#18665) (druid)
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #19906:
URL: https://github.com/apache/druid/pull/19906#issuecomment-6028275733
This pull request has been marked as stale due to 60 days of inactivity.
It will be closed in 4 weeks if no further activity occurs. If you think
that's incorrect or this pull request should instead be reviewed, please simply
write any comment. Even if closed, you can still revive the PR at any time or
discuss it on the dev@druid.apache.org list.
Thank you for your contributions.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org