-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Fix bugs in SQL planner with GROUP BY scalar function and alias #2457
Conversation
// 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)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the fix .. we were comparing qualified and unqualified names before this, leading to failures in some cases
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am a huge fan of the comments ❤️ thank you
Thanks for the review @alamb ! |
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 BY
where an alias from the projection could have the same name as an input to the aggregate planc0
when the grouping expression issubstr(c0, 1, 2)
Are there any user-facing changes?
No