Uh oh!
There was an error while loading. Please reload this page.
[SPARK-36677][SQL] NestedColumnAliasing should not push down aggregate functions into projections - #33921
Closed
vicennial wants to merge 3 commits into
Closed
[SPARK-36677][SQL] NestedColumnAliasing should not push down aggregate functions into projections#33921vicennial wants to merge 3 commits into
vicennial wants to merge 3 commits into
Conversation
dongjoon-hyun
commented
Sep 6, 2021
Member
HyukjinKwon
commented
Sep 7, 2021
Member
ok to test |
HyukjinKwon
commented
Sep 7, 2021
Member
cc @karenfeng too FYI |
SparkQA
commented
Sep 7, 2021
Kubernetes integration test starting |
SparkQA
commented
Sep 7, 2021
Kubernetes integration test status failure |
SparkQA
commented
Sep 7, 2021
Test build #143032 has finished for PR 33921 at commit
|
viirya
approved these changes
Sep 8, 2021
viirya
commented
Sep 8, 2021
Member
Thanks for your contribution! Merging to master/3.2. |
viirya pushed a commit
that referenced
this pull request
Sep 8, 2021
…e functions into projections
### What changes were proposed in this pull request?
This PR filters out `ExtractValues`s that contains any aggregation function in the `NestedColumnAliasing` rule to prevent cases where aggregations are pushed down into projections.
### Why are the changes needed?
To handle a corner/missed case in `NestedColumnAliasing` that can cause users to encounter a runtime exception.
Consider the following schema:
```
root
|-- a: struct (nullable = true)
| |-- c: struct (nullable = true)
| | |-- e: string (nullable = true)
| |-- d: integer (nullable = true)
|-- b: string (nullable = true)
```
and the query:
`SELECT MAX(a).c.e FROM (SELECT a, b FROM test_aggregates) GROUP BY b`
Executing the query before this PR will result in the error:
```
java.lang.UnsupportedOperationException: Cannot generate code for expression: max(input[0, struct<c:struct<e:string>,d:int>, true])
at org.apache.spark.sql.errors.QueryExecutionErrors$.cannotGenerateCodeForExpressionError(QueryExecutionErrors.scala:83)
at org.apache.spark.sql.catalyst.expressions.Unevaluable.doGenCode(Expression.scala:312)
at org.apache.spark.sql.catalyst.expressions.Unevaluable.doGenCode$(Expression.scala:311)
at org.apache.spark.sql.catalyst.expressions.aggregate.AggregateExpression.doGenCode(interfaces.scala:99)
...
```
The optimised plan before this PR is:
```
'Aggregate [b#1], [_extract_e#5 AS max(a).c.e#3]
+- 'Project [max(a#0).c.e AS _extract_e#5, b#1]
+- Relation default.test_aggregates[a#0,b#1] parquet
```
### Does this PR introduce _any_ user-facing change?
No
### How was this patch tested?
A new unit test in `NestedColumnAliasingSuite`. The test consists of the repro mentioned earlier.
The produced optimized plan is checked for equivalency with a plan of the form:
```
Aggregate [b#452], [max(a#451).c.e AS max('a)[c][e]#456]
+- LocalRelation <empty>, [a#451, b#452]
```
Closes#33921 from vicennial/spark-36677.
Authored-by: Venkata Sai Akhil Gudesa <venkata.gudesa@databricks.com>
Signed-off-by: Liang-Chi Hsieh <viirya@gmail.com>
(cherry picked from commit 2ed6e7b)
Signed-off-by: Liang-Chi Hsieh <viirya@gmail.com>dongjoon-hyun
commented
Sep 8, 2021
Member
+1, LGTM. Thank you, @vicennial , @HyukjinKwon , @hvanhovell , @viirya . |
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 freeto 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.
What changes were proposed in this pull request?
This PR filters out
ExtractValuess that contains any aggregation function in theNestedColumnAliasingrule to prevent cases where aggregations are pushed down into projections.Why are the changes needed?
To handle a corner/missed case in
NestedColumnAliasingthat can cause users to encounter a runtime exception.Consider the following schema:
and the query:
SELECT MAX(a).c.e FROM (SELECT a, b FROM test_aggregates) GROUP BY bExecuting the query before this PR will result in the error:
The optimised plan before this PR is:
Does this PR introduce any user-facing change?
No
How was this patch tested?
A new unit test in
NestedColumnAliasingSuite. The test consists of the repro mentioned earlier.The produced optimized plan is checked for equivalency with a plan of the form: