Repository navigation
feat: reuse range partitioning for date_trunc aggregation - #26449
Merged
jayzhan211 merged 50 commits intoOct 23, 2026
Merged
jayzhan211 merged 50 commits into
jayzhan211 merged 50 commits into
Conversation
Mark intentional expression hash keys with narrowly scoped lint expectations. Interior-mutable memory accounting does not affect expression hashing or equality.
Reject malformed effective split points before proving transformed-key locality. Cover uncombined aggregation, repeated optimization, incompatible join layouts, and grouping-set subtotals with executable regressions.
benbellick
force-pushed
the
feat/issue-25344-range-transform-locality
branch
from
October 17, 2026 16:32
2a0b4f5 to
a6482e5
Compare
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #26449 +/- ##
==========================================
+ Coverage 82.89% 82.93% +0.03%
==========================================
Files 1154 1155 +1
Lines 457630 458894 +1264
Branches 457630 458894 +1264
==========================================
+ Hits 379370 380592 +1222
+ Misses 55256 55240 -16
- Partials 23004 23062 +58 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
NGA-TRAN
approved these changes
Oct 21, 2026
NGA-TRAN
left a comment
Contributor
There was a problem hiding this comment.
The description and the plan outputs are for those test cases are exactly what we need. The code looks great. Thanks so much @benbellick
@jayzhan211 : since you review the earlier PR (that covers boarder cases), we hope you give this a look. Thanks
jayzhan211
self-requested a review
October 21, 2026 12:40
jayzhan211
approved these changes
Oct 21, 2026
Contributor
|
Thanks @benbellick @NGA-TRAN! LGTM |
Contributor
Author
|
Thanks for the quick reviews! I will continue with the followups once this is merged 🚀 |
This was referenced Oct 22, 2026
jayzhan211
enabled auto-merge
October 23, 2026 03:14
gabotechs
pushed a commit
to moraistejerina/datafusion
that referenced
this pull request
Oct 23, 2026
…26607) ## Which issue does this PR close? Closes apache#26605. ## Rationale for this change `date_bin` returns NULL for unrepresentable timestamp bins. Return an error instead, matching [PostgreSQL](https://www.db-fiddle.com/f/h3qSHUSRprbzkX9GBkSuY2/0). I'm not sure whether DataFusion has a specific policy on returning NULL versus an error here, but the PostgreSQL precedent seems clear. Returning NULL because we cannot compute a bin for a non-null timestamp silently hides a computation failure rather than representing missing input. This prepares `date_bin` for avoiding aggregate repartitioning in [apache#25345](apache#25345), similar to the `date_trunc` optimization in [apache#26449](apache#26449). It follows the error behavior established for `date_trunc` in [apache#25131](apache#25131). ## What changes are included in this PR? Make scalar and array timestamp-binning failures return `DATE_BIN timestamp out of range`. Preserve NULL inputs and successful wider-arithmetic results. ## What is the testing strategy for this PR? Unit tests and SQLLogicTests cover overflow errors, scalar/array consistency, NULL preservation, and representable results across timestamp precisions. ## Are there any user-facing changes? Previously NULL-producing timestamp-binning failures now fail the query. --- This PR was developed with AI assistance. All changes have been reviewed, and I take full responsibility for this contribution.
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?
Closes #26448.
Related to #23569, #25344, and #25345.
Rationale for this change
This PR implements a focused subset of the optimization in Nga's PR #24501 for a known-safe case. The plan is to iteratively expand support to more safe cases, following Gene's review feedback.
Suppose
eventsis range-partitioned ontimestamp, with partitions split at hourly boundaries.Each
(key, hour)group belongs entirely to one input partition. The simplified physical plans below omit projections and usehourfor the grouping expression.Without the optimization
With the optimization
The new locality check is specific to aggregates. General distribution satisfaction and join-layout checks are unchanged.
What changes are included in this PR?
Add a default-deny capability that identifies functions and argument types safe for range-key analysis. Check expression ordering and arguments, then evaluate both sides of each split to prove groups stay within partitions.
The optimizer calls it through this path.
flowchart TD A["EnsureRequirements checks aggregate input"] --> B["AggregateExec::input_keeps_groups_local"] B --> C["Partitioning::keeps_keys_local"] C --> D{"Function admitted, expression supported, and split boundaries safe?"} D -->|Yes| E["Can skip the aggregate hash shuffle"] D -->|No or unknown| F["Retain normal repartitioning"]Support is intentionally limited to timezone-less
date_truncover single-key timestamp ranges, with literal non-range arguments.date_binremains excluded pending its safety audit, including null behavior. Compound range keys remain follow-up work in #24644.Keep the shuffle when buckets cross partitions or the checks fail. Grouping sets still use the existing distribution checks.
What is the testing strategy for this PR?
Added multiple unit and integration tests.
I'm happy to add a benchmark if maintainers would find it useful.
Are there any user-facing changes?
Eligible
date_truncaggregations can skip a hash shuffle. Results are unchanged.Note: This PR was developed with AI assistance. All changes have been reviewed, and I take full responsibility for this contribution.