fix: hang in PeriodGranularity when using sub-day compound periods with imprecise timezone days#19382
Open
benhopp wants to merge 4 commits intoapache:masterfrom
Open
fix: hang in PeriodGranularity when using sub-day compound periods with imprecise timezone days#19382benhopp wants to merge 4 commits intoapache:masterfrom
benhopp wants to merge 4 commits intoapache:masterfrom
Conversation
…h imprecise timezone days
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.
This is my first real PR, and was largely assisted by AI, so please scrutinize heavily.
Fixes a bug where timestamp_floor with compound time-only periods falls back to an infinite loop when the timezone has daylight saving time.
Description
The issue is caused by how Druid's PeriodGranularity attempts to bucket timestamps when timezones and daylight saving time (DST) are involved.
When trying to bucket timestamps using a compound period like PT1M1S, Druid first tries a fast-path (
truncateMillisPeriod). It checks if the timezone has precise days and hours. Because timezones with DST (likeAmerica/New_York) observe daylight saving time, Druid incorrectly flags the timezone as imprecise for all period durations. It then falls back to a slow-path (truncateCompoundPeriod), which literally runs a while loop, adding the period duration starting from January 1st, 1970, until it reaches the target timestamp. This means it loops over 28 million times for every single row in the query, causing it to hang.This PR updates the
truncateMillisPeriodlogic to check if the period contains any inherently imprecise components like years, months, weeks, or days. If the period only contains hours, minutes, seconds, or milliseconds, it will safely convert the period to milliseconds and use the fast-path modulo math, avoiding the infinite while loop completely.A regression test
PeriodGranularityBugTest.javais included to validate this fix.