fix: duplicate ordering state field names in partial aggregates - #25196
Open
cdelmonte-zg wants to merge 2 commits into
Open
fix: duplicate ordering state field names in partial aggregates#25196cdelmonte-zg wants to merge 2 commits into
cdelmonte-zg wants to merge 2 commits into
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #25196 +/- ##
==========================================
- Coverage 81.92% 81.91% -0.01%
==========================================
Files 1132 1132
Lines 421192 421371 +179
Branches 421192 421371 +179
==========================================
+ Hits 345041 345183 +142
- Misses 55756 55778 +22
- Partials 20395 20410 +15 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
jayzhan211
approved these changes
Sep 13, 2026
jayzhan211
left a comment
Contributor
There was a problem hiding this comment.
Thanks @cdelmonte-zg, all suggestions are non-blocking
Maybe we could also add the change to docs/source/library-user-guide/upgrading/56.0.0.md
| .into(), | ||
| ]; | ||
| fields.extend(args.ordering_fields.iter().cloned()); | ||
| fields.extend(args.ordering_fields.iter().enumerate().map(|(idx, field)| { |
Contributor
There was a problem hiding this comment.
could we add helper to reduce duplication
/// Namespaces ordering fields so state field names stay unique per query.
pub fn ordering_state_fields(name: &str, ordering_fields: &[FieldRef]) -> Vec<FieldRef> {
ordering_fields
.iter()
.enumerate()
.map(|(idx, f)| {
Arc::new(f.as_ref().clone().with_name(format_state_name(
name,
&format!("ordering_{idx}_{}", f.name()),
)))
})
.collect()
}
Contributor
There was a problem hiding this comment.
I think the first idx might be enough 🤔
first_value(value)[ordering_0_timestamp@0] becomes first_value(value)[ordering_0]
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?
Rationale for this change
Partial aggregate state schemas can contain duplicate field names when multiple order-sensitive aggregate expressions use the same ordering expression.
For example,
first_value(value ORDER BY timestamp)andlast_value(value ORDER BY timestamp)both exposed the ordering state field astimestamp@0.This required
DFSchema::try_fromto skipcheck_names()as a workaround. However, thestate_fields()contract requires state field names to be unique within the query.What changes are included in this PR?
AggregateUDFImpl::state_fields()implementation and toFirstValue/LastValue.DFSchema::check_names()inTryFrom<SchemaRef> for DFSchema.state_fields()implementation, including duplicate ordering field names within a single aggregate.For example, an ordering state field now has a name such as:
rather than the unqualified:
The ordering position also disambiguates repeated ordering fields within the same aggregate.
What is the testing strategy for this PR?
The change is covered by:
test_partial_aggregate_state_fields_have_unique_namestest_default_state_fields_namespaces_ordering_fieldsThe following test suites pass locally:
cargo fmt --all -- --checkandgit diff --checkalso pass.Are there any user-facing changes?
No public API signatures were changed. Ordering state field names now use the aggregate namespace and ordering position to guarantee uniqueness, allowing DFSchema::check_names() to be re-enabled.