fix(sql): handle GROUP BY ALL with aliased aggregates#20943
Open
kumarUjjawal wants to merge 2 commits intoapache:mainfrom
Open
fix(sql): handle GROUP BY ALL with aliased aggregates#20943kumarUjjawal wants to merge 2 commits intoapache:mainfrom
kumarUjjawal wants to merge 2 commits intoapache:mainfrom
Conversation
neilconway
approved these changes
Mar 15, 2026
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn count_aggregated_group_by_all_alias() -> Result<()> { |
Contributor
There was a problem hiding this comment.
Seems like this would be better as an SLT test?
| } | ||
|
|
||
| #[test] | ||
| fn select_count_with_group_by_all() { |
Contributor
There was a problem hiding this comment.
The two tests in this file pass without the fix. Probably best to remove them?
datafusion/sql/src/select.rs
Outdated
| // Filter and collect non-aggregate select expressions | ||
| // 'group by all' groups wrt. all select expressions except aggregate expressions. | ||
| // Note: aggregate expressions can be nested under one or more aliases | ||
| // (e.g. count(1) AS count(*) AS c), so detect aggregates recursively. |
Contributor
There was a problem hiding this comment.
This comment is a bit misleading, because that SQL statement doesn't parse. The problem seems to actually occur in practice because of a (nested) alias inserted by the analyzer, which AFAICS you can't do from SQL. I'd probably just remove the change to the comment.
Contributor
Author
|
Thanks @neilconway for the feedback |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
Rationale for this change
Issue #20909 reported that:
The failure came from an incorrect plan that grouped by an aggregate alias expression.
What changes are included in this PR?
This PR fixes GROUP BY ALL when the select list has an aliased aggregate like COUNT(*) AS c.
Changes:
Are these changes tested?
Yes
Are there any user-facing changes?