feat: skip hash shuffle for date_bin/date_trunc on Range([timestamp]) - #24501
Open
NGA-TRAN wants to merge 9 commits into
Open
feat: skip hash shuffle for date_bin/date_trunc on Range([timestamp])#24501NGA-TRAN wants to merge 9 commits into
NGA-TRAN wants to merge 9 commits into
Conversation
Pin today's Partial + hash RepartitionExec + Final plan for GROUP BY key, date_bin(timestamp) on a table that is already Range([timestamp]) and sorted on (key, timestamp), so a follow-up can remove the shuffle. Co-authored-by: Cursor <cursoragent@cursor.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #24501 +/- ##
==========================================
+ Coverage 81.32% 81.33% +0.01%
==========================================
Files 1117 1117
Lines 396269 396682 +413
Branches 396269 396682 +413
==========================================
+ Hits 322260 322642 +382
- Misses 55186 55206 +20
- Partials 18823 18834 +11 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Use generic column and table names so the coverage does not expose a metrics-specific schema. Co-authored-by: Cursor <cursoragent@cursor.com>
Accept RecordBatches and optional file sort order so the time-bin table reuses the same registration path. Co-authored-by: Cursor <cursoragent@cursor.com>
Treat Range([x]) as a subset of KeyPartitioned([..., f(x), ...]) when f is monotonic and bins do not straddle split points, so GROUP BY key, date_bin/date_trunc can stream without a hash RepartitionExec. Co-authored-by: Cursor <cursoragent@cursor.com>
NGA-TRAN
force-pushed
the
feat/issue-23569-range-date-bin-trunc
branch
from
August 20, 2026 15:44
05705f6 to
b26846d
Compare
Drop the local order-preserving walk and scalar predecessor so date_bin/date_trunc range projection uses EquivalenceProperties and interval_arithmetic instead of duplicating them. Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
NGA-TRAN
marked this pull request as ready for review
August 20, 2026 19:16
…che#24500 Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Contributor
Author
|
Tag @gene-bordegaray and @jayshrivastava for review |
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.
Which issue does this PR close?
Rationale for this change
A table that is range-partitioned on
timestamp(for example by hour) and grouped bydate_bin/date_truncof that timestamp is already partition-disjoint when bins do not straddle split points. DataFusion still planned Partial → hashRepartitionExec→ Final.After this change,
Range([timestamp])subset-satisfiesKeyPartitioned([key, f(timestamp)])whenfis monotonic (date_bin,date_trunc) and evaluatingfat each split vs. its predecessor shows the bins are disjoint. Aggregation then runs as one streamingSinglePartitionedstep withordering_mode=Sorted.Bins that do straddle the split (for example
date_trunc('day')on hour-partitioned data) still hash-repartition.#24500's expected plan changes from:
to:
What changes are included in this PR?
Rangethrough monotonic grouping expressions when bins stay disjoint.SanityCheckPlanacceptsSinglePartitionedoverRange([timestamp]).range_sorted_time_bin_agg.sltfordate_bin(60s)anddate_trunc('hour')(no shuffle) anddate_trunc('day')(shuffle remains).Are these changes tested?
partitioning.rsfor aligneddate_bin/date_trunc('hour')vs unaligned split anddate_trunc('day').cargo test --test sqllogictests -- range_sorted_time_bin_agg.sltAre there any user-facing changes?
Queries that group by
date_bin/date_truncof a range-partitioned timestamp may skip a hash shuffle when bins do not cross file-group boundaries. Results are unchanged.Test plan
cargo test -p datafusion-physical-expr --lib -- partitioningcargo test --test sqllogictests -- range_sorted_time_bin_agg.sltCo-author with Cursor