Github user yhuai commented on a diff in the pull request:
https://github.com/apache/spark/pull/3910#discussion_r22806871
--- Diff:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/planning/patterns.scala
---
@@ -153,11 +153,11 @@ object PartialAggregation {
partialEvaluations(new TreeNodeRef(e)).finalEvaluation
case e: Expression =>
- // Should trim aliases around `GetField`s. These aliases are
introduced while
- // resolving struct field accesses, because `GetField` is not
a `NamedExpression`.
- // (Should we just turn `GetField` into a `NamedExpression`?)
namedGroupingExpressions
- .get(e.transform { case Alias(g: GetField, _) => g })
+ // Should trim aliases. These aliases can only be introduced
while resolving unnamed
+ // expressions like `GetField` and UDF calls, because GROUP
BY clause doesn't allow
+ // aliasing.
+ .get(e.transform { case a: Alias => a.child })
--- End diff --
Seems this line can remove needed aliases. For example, in `subq2.q`
```sql
SELECT a.k, a.c
FROM (SELECT b.key as k, count(1) as c FROM src b GROUP BY b.key) a
WHERE a.k >= 90;
```
We have the following plans.
```
[info] == Parsed Logical Plan ==
[info] 'Project ['a.k,'a.c]
[info] 'Filter ('a.k >= 90)
[info] 'Subquery a
[info] 'Aggregate ['b.key], ['b.key AS k#84130,COUNT(1) AS c#84131L]
[info] 'UnresolvedRelation [src], Some(b)
[info]
[info] == Analyzed Logical Plan ==
[info] Project [k#84130,c#84131L]
[info] Filter (k#84130 >= 90)
[info] Aggregate [key#84132], [key#84132 AS k#84130,COUNT(1) AS
c#84131L]
[info] MetastoreRelation default, src, Some(b)
[info]
[info] == Optimized Logical Plan ==
[info] Filter (k#84130 >= 90)
[info] Aggregate [key#84132], [key#84132 AS k#84130,COUNT(1) AS c#84131L]
[info] Project [key#84132]
[info] MetastoreRelation default, src, Some(b)
[info]
[info] == Physical Plan ==
[info] !Filter (k#84130 >= 90)
[info] Aggregate false, [key#84132],
[key#84132,Coalesce(SUM(PartialCount#84135L),0) AS c#84131L]
[info] Exchange (HashPartitioning [key#84132], 2)
[info] Aggregate true, [key#84132], [key#84132,COUNT(1) AS
PartialCount#84135L]
[info] HiveTableScan [key#84132], (MetastoreRelation default, src,
Some(b)), None
```
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]