feat: Unparse LogicalPlans with grouping aggregate functions #66
+81
−3
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?
Rationale for this change
DataFusion v43 added a new analyzer rule
ResolveGroupingFunction
that supports grouping aggregate functions in select expressions with grouping set aggregations.i.e.
As mentioned in the implementing PR (apache#12704) this is necessary to run several queries in the TPC-DS benchmark suite.
Unfortunately, logical plans that contain a
grouping
function that are run through this analyzer cannot be unparsed anymore, running into the error:Internal error: Tried to unproject column referring to internal grouping id.
This was because the plan was being transformed from this:
to this:
With this change, the unparser correctly supports unparsing back to the original SQL by taking the original SQL that was preserved in the column alias, and returning it directly in a Placeholder expression.
What changes are included in this PR?
When the unparser encounters the internal grouping id column, it returns a placeholder expression with the original SQL representing the grouping aggregate function.
Are these changes tested?
Yes
Are there any user-facing changes?
No