Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,17 @@ case class AdaptiveSparkPlanExec(
stagesToReplace = result.newStages ++ stagesToReplace
executionId.foreach(onUpdatePlan(_, result.newStages.map(_.plan)))

// SPARK-33933: we should submit tasks of broadcast stages first, to avoid waiting
// for tasks to be scheduled and leading to broadcast timeout.
val reorderedNewStages = result.newStages
Comment thread
zhongyu09 marked this conversation as resolved.
.sortWith {
case (_: BroadcastQueryStageExec, _: BroadcastQueryStageExec) => false
case (_: BroadcastQueryStageExec, _) => true
case _ => false
}

// Start materialization of all new stages and fail fast if any stages failed eagerly
result.newStages.foreach { stage =>
reorderedNewStages.foreach { stage =>
try {
stage.materialize().onComplete { res =>
if (res.isSuccess) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,29 @@ abstract class BroadcastJoinSuiteBase extends QueryTest with SQLTestUtils
}
}

test("SPARK-33933: AQE broadcast should not timeout with slow map tasks") {
Comment thread
zhongyu09 marked this conversation as resolved.
Outdated
Comment thread
zhongyu09 marked this conversation as resolved.
Outdated
val broadcastTimeoutInSec = 5
val df = spark.sparkContext.parallelize(Range(0, 1000), 1000)
.flatMap(x => {
Thread.sleep(20)
for (i <- Range(0, 100)) yield (x % 26, x % 10)
}).toDF("index", "pv")
val dim = Range(0, 26).map(x => (x, ('a' + x).toChar.toString))
.toDF("index", "name")
val testDf = df.groupBy("index")
.agg(sum($"pv").alias("pv"))
.join(dim, Seq("index"))
withSQLConf(SQLConf.BROADCAST_TIMEOUT.key -> broadcastTimeoutInSec.toString,
SQLConf.ADAPTIVE_EXECUTION_ENABLED.key -> "true") {
val startTime = System.currentTimeMillis()
val result = testDf.collect()
val queryTime = System.currentTimeMillis() - startTime
assert(result.length == 26)
// make sure the execution time is large enough
assert(queryTime > (broadcastTimeoutInSec + 1) * 1000)
}
}

test("broadcast join where streamed side's output partitioning is HashPartitioning") {
withTable("t1", "t3") {
withSQLConf(SQLConf.AUTO_BROADCASTJOIN_THRESHOLD.key -> "500") {
Expand Down