[feature](agg-state) Add aggregate state combine combinator - #66942
Open
HappenLee wants to merge 1 commit into
Open
[feature](agg-state) Add aggregate state combine combinator#66942HappenLee wants to merge 1 commit into
HappenLee wants to merge 1 commit into
Conversation
### What problem does this PR solve?
Issue Number: None
Related PR: None
Problem Summary: Existing <aggregate>_state plus <aggregate>_union constructs and serializes one aggregate state for every input row before merging those states. Add <aggregate>_combine to aggregate raw inputs directly with the nested aggregate function and emit one compatible AggState, preserving partial aggregation and avoiding per-row state materialization.
### Release note
Add the experimental <aggregate>_combine(...) combinator for directly producing reusable aggregate states.
### Check List (For Author)
- Test:
- Regression test: test_agg_state_avg
- Unit Test: AggregateStateCombineTest and CombineCombinatorTest
- Behavior changed: Yes. Adds a new aggregate-state combinator.
- Does this need documentation: No. The function is covered by the existing experimental AggState feature.
HappenLee
requested review from
924060929,
englefly,
morrySnow and
starocean999
as code owners
August 19, 2026 08:01
Contributor
|
Thank you for your contribution to Apache Doris. Please clearly describe your PR:
|
Contributor
Author
|
/review |
Contributor
|
Codex automated review failed and did not complete. Error: All Codex review accounts are usage-limited; earliest retry is 2026-08-20T03:35:00Z. Please trigger /review again after that time. |
Contributor
Author
|
run buildall |
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.
What problem does this PR solve?
Issue Number: None
Related PR: None
Problem Summary:
Existing
<aggregate>_stateplus<aggregate>_unionconstructs and serializes one aggregate state for every input row before merging those states. For queries with tens of millions of raw rows, this per-row state materialization can erase much of the pre-aggregation benefit.This PR adds a generic
<aggregate>_combine(...)combinator. It feeds raw arguments directly into the nested aggregate function and emits one compatibleAggStateper group. For example,avg_combine(x)is aggregation-equivalent toavg_union(avg_state(x)), while avoiding a serialized AVG state for every source row. The resulting state remains consumable by the existing_unionand_mergecombinators.The BE wrapper preserves the nested aggregate state layout and delegates raw accumulation, partial serialization, merge/deserialization, nullable handling, and fixed-length serialized column creation. Nereids resolves and translates the generic combinator and supports MV roll-up through the matching
_unionfunction. Zero-argument aggregates, DISTINCT, and aggregate ORDER BY expressions are rejected for now.Release note
Add the experimental
<aggregate>_combine(...)combinator for directly producing reusable aggregate states.Check List (For Author)
Regression coverage:
test_agg_state_avg, including nullable input, all-null input, grouped partial aggregation, and compatibility withavg_union(avg_state(...)).Unit coverage:
AggregateStateCombineTestandCombineCombinatorTest. Full BE and FE builds also passed; clang-tidy reported no warnings for the changed BE files.Behavior changed:
Does this need documentation?