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

   ## Which issue does this PR close?
   
   - Closes #27221.
   
   ## Rationale for this change
   
   When an aggregate groups by columns that share a name (`GROUP BY t1.a, 
t2.a`) and a partitioned hash join above it lists those keys in another order, 
the query returns wrong rows (no rows at all for the repro in the issue).
   
   `reorder_aggregate_keys` reorders the aggregate's group keys to match the 
join, then adds a projection that puts the columns back in their original 
order. That projection looked each column up by name with `index_of`, so when 
group columns are both named `a`, both output columns read the first one.
   
   ## What changes are included in this PR?
   
   - Build the restoring projection by position: invert `positions` (new index 
-> original index) into `orig_to_new` and look each original column up by its 
index instead of its name.
   - Drop the `Result` handling in that closure, since `index_of` was the only 
fallible call.
   
   With the fix, the plan also no longer needs the extra `RepartitionExec` 
above the projection.
   
   ## What is the testing strategy for this PR?
   
   Added cases in `repartition.slt`:
   
   - Two duplicate-named keys swapped (the repro from the issue).
   - Three duplicate-named keys in an order that is not its own inverse 
(`positions = [2, 0, 1]`). A swap of two keys is its own inverse, so only this 
case catches the mapping being applied in the wrong direction.
   
   ## Are there any user-facing changes?
   No API changes. Queries matching this shape now return correct results.


-- 
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