cloud-fan commented on code in PR #37320:
URL: https://github.com/apache/spark/pull/37320#discussion_r932183215


##########
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/v2/V2ScanRelationPushDown.scala:
##########
@@ -410,12 +413,24 @@ object V2ScanRelationPushDown extends Rule[LogicalPlan] 
with PredicateHelper {
     case s @ Sort(order, _, operation @ ScanOperation(project, filter, 
sHolder: ScanBuilderHolder))
         // Without building the Scan, we do not know the resulting column 
names after aggregate
         // push-down, and thus can't push down Top-N which needs to know the 
ordering column names.
-        // TODO: we can support simple cases like GROUP BY columns directly 
and ORDER BY the same
-        //       columns, which we know the resulting column names: the 
original table columns.
-        if sHolder.pushedAggregate.isEmpty && filter.isEmpty &&
+        // In particular, we push down the simple cases like GROUP BY 
expressions directly and
+        // ORDER BY the same expressions, which we know the original table 
columns.
+        if filter.isEmpty &&
           CollapseProject.canCollapseExpressions(order, project, alwaysInline 
= true) =>
       val aliasMap = getAliasMap(project)
-      val newOrder = order.map(replaceAlias(_, 
aliasMap)).asInstanceOf[Seq[SortOrder]]
+      def findGroupExprForSortOrder(sortOrder: SortOrder): SortOrder = 
sortOrder match {

Review Comment:
   I think we can just do something similar with `replaceAlias`
   ```
   sortOrder transform {
     case a: Attribute => sHolder.pushedAggOutputMap.getOrElse(a, a)
   }
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


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

Reply via email to