LiaCastaneda opened a new pull request, #22453:
URL: https://github.com/apache/datafusion/pull/22453

   ## Which issue does this PR close?
   
   <!--
   We generally require a GitHub issue to be filed for all bug fixes and 
enhancements and this helps us generate change logs for our releases. You can 
link an issue to this PR using the GitHub syntax. For example `Closes #123` 
indicates that this PR will close issue #123.
   -->
   
   - Closes #.
   
   ## Rationale for this change
   
   When the substrait consumer hits an `Aggregate` with two identical measures 
(e.g. `sum(a)` present twice), planning fails with `Schema contains duplicate 
unqualified field name`. Substrait carries column names at the plan root rather 
than on the measures themselves, so the measures arrive at `Aggregate` schema 
construction without aliases -- and two identical exprs produce two identical 
field names. PR #20539 fixed the `NameTracker` to dedupe duplicate names in the 
consumer, but it was only applied to grouping expressions, not to the measures.
   
   The planner sees:
   
   ```
   field 1: (qualifier: None, name: "sum(data.a)")
   field 2: (qualifier: None, name: "sum(data.a)")
   ```
   
   which is rejected when constructing the Aggregate's output schema.
   
   
   ## What changes are included in this PR?
   
   Run aggregate measures through the same `NameTracker` like the grouping 
expressions in `from_aggregate_rel`
   
   ## Are these changes tested?
   
   Yes -- added a roundtrip test `aggregate_identical_measures`. Without the 
fix it produces `Error: SchemaError(DuplicateUnqualifiedField { name: 
"sum(data.a)" }, Some(""))`
   
   ## Are there any user-facing changes?
   
   No.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to