Github user maropu commented on a diff in the pull request:

    https://github.com/apache/spark/pull/17191#discussion_r112173197
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala
 ---
    @@ -161,6 +161,8 @@ class Analyzer(
           HandleNullInputsForUDF),
         Batch("FixNullability", Once,
           FixNullability),
    +    Batch("ResolveAggAliasInGroupBy", Once,
    +      ResolveAggAliasInGroupBy),
    --- End diff --
    
    Finally, I found we couldn't easily put  the two rule outside `Resolution` 
batch. If we put them outside `Resolution` batch, upper operators depending on 
`Aggregate` resolutions (that is, `Aggregate.resolved`) cannot resolve their 
own expressions because grouping keys are unresolved during processing 
`Resolution` batch. IIUC since `ResolveOrdinalInOrderByAndGroupBy` has the same 
limitation, we put it inside `Resolution` batch. For example, if we put the two 
rule outside `Resolution` batch, we could get an exception below;
    ```
    
    scala> sql("""select a as k, count(b) from (select 1 as a, 1 as b) group by 
k having k = 1""").show
    org.apache.spark.sql.AnalysisException: cannot resolve '`k`' given input 
columns: [k, count(b)]; line 1 pos 71;
    'Filter ('k = 1)
    +- Aggregate [a#71], [a#71 AS k#73, count(b#72) AS count(b)#75L]
       +- Project [1 AS a#71, 1 AS b#72]
          +- OneRowRelation$
    ```
    So, we put back `ResolveAggAliasInGroupBy` inside `Resolution` batch and 
add a test case for that.


---
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]

Reply via email to