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


##########
sql/core/src/main/scala/org/apache/spark/sql/execution/limit.scala:
##########
@@ -250,17 +288,20 @@ case class TakeOrderedAndProjectExec(
     limit: Int,
     sortOrder: Seq[SortOrder],
     projectList: Seq[NamedExpression],
-    child: SparkPlan, offsetOpt: Option[Int] = None) extends UnaryExecNode {
+    child: SparkPlan,
+    offset: Int = 0) extends UnaryExecNode {
 
   override def output: Seq[Attribute] = {
     projectList.map(_.toAttribute)
   }
 
   override def executeCollect(): Array[InternalRow] = {
     val ord = new LazilyGeneratedOrdering(sortOrder, child.output)
-    val data = offsetOpt
-      .map(offset => child.execute().map(_.copy()).takeOrdered(limit + 
offset)(ord).drop(offset))
-      .getOrElse(child.execute().map(_.copy()).takeOrdered(limit)(ord))
+    val data = if (offset > 0) {
+      child.execute().map(_.copy()).takeOrdered(limit + 
offset)(ord).drop(offset)

Review Comment:
   ditto, use `mapPartitionsInternal`



##########
sql/core/src/main/scala/org/apache/spark/sql/execution/limit.scala:
##########
@@ -286,11 +327,15 @@ case class TakeOrderedAndProjectExec(
       val singlePartitionRDD = if (childRDD.getNumPartitions == 1) {
         childRDD
       } else {
-        val localTopK = offsetOpt.map(offset => childRDD.mapPartitions { iter 
=>
-          Utils.takeOrdered(iter.map(_.copy()), limit + offset)(ord)
-        }).getOrElse(childRDD.mapPartitions { iter =>
-          Utils.takeOrdered(iter.map(_.copy()), limit)(ord)
-        })
+        val localTopK = if (offset > 0) {
+          childRDD.mapPartitions { iter =>

Review Comment:
   ditto



-- 
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-unsubscr...@spark.apache.org

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


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

Reply via email to