Repository: spark
Updated Branches:
  refs/heads/branch-2.0 1f72e774b -> b17f10ced


[SPARK-17515] CollectLimit.execute() should perform per-partition limits

CollectLimit.execute() incorrectly omits per-partition limits, leading to 
performance regressions in case this case is hit (which should not happen in 
normal operation, but can occur in some cases (see #15068 for one example).

Regression test in SQLQuerySuite that asserts the number of records scanned 
from the input RDD.

Author: Josh Rosen <[email protected]>

Closes #15070 from JoshRosen/SPARK-17515.

(cherry picked from commit 3f6a2bb3f7beac4ce928eb660ee36258b5b9e8c8)
Signed-off-by: Herman van Hovell <[email protected]>


Project: http://git-wip-us.apache.org/repos/asf/spark/repo
Commit: http://git-wip-us.apache.org/repos/asf/spark/commit/b17f10ce
Tree: http://git-wip-us.apache.org/repos/asf/spark/tree/b17f10ce
Diff: http://git-wip-us.apache.org/repos/asf/spark/diff/b17f10ce

Branch: refs/heads/branch-2.0
Commit: b17f10ced34cbff8716610df370d19b130f93827
Parents: 1f72e77
Author: Josh Rosen <[email protected]>
Authored: Tue Sep 13 12:54:03 2016 +0200
Committer: Herman van Hovell <[email protected]>
Committed: Tue Sep 13 13:00:11 2016 +0200

----------------------------------------------------------------------
 .../main/scala/org/apache/spark/sql/execution/limit.scala   | 3 ++-
 .../src/test/scala/org/apache/spark/sql/SQLQuerySuite.scala | 9 +++++++++
 2 files changed, 11 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/spark/blob/b17f10ce/sql/core/src/main/scala/org/apache/spark/sql/execution/limit.scala
----------------------------------------------------------------------
diff --git a/sql/core/src/main/scala/org/apache/spark/sql/execution/limit.scala 
b/sql/core/src/main/scala/org/apache/spark/sql/execution/limit.scala
index 01fbe5b..86a8770 100644
--- a/sql/core/src/main/scala/org/apache/spark/sql/execution/limit.scala
+++ b/sql/core/src/main/scala/org/apache/spark/sql/execution/limit.scala
@@ -39,9 +39,10 @@ case class CollectLimitExec(limit: Int, child: SparkPlan) 
extends UnaryExecNode
   override def executeCollect(): Array[InternalRow] = child.executeTake(limit)
   private val serializer: Serializer = new 
UnsafeRowSerializer(child.output.size)
   protected override def doExecute(): RDD[InternalRow] = {
+    val locallyLimited = child.execute().mapPartitionsInternal(_.take(limit))
     val shuffled = new ShuffledRowRDD(
       ShuffleExchange.prepareShuffleDependency(
-        child.execute(), child.output, SinglePartition, serializer))
+        locallyLimited, child.output, SinglePartition, serializer))
     shuffled.mapPartitionsInternal(_.take(limit))
   }
 }

http://git-wip-us.apache.org/repos/asf/spark/blob/b17f10ce/sql/core/src/test/scala/org/apache/spark/sql/SQLQuerySuite.scala
----------------------------------------------------------------------
diff --git a/sql/core/src/test/scala/org/apache/spark/sql/SQLQuerySuite.scala 
b/sql/core/src/test/scala/org/apache/spark/sql/SQLQuerySuite.scala
index df72afb..c5bab99 100644
--- a/sql/core/src/test/scala/org/apache/spark/sql/SQLQuerySuite.scala
+++ b/sql/core/src/test/scala/org/apache/spark/sql/SQLQuerySuite.scala
@@ -2615,4 +2615,13 @@ class SQLQuerySuite extends QueryTest with 
SharedSQLContext {
         data.selectExpr("`part.col1`", "`col.1`"))
     }
   }
+
+  test("SPARK-17515: CollectLimit.execute() should perform per-partition 
limits") {
+    val numRecordsRead = spark.sparkContext.longAccumulator
+    spark.range(1, 100, 1, numPartitions = 10).map { x =>
+      numRecordsRead.add(1)
+      x
+    }.limit(1).queryExecution.toRdd.count()
+    assert(numRecordsRead.value === 10)
+  }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to