You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2021/10/20 04:46:43 UTC

[GitHub] [spark] wangyum commented on a change in pull request #34291: [SPARK-37020][SQL] DS V2 LIMIT push down

wangyum commented on a change in pull request #34291:
URL: https://github.com/apache/spark/pull/34291#discussion_r732411354



##########
File path: sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/v2/V2ScanRelationPushDown.scala
##########
@@ -225,6 +225,30 @@ object V2ScanRelationPushDown extends Rule[LogicalPlan] with PredicateHelper {
       withProjection
   }
 
+  def applyLimit(plan: LogicalPlan): LogicalPlan = plan.transform {
+    case globalLimit @ GlobalLimit(_,
+        LocalLimit(limitExpr, DataSourceV2ScanRelation(_, scan, _))) =>
+      val supportsPushDownLimit = scan match {
+        case _: SupportsPushDownLimit => true
+        case v1: V1ScanWrapper =>
+          v1.v1Scan match {
+            case _: SupportsPushDownLimit => true
+            case _ => false
+          }
+        case _ => false
+      }
+      if (supportsPushDownLimit) {
+        assert(limitExpr.isInstanceOf[Literal] &&
+          limitExpr.asInstanceOf[Literal].value.isInstanceOf[Integer],
+          "Limit has to be an Integer")
+        val value = limitExpr.asInstanceOf[Literal].value.asInstanceOf[Integer]
+        PushDownUtils.pushLimit(scan, value)
+        globalLimit
+      } else {
+        globalLimit
+      }

Review comment:
       Could we avoid using `assert` here?
   ```scala
       case globalLimit @ Limit(IntegerLiteral(limitValue), DataSourceV2ScanRelation(_, scan, _)) =>
         val supportsPushDownLimit = scan match {
           case _: SupportsPushDownLimit => true
           case v1: V1ScanWrapper =>
             v1.v1Scan match {
               case _: SupportsPushDownLimit => true
               case _ => false
             }
           case _ => false
         }
         if (supportsPushDownLimit) {
           PushDownUtils.pushLimit(scan, limitValue)
           globalLimit
         } else {
           globalLimit
         }
   ```




-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org