cloud-fan commented on a change in pull request #34738:
URL: https://github.com/apache/spark/pull/34738#discussion_r767463374
##########
File path:
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/v2/V2ScanRelationPushDown.scala
##########
@@ -246,16 +247,42 @@ object V2ScanRelationPushDown extends Rule[LogicalPlan]
with PredicateHelper {
}
}
+ private def pushDownLimit(plan: LogicalPlan, limit: Int): LogicalPlan = plan
match {
+ case operation @ ScanOperation(_, filter, sHolder: ScanBuilderHolder) if
filter.isEmpty =>
+ val limitPushed = PushDownUtils.pushLimit(sHolder.builder, limit)
+ if (limitPushed) {
+ sHolder.pushedLimit = Some(limit)
+ }
+ operation
+ case s @ Sort(order, _, operation @ ScanOperation(_, filter, sHolder:
ScanBuilderHolder))
+ if filter.isEmpty =>
+ val orders = DataSourceStrategy.translateSortOrders(order)
+ val topNPushed = PushDownUtils.pushTopN(sHolder.builder, orders.toArray,
limit)
+ if (topNPushed) {
+ sHolder.pushedLimit = Some(limit)
+ sHolder.sortValues = orders
+ operation
+ } else {
+ s
+ }
+ case p: Project =>
+ val newChild = pushDownLimit(p.child, limit)
+ if (newChild == p.child) {
Review comment:
we can call `p.withNewChildren(Seq(newChild))`, which does this check
for you.
--
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]