fix(optimizer): don't expand aggregate aliases into GROUP BY - #7971
Open
fivetran-kwoodbeck wants to merge 3 commits into
Open
fix(optimizer): don't expand aggregate aliases into GROUP BY#7971fivetran-kwoodbeck wants to merge 3 commits into
fivetran-kwoodbeck wants to merge 3 commits into
Conversation
Contributor
SQLGlot Integration Test Results✅ All tests passedComparing:
Overallmain: 192414 total, 153558 passed (pass rate: 79.8%) sqlglot:optimizer/fix-qualify-group-by-alias-collision: 180220 total, 142406 passed (pass rate: 79.0%) Transitions: Dialect pair changes: 0 previous results not found, 3 current results not found ✅ All tests passed |
fivetran-kwoodbeck
force-pushed
the
optimizer/fix-qualify-group-by-alias-collision
branch
from
July 27, 2026 17:00
56d0f7b to
ec7c86e
Compare
geooo109
reviewed
Jul 28, 2026
fivetran-kwoodbeck
force-pushed
the
optimizer/fix-qualify-group-by-alias-collision
branch
from
July 28, 2026 14:39
ec7c86e to
e4f732f
Compare
geooo109
approved these changes
Jul 28, 2026
fivetran-kwoodbeck
force-pushed
the
optimizer/fix-qualify-group-by-alias-collision
branch
from
July 28, 2026 16:38
64d2385 to
07f7ae5
Compare
fivetran-kwoodbeck
force-pushed
the
optimizer/fix-qualify-group-by-alias-collision
branch
from
July 28, 2026 18:28
07f7ae5 to
14e8554
Compare
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.
qualify_columnscan replace aGROUP BYreference with an aggregate alias's definition, nesting an aggregate insideGROUP BYwhich gives invalid SQL and is also non idempotent. Fixed by ensuring aggregate alias is never expanded whenis_group_by.Sample input:
Previous output:
Note:
GROUP BY UPPER(x)becameGROUP BY UPPER(MAX(x))which is wrong.Output after Patch: