[SPARK-57737][SQL] Cache zone offset per task in date_trunc#56848
Open
Licht-T wants to merge 4 commits into
Open
[SPARK-57737][SQL] Cache zone offset per task in date_trunc#56848Licht-T wants to merge 4 commits into
Licht-T wants to merge 4 commits into
Conversation
…meBenchmark (JDK 21, Scala 2.13, split 1 of 1)
…meBenchmark (JDK 25, Scala 2.13, split 1 of 1)
…meBenchmark (JDK 17, Scala 2.13, split 1 of 1)
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.
What changes were proposed in this pull request?
date_trunc(TruncTimestamp) resolves the session zone offset for each row viaZoneRules.getOffset(Instant)-- a binary search over the zone's transition array -- and for non-fixed-offset zones it does so twice per row (the input instant and the candidate truncated instant used by the DST-equality guard from SPARK-56663 / SPARK-56769).This PR adds a per-task
ZoneOffsetCachethat memoizes the resolved offset over the half-open epoch-second interval[lo, hi)on which it is provably constant, derived from the surrounding zone transitions (nextTransition/previousTransition, anchored on an interior point to avoid an off-by-one when an instant sits exactly on a transition). A lookup inside the cached interval reduces to two comparisons instead of a binary search.Why are the changes needed?
The session time zone is constant for a query and a zone's offset is piecewise-constant between DST/historical transitions, so consecutive rows almost always fall in the same constant-offset window (analytic data is typically temporally clustered -- time series, date-partitioned tables, post-sort). Repeating the transition-array binary search on every row is redundant work on the hot path.
DateTimeBenchmarkTruncation, whole-stage codegen on, session zoneAmerica/Los_Angeles, OpenJDK 17 on a 12th Gen Intel i7-1260P, ns/row (lower is better):Does this PR introduce any user-facing change?
No.
How was this patch tested?
Existing
DateTimeUtilsSuiteandDateExpressionsSuitepass.Was this patch authored or co-authored using generative AI tooling?
Yes, co-authored with Claude Code.