-
Notifications
You must be signed in to change notification settings - Fork 706
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat(optimizer): optimize pivots #1617
Merged
Merged
Conversation
This file contains 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
georgesittas
force-pushed
the
jo/pivot_optimization
branch
from
May 14, 2023 10:12
5b3c3cd
to
c279777
Compare
georgesittas
commented
May 14, 2023
georgesittas
commented
May 14, 2023
georgesittas
commented
May 14, 2023
georgesittas
commented
May 14, 2023
georgesittas
commented
May 14, 2023
georgesittas
commented
May 14, 2023
georgesittas
commented
May 14, 2023
Left some comments on the PR for clarity (they're now marked as resolved), let me know if something's not clear. Interested to hear alternatives, would love to simplify this somehow. |
georgesittas
commented
May 14, 2023
georgesittas
commented
May 14, 2023
georgesittas
commented
May 14, 2023
tobymao
reviewed
May 15, 2023
tobymao
reviewed
May 15, 2023
georgesittas
force-pushed
the
jo/pivot_optimization
branch
from
May 15, 2023 17:01
6703b06
to
f8baa73
Compare
TODO:
|
tobymao
reviewed
May 15, 2023
tobymao
reviewed
May 15, 2023
tobymao
reviewed
May 15, 2023
tobymao
approved these changes
May 15, 2023
@tobymao made a few more changes, let me know if you take a look.
|
adrianisk
pushed a commit
to adrianisk/sqlglot
that referenced
this pull request
Jun 21, 2023
* Feat(optimizer): optimize pivots * Fixup * Simplify * Cleanup * Fix pivot sql generation * Fixed snowflake pivot column names, add another optimizer test * Fixed issue with pivoted cte source, added bigquery test * Factor out some computations * Cleanup * Add transform to unalias pivot in spark, more tests * Typo * Comment fixup
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.
Fixes #1449
This PR introduces optimizer logic for handling the PIVOT operator, i.e. explode & qualify the columns of the table it produces where necessary. It's a first draft towards the general solution, which is more difficult because we may have multiple JOINs and / or PIVOTs, UNPIVOTs chained together in non-trivial ways.
We could also try to transform PIVOT operators using
exp.Case
expressions. This seems a bit less straightforward to me if we want to get it right in all cases. For example:GROUP BY
if there are additional columns besides what's referenced in theexp.Pivot
expression?COUNT(*)
?The major advantage of this approach, though, would be that we'd get back a canonical query without
PIVOT
s.References: