Repository navigation
Conversation
…6370) Closes apache#26369. Follow-up to apache#25150. Fully ordered multi-column `GROUP BY` still hashes temporal, decimal, and fixed-size binary keys. These types can use the existing adjacent-run grouping path because Arrow's adjacent equality agrees with the grouping builders. In our production usecases, we are especially interested in apache#26369's optimization extending to `Timestamp`s (timeseries data) and `FixedSizeBinary(16)` (for UUIDs). - **Only production code change is 12 new types** added to the `match` under `supports_schema`: the rest are tests and benches. - Enable timestamps with all units and timezone metadata, dates, valid time units, durations, intervals, Decimal32/64/128/256, and every valid fixed-size binary width. - Preserve type metadata and the existing selection of single-column specializations. - Add a `fully_ordered` group to the existing SQL aggregation Criterion benchmark, with integer/string controls, timestamp run-length variants, and a timestamp `SUM(v)` case. The first two commits contain only benchmarks, followed by the type expansion and regression tests, including the UUID coverage. Differential tests compare ordered and hash grouping across nulls, units/timezones, decimal metadata, sliced batches, and group emission. Dedicated tests cover zero-width binary and 16-byte binary keys that share their first 15 bytes, including cross-batch continuation and keys that differ only in the last byte. SQL regression tests cover single-stage and partial/final aggregation, mixed sort directions, null ordering, and aggregate filters. The benchmarks check input types, row and group counts, and fully clustered aggregation without sorting or repartitioning in the measured query. The timestamp `SUM(v)` case also checks every group's sum before timing. <details> <summary>SQL benchmark results</summary> [Latest benchmark bot report](apache#26370 (comment)), comparing the benchmark-only baseline `dc6a10cf3c8` with `a398f8768ca`. Both refs contain the same 17 benchmark cases. The table shows rounded speedups from the report. The controls are roughly unchanged; the small differences may be benchmark noise. Values below 1× mean slower. | Second grouping key / query | Rows per group | Approx. speedup | | --- | ---: | ---: | | Int64 (control) | 31 | ~0.95× | | Utf8View (control) | 31 | ~0.99× | | Timestamp (ns) | 31 | ~7.0× | | Timestamp (µs, UTC) | 31 | ~6.9× | | Date32 | 31 | ~7.5× | | Time32 (ms) | 31 | ~7.5× | | Time64 (ns) | 31 | ~7.0× | | Duration (ns) | 31 | ~7.0× | | Interval (day/time) | 31 | ~6.4× | | Interval (month/day/ns) | 31 | ~5.3× | | Decimal128(30, 4) | 31 | ~6.1× | | Decimal256(60, 4) | 31 | ~5.2× | | FixedSizeBinary(16) | 31 | ~4.6× | | FixedSizeBinary(7) | 31 | ~4.4× | | Timestamp (ns), singleton groups | 1 | ~2.9× | | Timestamp (ns), long groups | 512 | ~7.7× | | Timestamp (ns), `SUM(v)` | 31 | ~4.0× | The 16 key-only cases use the same two-key deduplication query: ```sql SELECT k1, k2 FROM ordered_input GROUP BY k1, k2 ``` The additional timestamp case includes accumulator work: ```sql SELECT k1, k2, SUM(v) FROM ordered_input GROUP BY k1, k2 ``` Here `v` is the nonconstant source row number. The timestamp `SUM(v)` case improved from approximately 43.9 ms to 11.0 ms (~4.0×). - **Input:** about 2.1 million rows. `k1` is an Int32 prefix that advances every 32 groups; nullable `k2` cycles through 32 values, including one null, using the type listed above. Both keys vary. - **Group sizes:** normally 31 rows per key pair, so runs cross the 8,192-row batch boundaries. The additional timestamp cases use one or 512 rows per group to vary cardinality. - **Before timing:** generate the data, sort by both keys, and materialize it into one in-memory partition with its ordering declared to the planner. - **Measured work:** SQL planning, query execution, and collection of all results. The key-only cases focus on grouping the keys; the timestamp `SUM(v)` case also updates an accumulator. - **Setup checks:** verify input type, row count, and output group count; require fully clustered aggregation and fail if the measured plan adds sorting or repartitioning. The `SUM(v)` case verifies every group's result, including null timestamp keys and the final short group, before timing. </details> Already-sorted multi-column aggregations can use lower-overhead key storage for these types. Query results stay the same. Developed with AI assistance. (cherry picked from commit 6c1727f) Environment: Datadog workspace Co-authored-by: Codex GPT-6.2 Astra <noreply@localhost>
This was referenced Nov 30, 2026
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.
PR stack
DataDog/datafusion·branch-55<-- THIS PRWhich issue does this PR close?
Backports apache/datafusion#26370. This is stacked on the DF55 adjacent-run implementation. Merge that first, then target this change to
branch-55.Rationale for this change
The first backport handles a subset of compound keys. A clustered key such as
(series_id, time_bin)can still require hashing if the time bin is an Arrow timestamp. Comparing adjacent scalar values directly lets more queries use the same grouping path.What changes are included in this PR?
Cherry-pick Apache commit
6c1727fcd923and adapt its type dispatch and tests to DF55. Adds timestamps (including time zones), dates, supported time units, durations, intervals, Decimal128/256 and fixed-size binary keys. Unsupported types continue to use the existing grouping path.Are these changes tested?
Adds scalar-key SQL coverage and benchmarks for ordered compound keys. Workspace formatting and Clippy with all targets and features passed on this source tree. This PR has no stand-alone CPU or memory estimate. The original combined benchmark includes the first backport and the grouped FILTER fix.
Are there any user-facing changes?
Queries with eligible clustered compound keys can use adjacent-key comparisons for more SQL types.