Github user cloud-fan commented on a diff in the pull request:

    https://github.com/apache/spark/pull/8599#discussion_r38762488
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala
 ---
    @@ -561,7 +561,7 @@ class Analyzer(
             }
     
           case sort @ Sort(sortOrder, global, aggregate: Aggregate)
    -        if aggregate.resolved && !sort.resolved =>
    +        if aggregate.resolved =>
    --- End diff --
    
    We need to set up a stop condition for this rule, or something like `SELECT 
a, SUM(b) FROM t GROUP BY a ORDER BY a` will go through this rule again and 
again until reach the fixed point. How about changing the end of this rule to:
    ```
    if (evaluatedOrderings == sortOrder) {
      sort
    } else {
      Project(aggregate.output,
        Sort(evaluatedOrderings, global,
          aggregate.copy(aggregateExpressions = originalAggExprs ++ 
needsPushDown)))
    }
    ```


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