leanken commented on a change in pull request #29431:
URL: https://github.com/apache/spark/pull/29431#discussion_r471409128
##########
File path:
sql/core/src/test/scala/org/apache/spark/sql/execution/ui/SQLAppStatusListenerSuite.scala
##########
@@ -679,6 +679,138 @@ class SQLAppStatusListenerSuite extends
SharedSparkSession with JsonTestUtils
val sparkPlanInfo =
SparkPlanInfo.fromSparkPlan(df.queryExecution.executedPlan)
assert(sparkPlanInfo.nodeName === "WholeStageCodegen (2)")
}
+
+ test("SPARK-32615: SQLMetrics validation after sparkPlanInfo updated in
AQE") {
+ val statusStore = createStatusStore()
+ val listener = statusStore.listener.get
+
+ val executionId = 0
+ val df = createTestDataFrame
+
+ // oldPlan SQLMetrics
+ // SQLPlanMetric(duration,0,timing)
+ // SQLPlanMetric(number of output rows,1,sum)
+ // SQLPlanMetric(number of output rows,2,sum)
+ val oldPlan = SparkPlanInfo.fromSparkPlan(df.queryExecution.executedPlan)
+ val oldAccumulatorIds =
+ SparkPlanGraph(oldPlan)
+ .allNodes.flatMap(_.metrics.map(_.accumulatorId))
+
+ listener.onOtherEvent(SparkListenerSQLExecutionStart(
+ executionId,
+ "test",
+ "test",
+ df.queryExecution.toString,
+ oldPlan,
+ System.currentTimeMillis()))
+
+ listener.onJobStart(SparkListenerJobStart(
+ jobId = 0,
+ time = System.currentTimeMillis(),
+ stageInfos = Seq(createStageInfo(0, 0)),
+ createProperties(executionId)))
+
+ listener.onStageSubmitted(SparkListenerStageSubmitted(createStageInfo(0,
0)))
+ listener.onTaskStart(SparkListenerTaskStart(0, 0, createTaskInfo(0, 0)))
+
+ assert(statusStore.executionMetrics(executionId).isEmpty)
+
+ // update old metrics with Id 1 & 2, since 0 is timing Metrics
+ val oldMetricsValueMap = oldAccumulatorIds.sorted.tail.map(id => (id,
100L)).toMap
+ listener.onExecutorMetricsUpdate(SparkListenerExecutorMetricsUpdate("",
Seq(
+ (0L, 0, 0, createAccumulatorInfos(oldMetricsValueMap))
+ )))
+
+ assert(statusStore.executionMetrics(executionId).size == 2)
+ statusStore.executionMetrics(executionId).foreach { m =>
+ assert(m._2 == "100")
+ }
+
+ listener.onTaskEnd(SparkListenerTaskEnd(
+ stageId = 0,
+ stageAttemptId = 0,
+ taskType = "",
+ reason = null,
+ createTaskInfo(0, 0),
+ new ExecutorMetrics,
+ null))
+
+ listener.onStageCompleted(SparkListenerStageCompleted(createStageInfo(0,
0)))
+
+ listener.onJobEnd(SparkListenerJobEnd(
+ jobId = 0,
+ time = System.currentTimeMillis(),
+ JobSucceeded
+ ))
+
+ val df2 = createTestDataFrame.filter("_2 > 2")
+ // newPlan SQLMetrics
+ // SQLPlanMetric(duration,3,timing)
+ // SQLPlanMetric(number of output rows,4,sum)
+ // SQLPlanMetric(number of output rows,5,sum)
+ val newPlan = SparkPlanInfo.fromSparkPlan(df2.queryExecution.executedPlan)
+ val newAccumulatorIds =
+ SparkPlanGraph(newPlan)
+ .allNodes.flatMap(_.metrics.map(_.accumulatorId))
+
+ // Assume that AQE update sparkPlanInfo with newPlan
+ // ExecutionMetrics will be replaced using newPlan's SQLMetrics
+ listener.onOtherEvent(SparkListenerSQLAdaptiveExecutionUpdate(
+ executionId,
+ "test",
+ newPlan))
+
+ listener.onJobStart(SparkListenerJobStart(
+ jobId = 1,
+ time = System.currentTimeMillis(),
+ stageInfos = Seq(createStageInfo(1, 0)),
+ createProperties(executionId)))
+
+ listener.onStageSubmitted(SparkListenerStageSubmitted(createStageInfo(1,
0)))
+ listener.onTaskStart(SparkListenerTaskStart(1, 0, createTaskInfo(0, 0)))
+
+ // live metrics will be override, and ExecutionMetrics should be empty as
the newPlan updated.
+ assert(statusStore.executionMetrics(executionId).isEmpty)
+
+ // update new metrics with Id 4 & 5, since 3 is timing Metrics
+ val newMetricsValueMap = newAccumulatorIds.sorted.tail.map(id => (id,
500L)).toMap
+ listener.onExecutorMetricsUpdate(SparkListenerExecutorMetricsUpdate("",
Seq(
+ (0L, 1, 0, createAccumulatorInfos(newMetricsValueMap))
+ )))
+
+ assert(statusStore.executionMetrics(executionId).size == 2)
+ statusStore.executionMetrics(executionId).foreach { m =>
+ assert(m._2 == "500")
+ }
+
+ listener.onTaskEnd(SparkListenerTaskEnd(
+ stageId = 1,
+ stageAttemptId = 0,
+ taskType = "",
+ reason = null,
+ createTaskInfo(0, 0),
+ new ExecutorMetrics,
+ null))
+
+ listener.onStageCompleted(SparkListenerStageCompleted(createStageInfo(1,
0)))
+
+ listener.onJobEnd(SparkListenerJobEnd(
+ jobId = 1,
+ time = System.currentTimeMillis(),
+ JobSucceeded
+ ))
+
+ // aggregateMetrics should ignore metrics from job 0
Review comment:
OK
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]