cloud-fan commented on code in PR #53358:
URL: https://github.com/apache/spark/pull/53358#discussion_r2610449979


##########
sql/core/src/main/scala/org/apache/spark/sql/classic/ObservationManager.scala:
##########
@@ -56,10 +56,22 @@ private[sql] class ObservationManager(session: 
SparkSession) {
     val allMetrics = qe.observedMetrics
     qe.logical.foreach {
       case c: CollectMetrics =>
-        allMetrics.get(c.name).foreach { metrics =>
+        val keyExists = observations.containsKey((c.name, c.dataframeId))
+        val metrics = allMetrics.get(c.name)
+        if (keyExists && metrics.isEmpty) {
+          // If the key exists but no metrics were collected, it means for 
some reason the metrics
+          // could not be collected. This can happen e.g., if the 
CollectMetricsExec was optimized
+          // away.
           val observation = observations.remove((c.name, c.dataframeId))
           if (observation != null) {
-            observation.setMetricsAndNotify(metrics)
+            observation.setMetricsAndNotify(Row.empty)
+          }
+        } else {
+          metrics.foreach { metrics =>

Review Comment:
   `metrics.foreach { metric`



##########
sql/core/src/main/scala/org/apache/spark/sql/classic/ObservationManager.scala:
##########
@@ -56,10 +56,22 @@ private[sql] class ObservationManager(session: 
SparkSession) {
     val allMetrics = qe.observedMetrics
     qe.logical.foreach {
       case c: CollectMetrics =>
-        allMetrics.get(c.name).foreach { metrics =>
+        val keyExists = observations.containsKey((c.name, c.dataframeId))
+        val metrics = allMetrics.get(c.name)
+        if (keyExists && metrics.isEmpty) {
+          // If the key exists but no metrics were collected, it means for 
some reason the metrics
+          // could not be collected. This can happen e.g., if the 
CollectMetricsExec was optimized
+          // away.
           val observation = observations.remove((c.name, c.dataframeId))
           if (observation != null) {
-            observation.setMetricsAndNotify(metrics)
+            observation.setMetricsAndNotify(Row.empty)
+          }
+        } else {
+          metrics.foreach { metrics =>

Review Comment:
   `metrics.foreach { metric =>`



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to