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


##########
sql/core/src/main/scala/org/apache/spark/sql/execution/limit.scala:
##########
@@ -207,32 +230,47 @@ case class GlobalLimitExec(limit: Int, child: SparkPlan) 
extends BaseLimitExec {
  * the child's single output partition.
  */
 case class GlobalLimitAndOffsetExec(
-    limit: Int,
+    limit: Int = -1,
     offset: Int,
     child: SparkPlan) extends BaseLimitExec {
+  assert(offset > 0)
 
   override def requiredChildDistribution: List[Distribution] = AllTuples :: Nil
 
-  override def doExecute(): RDD[InternalRow] = child.execute().mapPartitions { 
iter =>
-    iter.take(limit + offset).drop(offset)
+  override def doExecute(): RDD[InternalRow] = if (limit >= 0) {
+    child.execute().mapPartitions(iter => iter.take(limit + 
offset).drop(offset))

Review Comment:
   not related to this PR, but since we are touch here, let's use 
`mapPartitionsInternal` which is more efficient.



##########
sql/core/src/main/scala/org/apache/spark/sql/execution/limit.scala:
##########
@@ -207,32 +230,47 @@ case class GlobalLimitExec(limit: Int, child: SparkPlan) 
extends BaseLimitExec {
  * the child's single output partition.
  */
 case class GlobalLimitAndOffsetExec(
-    limit: Int,
+    limit: Int = -1,
     offset: Int,
     child: SparkPlan) extends BaseLimitExec {
+  assert(offset > 0)
 
   override def requiredChildDistribution: List[Distribution] = AllTuples :: Nil
 
-  override def doExecute(): RDD[InternalRow] = child.execute().mapPartitions { 
iter =>
-    iter.take(limit + offset).drop(offset)
+  override def doExecute(): RDD[InternalRow] = if (limit >= 0) {
+    child.execute().mapPartitions(iter => iter.take(limit + 
offset).drop(offset))

Review Comment:
   not related to this PR, but since we are touching here, let's use 
`mapPartitionsInternal` which is more efficient.



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