cloud-fan commented on code in PR #35975:
URL: https://github.com/apache/spark/pull/35975#discussion_r850091937
##########
sql/core/src/main/scala/org/apache/spark/sql/execution/limit.scala:
##########
@@ -182,6 +190,48 @@ case class GlobalLimitExec(limit: Int, child: SparkPlan)
extends BaseLimitExec {
copy(child = newChild)
}
+/**
+ * Skip the first `offset` elements then take the first `limit` of the
following elements in
+ * the child's single output partition.
+ */
+case class GlobalLimitAndOffsetExec(
+ limit: Int,
+ offset: Int,
+ child: SparkPlan) extends BaseLimitExec {
+
+ override def requiredChildDistribution: List[Distribution] = AllTuples :: Nil
+
+ override def outputPartitioning: Partitioning = child.outputPartitioning
+
+ override def outputOrdering: Seq[SortOrder] = child.outputOrdering
+
+ override def doExecute(): RDD[InternalRow] = {
+ val rdd = child.execute().mapPartitions { iter => iter.take(limit +
offset)}
+ rdd.zipWithIndex().filter(_._2 >= offset).map(_._1)
Review Comment:
If you look at `RDD.zipWithIndex`, it doesn't do shuffle but it submits an
extra job to get the number of records in each partition, which means it
executes the compute task twice.
I think shuffle is safer here. Let's just follow what `GlobalLimitExec` does.
--
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]