viirya commented on a change in pull request #23701: [SPARK-26741][SQL] Allow 
using aggregate expressions in ORDER BY clause
URL: https://github.com/apache/spark/pull/23701#discussion_r253006150
 
 

 ##########
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala
 ##########
 @@ -1666,10 +1679,12 @@ class Analyzer(
           // we need to check this and prevent applying this rule multiple 
times
           if (sortOrder == finalSortOrders) {
             sort
+          } else if (needsPushDown.isEmpty) {
+            Sort(finalSortOrders, global, child)
           } else {
-            Project(aggregate.output,
+            Project(child.output,
               Sort(finalSortOrders, global,
-                aggregate.copy(aggregateExpressions = originalAggExprs ++ 
needsPushDown)))
+                pushDownMissingAttrs(needsPushDown, child)))
 
 Review comment:
   Seems the principle we followed now is to return original plan if we can't 
push down it. Should we also follow it here?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to