Improve unparsing to handle aggregations with grouping set #36
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_exprlist
is 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
schema
does 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_exprlist
is used directly infind_agg_exp
so 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_exp
signature will make code less clean andgrouping_set_to_exprlist
does NOT create expressions copies (operates by Vec<&Expr>)