fix(expression): treat COUNT(*) as referencing no fields in GetReferencedFieldIds - #981
Open
LuciferYang wants to merge 1 commit into
Open
LuciferYang wants to merge 1 commit into
LuciferYang wants to merge 1 commit into
Conversation
…ncedFieldIds ReferenceVisitor::Aggregate unconditionally called aggregate->reference()->field_id(), but BoundAggregate::reference() returns nullptr for aggregates without a term such as COUNT(*), so GetReferencedFieldIds on a bound count(*) dereferenced null and crashed. Skip the insert when there is no reference; the aggregate then correctly contributes no field ids, matching the Java reference.
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
The focused null-safety fix is correct and adequately covered by regression tests.
Review effort: Balanced
Findings: None
What changed in this PR
Fixes #978 by preventing a null dereference when collecting field references from bound COUNT(*).
Changes:
- Treats termless aggregates as referencing no fields.
- Adds regression tests for
COUNT(*)andMAX(age).
| File | Description |
|---|---|
src/iceberg/expression/binder.cc |
Guards nullable aggregate references. |
src/iceberg/test/expression_visitor_test.cc |
Tests termless and field-based aggregates. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
This branch has not been deployed
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
ReferenceVisitor::GetReferencedFieldIdscrashed on a boundCOUNT(*).ReferenceVisitor::Aggregatedereferencedaggregate->reference(), which isnullptrforCOUNT(*)(its term is null by construction). The visitor is reached through the exportedGetReferencedFieldIds, so a consumer doing aggregate pushdown would segfault on the most common SQL aggregate.Closes #978.
How
Aggregatenow inserts the field id only whenreference()is non-null, soCOUNT(*)contributes nothing (it references no columns).COUNT(col)/MAX/MINkeep their existing behavior.Testing
Two tests in
expression_visitor_test.cc:CountStar— bindingCOUNT(*)and callingGetReferencedFieldIdsreturns an empty set. Without the fix this segfaults the test binary at the null dereference.AggregateWithTerm—MAX(age)still reports its field id{3}, pinning the non-null branch so a mutation that drops or inverts the guard is caught.