Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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 @@ -145,6 +145,12 @@ case class BroadcastExchangeExec(
Statistics(dataSize, Some(rowCount))
}

override def resetMetrics(): Unit = {
// no-op
// BroadcastExchangeExec after materialized won't be materialized again, so we should not
// reset the metrics. Otherwise, we will lose the metrics collected in the broadcast job.
}

@transient
private lazy val promise = Promise[broadcast.Broadcast[Any]]()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,21 @@ class BroadcastExchangeSuite extends SparkPlanTest
assert(joinDF.collect().length == 1)
}
}

test("SPARK-52962: broadcast exchange should not reset metrics") {
val df = spark.range(1).toDF()
val joinDF = df.join(broadcast(df), "id")
joinDF.collect()
val broadcastExchangeExec = collect(
joinDF.queryExecution.executedPlan) { case p: BroadcastExchangeExec => p }
assert(broadcastExchangeExec.size == 1, "one and only BroadcastExchangeExec")

val broadcastExchangeNode = broadcastExchangeExec.head
val metrics = broadcastExchangeNode.metrics
assert(metrics("numOutputRows").value == 1)
broadcastExchangeNode.resetMetrics()
assert(metrics("numOutputRows").value == 1)
}
}

// Additional tests run in 'local-cluster' mode.
Expand Down