Fix bugs in SQL planner with GROUP BY scalar function and alias#2457
Merged
andygrove merged 5 commits intoapache:masterfrom May 6, 2022
Merged
Fix bugs in SQL planner with GROUP BY scalar function and alias#2457andygrove merged 5 commits intoapache:masterfrom
andygrove merged 5 commits intoapache:masterfrom
Conversation
andygrove
commented
May 6, 2022
| // now attempt to resolve columns and replace with fully-qualified columns | ||
| let aggr_projection_exprs = aggr_projection_exprs | ||
| .iter() | ||
| .map(|expr| resolve_columns(expr, &input)) |
Member
Author
There was a problem hiding this comment.
This is the fix .. we were comparing qualified and unqualified names before this, leading to failures in some cases
alamb
approved these changes
May 6, 2022
Contributor
alamb
left a comment
There was a problem hiding this comment.
I also tried out some more exotic queries and they seem to work as expected 👍
❯ select substr(substr(location, 4), 1) a from andrew group by substr(substr(location, 4), 1);
+-----------+
| a |
+-----------+
| ta_monica |
| ote_creek |
| et_sound |
+-----------+
❯ select substr(location, 4) a from andrew group by substr(location, 5);
Plan("Projection references non-aggregate values: Expression #andrew.location could not be resolved from available columns: #substr(andrew.location,Int64(5))")I did find an issue with a query which technically probably shouldn't be run:
❯ select substr(location, 4) a from andrew group by a;
+-----------+
| a |
+-----------+
| ote_creek |
| et_sound |
| ta_monica |
+-----------+As the a is defined logically after the grouping
However, that query also works on the master branch prior to this PR
| .aggregate(group_by_exprs.clone(), aggr_exprs.clone())? | ||
| .build()?; | ||
|
|
||
| // in this next section of code we are re-writing the projection to refer to columns |
Contributor
There was a problem hiding this comment.
I am a huge fan of the comments ❤️ thank you
Member
Author
|
Thanks for the review @alamb ! |
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?
Closes #2430
Rationale for this change
Fix bugs that prevent us from running some valid aggregate SQL queries.
What changes are included in this PR?
GROUP BYwhere an alias from the projection could have the same name as an input to the aggregate planc0when the grouping expression issubstr(c0, 1, 2)Are there any user-facing changes?
No