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

    https://github.com/apache/spark/pull/11846#discussion_r57021217
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala
 ---
    @@ -659,6 +669,40 @@ class Analyzer(
             }
             Sort(newOrders, global, child)
     
    +      // Replace the index with the corresponding expression in 
aggregateExpressions. The index is
    +      // a 1-base position of aggregateExpressions, which is output 
columns (select expression)
    +      case a @ Aggregate(groups, aggs, child)
    +          if conf.groupByOrdinal && child.resolved && 
aggs.forall(_.resolved) &&
    +            groups.exists(IntegerIndex.unapply(_).nonEmpty) =>
    +        val newGroups = groups.map {
    +          case IntegerIndex(index) if index > 0 && index <= aggs.size =>
    +            aggs(index - 1) match {
    +              case e if ResolveAggregateFunctions.containsAggregate(e) =>
    +                throw new UnresolvedException(a,
    +                  s"Group by position: the '$index'th column in the select 
contains an " +
    +                  s"aggregate function: ${e.sql}. Aggregate functions are 
not allowed in GROUP BY")
    +              // Group by clause is unable to use the alias defined in 
aggregateExpressions
    --- End diff --
    
    This part is used to handle the case like:
    ```SQL
    SELECT a, (b + 2) as c, count(2) FROM testData2 GROUP BY a, 2
    ```
    If we do not have this case, I think our Spark SQL is unable to handle the 
following converted plan:
    ```SQL
    SELECT a, (b + 2) as c, count(2) FROM testData2 GROUP BY a, c
    ```
    
    In addition, our parser does not support the following query:
    ```SQL
    SELECT 1, sum(b) FROM testData2 GROUP BY (b + 1) as c
    ```


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