-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-31670][SQL] Trim unnecessary Struct field alias in Aggregate/GroupingSets #28490
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 1 commit
27c495b
4c0b04c
282648d
c4ff823
6d1b60e
e28b084
1ee0542
0af3166
5f0562c
7ecc8ad
53fd03a
cf818cf
cf31ab4
f846539
d63613f
ef6c87f
82f3876
d0f89af
3ebec5f
72dc305
d3ffbbd
f17dd53
891fd1b
281096a
51cea07
84e65af
9411887
e6fb91f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3495,6 +3495,59 @@ class SQLQuerySuite extends QueryTest with SharedSparkSession with AdaptiveSpark | |
| assert(df4.schema.head.name === "randn(1)") | ||
| checkIfSeedExistsInExplain(df2) | ||
| } | ||
|
|
||
| test("SPARK-31670: Struct Field in groupByExpr with CUBE") { | ||
|
||
| withTable("t1") { | ||
|
||
| sql( | ||
| """create table t1( | ||
| |a string, | ||
| |b int, | ||
| |c array<struct<row_id:int,json_string:string>>, | ||
| |d array<array<string>>, | ||
| |e array<map<string, int>>) | ||
| |using orc""".stripMargin) | ||
|
||
|
|
||
| checkAnswer( | ||
| sql( | ||
| """ | ||
| |select a, each.json_string, sum(b) | ||
|
||
| |from t1 | ||
| |LATERAL VIEW explode(c) x AS each | ||
| |group by a, each.json_string | ||
| |with cube | ||
| |""".stripMargin), Nil) | ||
|
|
||
| checkAnswer( | ||
| sql( | ||
| """ | ||
| |select a, get_json_object(each.json_string, '$.i'), sum(b) | ||
| |from t1 | ||
| |LATERAL VIEW explode(c) x AS each | ||
| |group by a, get_json_object(each.json_string, '$.i') | ||
| |with cube | ||
| |""".stripMargin), Nil) | ||
|
|
||
| checkAnswer( | ||
| sql( | ||
| """ | ||
| |select a, each.json_string as json_string, sum(b) | ||
| |from t1 | ||
| |LATERAL VIEW explode(c) x AS each | ||
| |group by a, each.json_string | ||
| |with cube | ||
| |""".stripMargin), Nil) | ||
|
|
||
| checkAnswer( | ||
| sql( | ||
| """ | ||
| |select a, each.json_string as js, sum(b) | ||
| |from t1 | ||
| |LATERAL VIEW explode(c) x AS each | ||
| |group by a, each.json_string | ||
| |with cube | ||
|
||
| |""".stripMargin), Nil) | ||
|
||
| } | ||
| } | ||
| } | ||
|
|
||
| case class Foo(bar: Option[String]) | ||
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.
Probably, we should not fix this issue in
ResolveGroupingAnalytics, but inResolveRefencesjust like this;A root cause seems to be that
ResolveReferencesassigns different exprIds toeach#30.json_string AS json_strings (#31vs#32);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.
cc: @cloud-fan @viirya
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.
Based on above analysis, seems it is caused by
ResolveReferences, instead ofResolveGroupingAnalytics? Can we possibly have a reproducible case without CUBE?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.
This happened with cube when construct cube LogicalPlan.
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.
The shown query plan above seems before
ResolveGroupingAnalytics? So without CUBE is it possible to encounter similar issue? @maropuThere 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.
Yea, StructGetFiled will construct with a alias in ResolveReference and got different ExprID
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.
Also having clause.. may have this problem. I didn't thinking enough case.
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.
Yea, all the cases have the same issue;