Skip to content

Commit c89f03b

Browse files
author
Justin Uang
committed
Simple unit test
1 parent 710916c commit c89f03b

File tree

1 file changed

+10
-37
lines changed

1 file changed

+10
-37
lines changed

sql/core/src/test/scala/org/apache/spark/sql/execution/adaptive/QueryStageTest.scala

Lines changed: 10 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -17,53 +17,26 @@
1717

1818
package org.apache.spark.sql.execution.adaptive
1919

20-
import org.apache.spark.sql.catalyst.expressions.{Ascending, SortOrder}
21-
import org.apache.spark.sql.catalyst.plans.Inner
2220
import org.apache.spark.sql.catalyst.plans.physical.HashPartitioning
23-
import org.apache.spark.sql.execution.{RangeExec, SortExec}
21+
import org.apache.spark.sql.execution.RangeExec
2422
import org.apache.spark.sql.execution.exchange.ShuffleExchangeExec
25-
import org.apache.spark.sql.execution.joins.SortMergeJoinExec
2623
import org.apache.spark.sql.internal.SQLConf
2724
import org.apache.spark.sql.test.SharedSQLContext
2825

2926
class QueryStageTest extends SharedSQLContext {
30-
3127
test("Adaptive Query Execution repartitions") {
32-
val plan = createMergeJoinPlan(100, 100)
33-
34-
val resultQueryStage = PlanQueryStage.apply(new SQLConf)(plan)
28+
val originalNumPartitions = 100
3529

36-
val rdd = resultQueryStage.execute()
37-
assert(rdd.getNumPartitions == 0)
38-
}
39-
40-
def createMergeJoinPlan(leftNum: Int, rightNum: Int): SortMergeJoinExec = {
41-
val leftRangeExec = RangeExec(
42-
org.apache.spark.sql.catalyst.plans.logical.Range(1, leftNum, 1, 1))
43-
val leftOutput = leftRangeExec.output(0)
44-
val left = SortExec(
45-
Seq(SortOrder(leftOutput, Ascending)),
46-
true,
47-
ShuffleExchangeExec(
48-
HashPartitioning(Seq(leftOutput), 100),
49-
leftRangeExec))
30+
val plan = {
31+
val leftRangeExec = RangeExec(
32+
org.apache.spark.sql.catalyst.plans.logical.Range(1, 1000, 1, 1))
5033

51-
val rightRangeExec = RangeExec(
52-
org.apache.spark.sql.catalyst.plans.logical.Range(1, rightNum, 1, 1))
53-
val rightOutput = rightRangeExec.output(0)
54-
val right = SortExec(
55-
Seq(SortOrder(rightOutput, Ascending)),
56-
true,
5734
ShuffleExchangeExec(
58-
HashPartitioning(Seq(rightOutput), 100),
59-
rightRangeExec))
35+
HashPartitioning(leftRangeExec.output, originalNumPartitions),
36+
leftRangeExec)
37+
}
6038

61-
SortMergeJoinExec(
62-
Seq(leftOutput),
63-
Seq(rightOutput),
64-
Inner,
65-
None,
66-
left,
67-
right)
39+
assert(plan.execute().getNumPartitions == originalNumPartitions)
40+
assert(PlanQueryStage.apply(new SQLConf)(plan).execute().getNumPartitions == 1)
6841
}
6942
}

0 commit comments

Comments
 (0)