Fix wrong results for multi-key GROUP BY with transform expressions - #19663
Open
zeronerdzerogeekzerocool wants to merge 2 commits into
Open
zeronerdzerogeekzerocool wants to merge 2 commits into
zeronerdzerogeekzerocool wants to merge 2 commits into
Conversation
added 2 commits
September 24, 2026 16:42
…bine OrderByComparatorFactory.getGroupByExpressionIndexMap keyed group-by expressions by getIdentifier(), which is null for any transform expression (e.g. dateTrunc(...), json_extract_index(...)). With two or more transform-based GROUP BY keys, they all collapsed onto the same null map entry, so every ORDER BY expression resolved to the same column index. This corrupted the SSE sort-aggregate combine (SortedGroupByCombineOperator / SequentialSortedGroupByCombineOperator) when merging per-segment sorted results across segments. Key on the whole ExpressionContext instead, and add regression tests covering multi-transform-key comparison, the group-key generator at the groups limit with null handling enabled, and end-to-end multi-key JSON group-by queries against offline and realtime tables.
…on tests Checkstyle in this repo rejects /** */ Javadoc in favor of /// markdown doc comments (JEP 467); the linter CI job on PR apache#19663 failed with 5 violations in the two new JsonExtractIndexGroupByTest files for this reason.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #19663 +/- ##
============================================
- Coverage 67.99% 67.98% -0.01%
Complexity 1450 1450
============================================
Files 3511 3511
Lines 227483 227485 +2
Branches 35994 35995 +1
============================================
- Hits 154676 154656 -20
- Misses 60661 60681 +20
- Partials 12146 12148 +2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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 flow
Fix maps GROUP BY keys by full ExpressionContext and validates ORDER BY keys are present.
AI-generated · Green: added · Yellow: modified · Red: removed · Gray: existing
Diff evidence
OrderByComparatorFactory.getGroupByExpressionIndexMapkeyed group-by expressions byexpression.getIdentifier(), which isnullfor anything that isn't a plain column reference (e.g.dateTrunc(...),json_extract_index(...)). With two or more transform-based GROUP BY keys, every expression collapsed onto the samenullmap entry, sogetRecordKeyComparatorresolved every ORDER BY expression to the same column index instead of its own.This corrupted the SSE sort-aggregate combine (
SortedGroupByCombineOperator/SequentialSortedGroupByCombineOperator): when merging per-segment sorted group-by results, the comparator no longer distinguished between distinct group keys, so unequal groups could be treated as equal and merged, silently corrupting aggregated values for multi-key GROUP BY queries where at least two keys are transform expressions.Fix: key the map by the whole
ExpressionContextinstead of its identifier, and fail fast viaPreconditions.checkStateif an ORDER BY expression isn't actually a GROUP BY key (rather than silently mapping to a wrong/null index).Instructions:
featurebugfixperformanceuibackward-incompatrelease-notes(**)(*) Other labels to consider:
testingdependenciesdockerkubernetesobservabilitysecuritycode-styleextension-pointrefactorcleanup(**) Use
release-noteslabel for scenarios like: