HairstonE opened a new pull request, #23871: URL: https://github.com/apache/datafusion/pull/23871
## Which issue does this PR close? - Closes #11748. ## Rationale for this change `EliminateGroupByConstant` strips constant expressions from a GROUP BY. When it strips all of them, it turns a grouping aggregate into a global aggregate, which returns 1 row on empty input instead of 0. Original attempt: #11897. My previous PR #22132 had the correct output but at a per-row cost, whereas this solution does not have that cost. ## What changes are included in this PR? `EliminateGroupByConstant` now leaves an all-constant GROUP BY alone. When every group key is a literal and there's at least one aggregate, the physical planner plans a global AggregateExec carrying a new emit_no_rows_on_empty_input flag, with a projection re-attaching the constant columns. Now a flagged aggregate that saw no input rows emits 0 rows instead of the one default row a global aggregate returns. The flag survives plan rewrites and round-trips through the proto. A GROUP BY that isn't all-constant takes exactly the path it did before. ## Are these changes tested? Yes. A sqllogictest reproducer for the original issue (`GROUP BY false HAVING false` returning 0 rows), plus the non-HAVING case (`GROUP BY false` on empty input) and the non-empty case. Updated the optimizer SLT expectations and unit tests. ## Are there any user-facing changes? Queries with an all-constant GROUP BY over empty input now correctly return 0 rows instead of 1 row of NULL. -- 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]
