-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Improve unparsing for ORDER BY
, UNION
, Windows functions with Aggregation
#12946
Conversation
… dialect setting (#43)
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.
Thanks @sgrebnov, I think overall is good but one question and minor suggestions.
187f5e0
to
28670e3
Compare
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.
👍
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.
Thank you very much @sgrebnov and very much appreciate the help reviewing @goldmedal
Which issue does this PR close?
Improves unparsing to produce valid sql for TPC-DS benchmark queries:
Improve UNION unparsing
Fix UNION unparsing for queries where UNION is a subquery
Original query
Before (invalid):
After (correct)
Fix unparsing for ORDER BY with Aggregation functions
Improve unparsing to handle cases when
ORDER BY
clause contains aggregation functions that needs to be unprojected, otherwise it will result in unparsed/incorrect sql -Referenced column "sum(catalog_returns.cr_net_loss)" not found in FROM clause
/Referenced column "count(DISTINCT cs1.cs_order_number)" not found in FROM clause
For example TPC-DS Q42
Improve scalar functions in ORDER BY unparsing
Improve unparsing to correctly handle scalar functions in ORDER BY. If SELECT and ORDER BY contain the same expression with a scalar function, the ORDER BY expression will be replaced by a Column expression (e.g., "substr(customer.c_last_name, Int64(0), Int64(5))"), and we need to transform it back to the actual expression. This is done for scalar function expressions only.
Before
After
Fix unparsing for complex Window functions with Aggregation
Improve
unproject_agg_exprs
to unparse complex Window functions with aggregation when aggregation functions present inWhen/Then and Order By parts
.For example
case when grouping(i_class) = 0 then i_category end
andorder by sum(ws_net_paid) desc
in Windowrank()
:Are these changes tested?
Added automated tests
Are there any user-facing changes?
Unparser will generate valid sql for complex Window functions and Order By w/ aggregations and Union and Order By with Aggregation functions