@@ -1456,11 +1456,7 @@ class Analyzer(
14561456
14571457 val resolvedGroupingExprs = a.groupingExpressions
14581458 .map(resolveExpressionTopDown(_, planForResolve, trimAlias = true ))
1459- .map {
1460- // trim Alias over top-level GetStructField
1461- case Alias (s : GetStructField , _) => s
1462- case other => other
1463- }
1459+ .map(trimTopLevelGetStructFieldAlias)
14641460
14651461 val resolvedAggExprs = a.aggregateExpressions
14661462 .map(resolveExpressionTopDown(_, planForResolve, trimAlias = true ))
@@ -1471,19 +1467,11 @@ class Analyzer(
14711467 case g : GroupingSets =>
14721468 val resolvedSelectedExprs = g.selectedGroupByExprs
14731469 .map(_.map(resolveExpressionTopDown(_, g, trimAlias = true ))
1474- .map {
1475- // trim Alias over top-level GetStructField
1476- case Alias (s : GetStructField , _) => s
1477- case other => other
1478- })
1470+ .map(trimTopLevelGetStructFieldAlias))
14791471
14801472 val resolvedGroupingExprs = g.groupByExprs
14811473 .map(resolveExpressionTopDown(_, g, trimAlias = true ))
1482- .map {
1483- // trim Alias over top-level GetStructField
1484- case Alias (s : GetStructField , _) => s
1485- case other => other
1486- }
1474+ .map(trimTopLevelGetStructFieldAlias)
14871475
14881476 val resolvedAggExprs = g.aggregations
14891477 .map(resolveExpressionTopDown(_, g, trimAlias = true ))
@@ -1585,6 +1573,17 @@ class Analyzer(
15851573 AttributeSet (projectList.collect { case a : Alias => a.toAttribute })
15861574 }
15871575
1576+ // This method is used to trim groupByExpressions/selectedGroupByExpressions's top-level
1577+ // GetStructField Alias. Since these expression are not NamedExpression originally,
1578+ // we are safely to trim top-level GetStructField Alias.
1579+ def trimTopLevelGetStructFieldAlias (e : Expression ): Expression = {
1580+ e match {
1581+ // trim Alias over top-level GetStructField
1582+ case Alias (s : GetStructField , _) => s
1583+ case other => other
1584+ }
1585+ }
1586+
15881587 /**
15891588 * Build a project list for Project/Aggregate and expand the star if possible
15901589 */
0 commit comments