Repository navigation
feat: use range partitioning for date_trunc aggregation - #1
Closed
benbellick wants to merge 4 commits into
Closed
benbellick wants to merge 4 commits into
benbellick wants to merge 4 commits into
Conversation
|
Thank you for opening this pull request! Reviewer note: cargo-semver-checks reported the current version number is not SemVer-compatible with the changes in this pull request (compared against the base branch). Details |
Owner
Author
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?
None. This is a fork-only preview for reviewing the combined change.
Rationale for this change
Grouped aggregation currently inserts a hash repartition when grouping by a monotonic transformation of a range-partitioned key, even when the concrete range boundaries keep every resulting group within one input partition.
What changes are included in this PR?
An argument-type-aware, default-deny audit capability enables only timezone-less
date_trunc. Concrete boundary analysis establishes group locality, not join co-partitioning. Non-range arguments must be literals; unsupported inputs and evaluation errors fail closed.Aggregation enforcement and validation share one locality policy, including uncombined partial/final stages and reoptimization of combined aggregates. No transformed range metadata is invented.
date_bin, timezone-bearing timestamps, and overlapping bucket boundaries remain denied.Stronger tests exposed an existing scalar/array discrepancy for negative fractional timestamps. Scalar millisecond/microsecond truncation now uses checked flooring, matching array execution and rejecting underflow.
What is the testing strategy for this PR?
Tests cover capability forwarding, fractional/pre-epoch/calendar boundaries, interspersed nulls, timestamp extremes, and conservative rejection when scalar evaluation fails. A table-driven harness evaluates actual partition arrays across all timestamp units, ASC/DESC and both null placements, checking disjoint images for accepted cases and overlaps for rejected ones. It includes the previously unsafe microsecond split at
-999when truncating to milliseconds.Optimizer regressions cover validation without aggregate combination, repeated enforcement after combination, and join rejection. SQLLogicTest retains positive aligned
date_trunc('hour')and negative day/date_bin cases.Passed full workspace extended tests, all-target/all-feature strict Clippy,
dev/rust_lint.sh, and the targeted SQLLogicTest.The new
range_date_truncCriterion benchmark uses eight in-memory hourly partitions and eight rows per group. Against forkmainat22651d24c, optimized non-LTO builds of the same benchmark source (20 samples) measured:These synthetic aligned-range cases show roughly 35–36% lower execution time, not a general workload claim. Planning and data generation are excluded; results are checked before timing. Measurements used a standalone Cargo driver with SQL/datetime features; the benchmark is also registered for
cargo bench -p datafusion --bench range_date_trunc.Are there any user-facing changes?
Eligible grouped aggregations avoid hash repartitioning. Negative fractional scalar millisecond/microsecond truncation now agrees with array results. Public range-analysis and aggregate-locality APIs are added.
Note: This PR was developed with AI assistance. All changes have been reviewed, and I take full responsibility for this contribution.