mbutrovich commented on code in PR #3842:
URL: https://github.com/apache/datafusion-comet/pull/3842#discussion_r3012439622


##########
spark/src/main/scala/org/apache/spark/sql/comet/CometExecRDD.scala:
##########
@@ -139,6 +139,18 @@ private[spark] class CometExecRDD(
       ctx.addTaskCompletionListener[Unit] { _ =>
         it.close()
         subqueries.foreach(sub => CometScalarSubquery.removeSubquery(it.id, 
sub))
+
+        // Propagate native scan metrics (bytes_scanned, output_rows) to 
Spark's task-level
+        // inputMetrics so they appear in the Spark UI "Input" column and are 
reported via
+        // the listener infrastructure. The native reader bypasses Hadoop's 
Java FileSystem,
+        // so thread-local FS statistics are never updated -- we bridge the 
gap here.
+        val bytesScannedMetric = nativeMetrics.findMetric("bytes_scanned")
+        val outputRowsMetric = nativeMetrics.findMetric("output_rows")
+        if (bytesScannedMetric.isDefined || outputRowsMetric.isDefined) {
+          val inputMetrics = ctx.taskMetrics().inputMetrics
+          bytesScannedMetric.foreach(m => inputMetrics.setBytesRead(m.value))

Review Comment:
   `foreach` already handles the `None` case for finding the metric, so I find 
wrapping this in `if` unnecessary. You save `ctx.taskMetrics().inputMetrics` 
but the result is oddly-structured conditional logic.



##########
spark/src/main/scala/org/apache/spark/sql/comet/CometMetricNode.scala:
##########
@@ -79,10 +79,21 @@ case class CometMetricNode(metrics: Map[String, SQLMetric], 
children: Seq[CometM
     }
   }
 
+  // Called via JNI from `comet_metric_node.rs`
   def set_all_from_bytes(bytes: Array[Byte]): Unit = {
     val metricNode = Metric.NativeMetricNode.parseFrom(bytes)
     set_all(metricNode)
   }
+
+  /**
+   * Finds a metric by name in this node or any descendant node. Returns the 
first match found via
+   * depth-first search.
+   */
+  def findMetric(name: String): Option[SQLMetric] = {
+    metrics.get(name).orElse {
+      children.iterator.map(_.findMetric(name)).collectFirst { case Some(m) => 
m }

Review Comment:
   Doesn't this just return the first match it finds with the metric name? 
Can't multiple plans have nodes that have "output_rows"?



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