tshauck opened a new pull request, #18831: URL: https://github.com/apache/datafusion/pull/18831
## Which issue does this PR close? - Closes #18683 ``` ./target/debug/datafusion-cli DataFusion CLI v51.0.0 > create table t(a int, b int) as values (1,3), (3,4), (4,5); 0 row(s) fetched. Elapsed 0.021 seconds. > select a from t group by a order by min(b); +---+ | a | +---+ | 1 | | 3 | | 4 | +---+ 3 row(s) fetched. Elapsed 0.017 seconds. > EXPLAIN select a from t group by a order by min(b); +---------------+-------------------------------+ | plan_type | plan | +---------------+-------------------------------+ | physical_plan | ┌───────────────────────────┐ | | | │ ProjectionExec │ | | | │ -------------------- │ | | | │ a: a │ | | | └─────────────┬─────────────┘ | | | ┌─────────────┴─────────────┐ | | | │ SortPreservingMergeExec │ | | | │ -------------------- │ | | | │ min(t.b) ASC NULLS LAST │ | | | └─────────────┬─────────────┘ | | | ┌─────────────┴─────────────┐ | | | │ SortExec │ | | | │ -------------------- │ | | | │ min(t.b)@1 ASC NULLS LAST │ | | | └─────────────┬─────────────┘ | | | ┌─────────────┴─────────────┐ | | | │ AggregateExec │ | | | │ -------------------- │ | | | │ aggr: min(t.b) │ | | | │ group_by: a │ | | | │ │ | | | │ mode: │ | | | │ FinalPartitioned │ | | | └─────────────┬─────────────┘ | | | ┌─────────────┴─────────────┐ | | | │ CoalesceBatchesExec │ | | | │ -------------------- │ | | | │ target_batch_size: │ | | | │ 8192 │ | | | └─────────────┬─────────────┘ | | | ┌─────────────┴─────────────┐ | | | │ RepartitionExec │ | | | │ -------------------- │ | | | │ partition_count(in->out): │ | | | │ 1 -> 8 │ | | | │ │ | | | │ partitioning_scheme: │ | | | │ Hash([a@0], 8) │ | | | └─────────────┬─────────────┘ | | | ┌─────────────┴─────────────┐ | | | │ AggregateExec │ | | | │ -------------------- │ | | | │ aggr: min(t.b) │ | | | │ group_by: a │ | | | │ mode: Partial │ | | | └─────────────┬─────────────┘ | | | ┌─────────────┴─────────────┐ | | | │ DataSourceExec │ | | | │ -------------------- │ | | | │ bytes: 224 │ | | | │ format: memory │ | | | │ rows: 1 │ | | | └───────────────────────────┘ | | | | +---------------+-------------------------------+ 1 row(s) fetched. Elapsed 0.019 seconds. ``` ## Rationale for this change This PR fixes a bug where if there's an aggregate expression in the order by that is not included in the projection, the query fails as the expression isn't propagated. ## What changes are included in this PR? Fixes the bug by making sure expressions in the order by are also passed to the aggregate function. ## Are these changes tested? Yes, tests are added to ensure the query compiles and produces the proper plan. ## 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]
