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_r253015103
 
 

 ##########
 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:
   In that case, it is better to keep original plan for investigating, I think. 
You can see that if we can't resolve aggregate expressions, we do just return 
original plan. By changing original plan like that, it makes debugging harder.

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