Skip to content

Commit ba43922

Browse files
manuzhanggatorsmile
andcommitted
[SPARK-31658][SQL] Fix SQL UI not showing write commands of AQE plan
Show write commands on SQL UI of an AQE plan Currently the leaf node of an AQE plan is always a `AdaptiveSparkPlan` which is not true when it's a child of a write command. Hence, the node of the write command as well as its metrics are not shown on the SQL UI. ![image](https://user-images.githubusercontent.com/1191767/81288918-1893f580-9098-11ea-9771-e3d0820ba806.png) ![image](https://user-images.githubusercontent.com/1191767/81289008-3a8d7800-9098-11ea-93ec-516bbaf25d2d.png) No Add UT. Closes #28474 from manuzhang/aqe-ui. Lead-authored-by: manuzhang <[email protected]> Co-authored-by: Xiao Li <[email protected]> Signed-off-by: gatorsmile <[email protected]> (cherry picked from commit 77c690a) Signed-off-by: gatorsmile <[email protected]>
1 parent 57b55ea commit ba43922

File tree

2 files changed

+34
-5
lines changed

2 files changed

+34
-5
lines changed

sql/core/src/main/scala/org/apache/spark/sql/execution/adaptive/AdaptiveSparkPlanExec.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -526,8 +526,8 @@ case class AdaptiveSparkPlanExec(
526526
} else {
527527
context.session.sparkContext.listenerBus.post(SparkListenerSQLAdaptiveExecutionUpdate(
528528
executionId,
529-
SQLExecution.getQueryExecution(executionId).toString,
530-
SparkPlanInfo.fromSparkPlan(this)))
529+
context.qe.toString,
530+
SparkPlanInfo.fromSparkPlan(context.qe.executedPlan)))
531531
}
532532
}
533533

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

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -805,9 +805,11 @@ class AdaptiveQueryExecSuite
805805
test("SPARK-30953: InsertAdaptiveSparkPlan should apply AQE on child plan of write commands") {
806806
withSQLConf(SQLConf.ADAPTIVE_EXECUTION_ENABLED.key -> "true",
807807
SQLConf.ADAPTIVE_EXECUTION_FORCE_APPLY.key -> "true") {
808-
val plan = sql("CREATE TABLE t1 AS SELECT 1 col").queryExecution.executedPlan
809-
assert(plan.isInstanceOf[DataWritingCommandExec])
810-
assert(plan.asInstanceOf[DataWritingCommandExec].child.isInstanceOf[AdaptiveSparkPlanExec])
808+
withTable("t1") {
809+
val plan = sql("CREATE TABLE t1 AS SELECT 1 col").queryExecution.executedPlan
810+
assert(plan.isInstanceOf[DataWritingCommandExec])
811+
assert(plan.asInstanceOf[DataWritingCommandExec].child.isInstanceOf[AdaptiveSparkPlanExec])
812+
}
811813
}
812814
}
813815

@@ -847,4 +849,31 @@ class AdaptiveQueryExecSuite
847849
}
848850
}
849851
}
852+
853+
test("SPARK-31658: SQL UI should show write commands") {
854+
withSQLConf(SQLConf.ADAPTIVE_EXECUTION_ENABLED.key -> "true",
855+
SQLConf.ADAPTIVE_EXECUTION_FORCE_APPLY.key -> "true") {
856+
withTable("t1") {
857+
var checkDone = false
858+
val listener = new SparkListener {
859+
override def onOtherEvent(event: SparkListenerEvent): Unit = {
860+
event match {
861+
case SparkListenerSQLAdaptiveExecutionUpdate(_, _, planInfo) =>
862+
assert(planInfo.nodeName == "Execute CreateDataSourceTableAsSelectCommand")
863+
checkDone = true
864+
case _ => // ignore other events
865+
}
866+
}
867+
}
868+
spark.sparkContext.addSparkListener(listener)
869+
try {
870+
sql("CREATE TABLE t1 AS SELECT 1 col").collect()
871+
spark.sparkContext.listenerBus.waitUntilEmpty()
872+
assert(checkDone)
873+
} finally {
874+
spark.sparkContext.removeSparkListener(listener)
875+
}
876+
}
877+
}
878+
}
850879
}

0 commit comments

Comments
 (0)