AngersZhuuuu opened a new pull request #28490:
URL: https://github.com/apache/spark/pull/28490
### What changes were proposed in this pull request?
Will wrong with below SQL
```
test("TEST STRUCT FIELD WITH GROUP BY with CUBE") {
withTable("t1") {
sql(
"""create table t1(
|a string,
|b int,
|c array<struct<row_id:int,json_string:string>>)
|using orc""".stripMargin)
sql(
"""
|select a,
coalesce(get_json_object(each.json_string,'$.iType'),'-127') as iType, sum(b)
|from t1
|LATERAL VIEW explode(c) x AS each
|group by a, get_json_object(each.json_string,'$.iType')
|with cube
|""".stripMargin).explain(true)
}
}
```
ErrorĀ
```
expression 'x.`each`' is neither present in the group by, nor is it an
aggregate function. Add to group by or wrap in first() (or first_value) if you
don't care which value you get.;;
Aggregate [a#230, get_json_object(each#222.json_string AS json_string#223,
$.iType)#231, spark_grouping_id#229L], [a#230,
coalesce(get_json_object(each#222.json_string, $.iType), -127) AS iType#218,
sum(cast(b#220 as bigint)) AS sum(b)#226L]
```
It is because for Struct type Field, it will add a Alias by default but with
different exprId,
This make `ResolveGroupingAnalytics.constructAggregateExprs()` failed to
replace expression by expand output attribute.
### Why are the changes needed?
Fix analyze bug
### Does this PR introduce _any_ user-facing change?
NO
### How was this patch tested?
Added UT
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]