Improve unparsing to handle aggregations with grouping set#36
Merged
sgrebnov merged 3 commits intospiceai-42from Oct 1, 2024
Merged
Improve unparsing to handle aggregations with grouping set#36sgrebnov merged 3 commits intospiceai-42from
sgrebnov merged 3 commits intospiceai-42from
Conversation
Sevenannn
approved these changes
Oct 1, 2024
Author
|
Created PR to datafusion combining this and previous improvement. Merged this PR to unblock TPC-DS queries, will add required changes based on review/feedback if any: |
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?
PR improves Aggregation unparsing logic to handle plans with grouping sets. When Aggregation is created (below)
grouping_set_to_exprlistis used to retrieve grouping set expressions and populate schema (qualified_fields)https://github.com/apache/datafusion/blob/f54712d8c2545fc0dd60cdc693704992e9d82eef/datafusion/expr/src/logical_plan/plan.rs#L2953C9-L2977C6
PR adds the same step/logic to correctly retrieve all aggregation expressions when unproject columns. W/o this logic current unproject logic fails as
schemadoes not matchagg.group_exp + agg.aggr_expr(must begrouping_set_to_exprlist(agg.group_exp) + agg.aggr_expr) : can't get and then unwrap unprojected expression by index: https://github.com/apache/datafusion/blob/f54712d8c2545fc0dd60cdc693704992e9d82eef/datafusion/sql/src/unparser/utils.rs#L92Concern
grouping_set_to_exprlistis used directly infind_agg_expso invoked for each column to unproject (in case of grouping set). This could be optimized to do this only once. Decided to keep this logic this way as pre-calculating and passing such expressions as argument or changingfind_agg_expsignature will make code less clean andgrouping_set_to_exprlistdoes NOT create expressions copies (operates by Vec<&Expr>)