Skip to content

Commit 2dfc648

Browse files
committed
Add failing test illustrating bad exchange planning.
1 parent 4399b7b commit 2dfc648

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

sql/core/src/test/scala/org/apache/spark/sql/execution/ExchangeSuite.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package org.apache.spark.sql.execution
1919

2020
import org.apache.spark.sql.Row
2121
import org.apache.spark.sql.catalyst.plans.physical.SinglePartition
22+
import org.apache.spark.sql.execution.joins.SortMergeJoin
2223

2324
class ExchangeSuite extends SparkPlanTest {
2425
test("shuffling UnsafeRows in exchange") {
@@ -29,4 +30,14 @@ class ExchangeSuite extends SparkPlanTest {
2930
input.map(Row.fromTuple)
3031
)
3132
}
33+
34+
test("EnsureRequirements shouldn't add exchange to SMJ inputs if both are SinglePartition") {
35+
val df = (1 to 10).map(Tuple1.apply).toDF("a").repartition(1)
36+
val keys = Seq(df.col("a").expr)
37+
val smj = SortMergeJoin(keys, keys, df.queryExecution.sparkPlan, df.queryExecution.sparkPlan)
38+
val afterEnsureRequirements = EnsureRequirements(df.sqlContext).apply(smj)
39+
if (afterEnsureRequirements.collect { case Exchange(_, _) => true }.nonEmpty) {
40+
fail(s"No Exchanges should have been added:\n$afterEnsureRequirements")
41+
}
42+
}
3243
}

0 commit comments

Comments
 (0)