-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-35712][SQL] Simplify ResolveAggregateFunctions #32470
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -652,3 +652,15 @@ case object UnresolvedSeed extends LeafExpression with Unevaluable { | |
| override def dataType: DataType = throw new UnresolvedException("dataType") | ||
| override lazy val resolved = false | ||
| } | ||
|
|
||
| /** | ||
| * An intermediate expression to hold a resolved (nested) column. Some rules may need to undo the | ||
| * column resolution and use this expression to keep the original column name. | ||
| */ | ||
| case class TempResolvedColumn(child: Expression, nameParts: Seq[String]) extends UnaryExpression | ||
|
||
| with Unevaluable { | ||
| override lazy val canonicalized = child.canonicalized | ||
| override def dataType: DataType = child.dataType | ||
| override protected def withNewChildInternal(newChild: Expression): Expression = | ||
| copy(child = newChild) | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -287,9 +287,9 @@ class ResolveGroupingAnalyticsSuite extends AnalysisTest { | |
| Seq(GroupingSets(Seq(Seq(), Seq(unresolved_a), Seq(unresolved_a, unresolved_b)))), | ||
| Seq(unresolved_a, unresolved_b), r1)) | ||
| val expected = Project(Seq(a, b), Sort( | ||
| Seq(SortOrder('aggOrder.byte.withNullability(false), Ascending)), true, | ||
| Seq(SortOrder(grouping_a, Ascending)), true, | ||
| Aggregate(Seq(a, b, gid), | ||
| Seq(a, b, grouping_a.as("aggOrder")), | ||
| Seq(a, b, gid), | ||
|
||
| Expand( | ||
| Seq(Seq(a, b, c, nulInt, nulStr, 3L), Seq(a, b, c, a, nulStr, 1L), | ||
| Seq(a, b, c, a, b, 0L)), | ||
|
|
@@ -309,9 +309,9 @@ class ResolveGroupingAnalyticsSuite extends AnalysisTest { | |
| Seq(GroupingSets(Seq(Seq(), Seq(unresolved_a), Seq(unresolved_a, unresolved_b)))), | ||
| Seq(unresolved_a, unresolved_b), r1)) | ||
| val expected3 = Project(Seq(a, b), Sort( | ||
| Seq(SortOrder('aggOrder.long.withNullability(false), Ascending)), true, | ||
| Seq(SortOrder(gid, Ascending)), true, | ||
| Aggregate(Seq(a, b, gid), | ||
| Seq(a, b, gid.as("aggOrder")), | ||
| Seq(a, b, gid), | ||
| Expand( | ||
| Seq(Seq(a, b, c, nulInt, nulStr, 3L), Seq(a, b, c, a, nulStr, 1L), | ||
| Seq(a, b, c, a, b, 0L)), | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -149,14 +149,13 @@ EXPLAIN FORMATTED | |
| struct<plan:string> | ||
| -- !query output | ||
| == Physical Plan == | ||
| AdaptiveSparkPlan (8) | ||
| +- Project (7) | ||
| +- Filter (6) | ||
| +- HashAggregate (5) | ||
| +- Exchange (4) | ||
| +- HashAggregate (3) | ||
| +- Filter (2) | ||
| +- Scan parquet default.explain_temp1 (1) | ||
| AdaptiveSparkPlan (7) | ||
| +- Filter (6) | ||
| +- HashAggregate (5) | ||
| +- Exchange (4) | ||
| +- HashAggregate (3) | ||
| +- Filter (2) | ||
| +- Scan parquet default.explain_temp1 (1) | ||
|
|
||
|
|
||
| (1) Scan parquet default.explain_temp1 | ||
|
|
@@ -186,17 +185,13 @@ Input [2]: [key#x, max#x] | |
| Keys [1]: [key#x] | ||
| Functions [1]: [max(val#x)] | ||
| Aggregate Attributes [1]: [max(val#x)#x] | ||
| Results [3]: [key#x, max(val#x)#x AS max(val)#x, max(val#x)#x AS max(val#x)#x] | ||
| Results [2]: [key#x, max(val#x)#x AS max(val)#x] | ||
|
||
|
|
||
| (6) Filter | ||
| Input [3]: [key#x, max(val)#x, max(val#x)#x] | ||
| Condition : (isnotnull(max(val#x)#x) AND (max(val#x)#x > 0)) | ||
|
|
||
| (7) Project | ||
| Output [2]: [key#x, max(val)#x] | ||
| Input [3]: [key#x, max(val)#x, max(val#x)#x] | ||
| Input [2]: [key#x, max(val)#x] | ||
| Condition : (isnotnull(max(val)#x) AND (max(val)#x > 0)) | ||
|
|
||
| (8) AdaptiveSparkPlan | ||
| (7) AdaptiveSparkPlan | ||
| Output [2]: [key#x, max(val)#x] | ||
| Arguments: isFinalPlan=false | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -148,14 +148,13 @@ EXPLAIN FORMATTED | |
| struct<plan:string> | ||
| -- !query output | ||
| == Physical Plan == | ||
| * Project (8) | ||
| +- * Filter (7) | ||
| +- * HashAggregate (6) | ||
| +- Exchange (5) | ||
| +- * HashAggregate (4) | ||
| +- * Filter (3) | ||
| +- * ColumnarToRow (2) | ||
| +- Scan parquet default.explain_temp1 (1) | ||
| * Filter (7) | ||
| +- * HashAggregate (6) | ||
| +- Exchange (5) | ||
| +- * HashAggregate (4) | ||
| +- * Filter (3) | ||
| +- * ColumnarToRow (2) | ||
| +- Scan parquet default.explain_temp1 (1) | ||
|
|
||
|
|
||
| (1) Scan parquet default.explain_temp1 | ||
|
|
@@ -188,15 +187,11 @@ Input [2]: [key#x, max#x] | |
| Keys [1]: [key#x] | ||
| Functions [1]: [max(val#x)] | ||
| Aggregate Attributes [1]: [max(val#x)#x] | ||
| Results [3]: [key#x, max(val#x)#x AS max(val)#x, max(val#x)#x AS max(val#x)#x] | ||
| Results [2]: [key#x, max(val#x)#x AS max(val)#x] | ||
|
||
|
|
||
| (7) Filter [codegen id : 2] | ||
| Input [3]: [key#x, max(val)#x, max(val#x)#x] | ||
| Condition : (isnotnull(max(val#x)#x) AND (max(val#x)#x > 0)) | ||
|
|
||
| (8) Project [codegen id : 2] | ||
| Output [2]: [key#x, max(val)#x] | ||
| Input [3]: [key#x, max(val)#x, max(val#x)#x] | ||
| Input [2]: [key#x, max(val)#x] | ||
| Condition : (isnotnull(max(val)#x) AND (max(val)#x > 0)) | ||
|
|
||
|
|
||
| -- !query | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
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.
Expression.referencesdoesn't count outer refs, so this is unnecessary. It can miss some cases if the outer ref is the same as local ref (e.g. the outer query and inner query select from the same table)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.
Good catch!