xgbtxy opened a new pull request, #26712: URL: https://github.com/apache/datafusion/pull/26712
## Which issue does this PR close? Closes #26691. ## Rationale for this change A projection can change an aggregate value while keeping its output name. For example, ordering by `-max(v)` in descending order must retain the groups with the smallest original maxima. TopK aggregation currently follows the reused name and can discard those groups before the projection runs. ## What changes are included in this PR? Track the sort column through the corresponding projection output index. Continue through direct column references, including renamed or reordered outputs, and stop at a computed expression. Treat materialized CTEs as a boundary because their producer and output continuation can use different column positions. The regression tests cover the reported MAX query, a computed projection over DISTINCT, a direct sort column with a computed sibling that should retain TopK aggregation, and an outer sort over a materialized CTE with reordered output columns. ## What is the testing strategy for this PR? The new tests fail with two result mismatches on the unchanged upstream source. With the production change applied, the same complete `aggregates_topk.slt` file passes. The positive EXPLAIN assertion retains `AggregateExec lim=[2]`. Focused validation: https://github.com/xgbtxy/contribution-checks/actions/runs/40091933143 On upstream base `92f170cb7ea5ad87bdff8fde89ac7a1541f3b0fa`, formatting, all-target/all-feature Clippy, extended workspace tests, core/CLI tests, and the complete repository lint suite have passed. Required checks: https://github.com/xgbtxy/contribution-checks/actions/runs/40091939116 Materialized CTE control: https://github.com/xgbtxy/contribution-checks/actions/runs/40091936040 Fork CI for the submitted commit: https://github.com/xgbtxy/datafusion/actions/runs/40095216860 (28 jobs passed). The fork coverage upload lacked a token; the native tests completed successfully. ## Are there any user-facing changes? Queries that order computed aggregate or DISTINCT outputs with reused column names return the correct groups. There are no public API changes. Developed with AI assistance. The original five-row reproducer was reported by @jayzhan211 in #26691. -- 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]
