Skip to content

Commit d9aacb4

Browse files
committed
Should always have base metrics
1 parent 83b995e commit d9aacb4

3 files changed

Lines changed: 27 additions & 9 deletions

File tree

spark/src/main/scala/org/apache/spark/sql/comet/CometBatchScanExec.scala

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,12 @@ case class CometBatchScanExec(wrapped: BatchScanExec, runtimeFilters: Seq[Expres
141141
wrapped
142142
}
143143

144-
override lazy val metrics: Map[String, SQLMetric] = wrapped.customMetrics ++ (scan match {
145-
case s: MetricsSupport => s.getMetrics
146-
case _ => Map.empty
147-
})
144+
override lazy val metrics: Map[String, SQLMetric] =
145+
wrappedScan.customMetrics ++ CometMetricNode.baseScanMetrics(
146+
session.sparkContext) ++ (scan match {
147+
case s: MetricsSupport => s.getMetrics
148+
case _ => Map.empty
149+
})
148150

149151
@transient override lazy val partitions: Seq[Seq[InputPartition]] = wrappedScan.partitions
150152

spark/src/main/scala/org/apache/spark/sql/comet/CometMetricNode.scala

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,22 @@ object CometMetricNode {
9898
"total time (in ms) spent in this operator"))
9999
}
100100

101+
/**
102+
* Base SQL Metrics for ScanExec and BatchScanExec These are needed for various Spark systems to
103+
* function properly, and are calculated on the general iterator created by the scan operator,
104+
* regardless of which scan implementation is used.
105+
*/
106+
def baseScanMetrics(sc: SparkContext): Map[String, SQLMetric] = {
107+
Map(
108+
"numOutputRows" -> SQLMetrics.createMetric(sc, "number of output rows"),
109+
"scanTime" -> SQLMetrics.createNanoTimingMetric(sc, "scan time"))
110+
}
111+
112+
/**
113+
* Metrics specific to Parquet format in scan operators. This provides some statistics about the
114+
* read files, as well as some meta filtering occuring. These metrics are independent of the
115+
* native reader metrics.
116+
*/
101117
def parquetScanMetrics(sc: SparkContext): Map[String, SQLMetric] = {
102118
Map(
103119
"ParquetRowGroups" -> SQLMetrics.createMetric(sc, "num of Parquet row groups read"),
@@ -121,12 +137,11 @@ object CometMetricNode {
121137
"read throughput when reading Parquet file from storage (MB/sec)"))
122138
}
123139

140+
/**
141+
* SQL Metrics from the native Datafusion reader.
142+
*/
124143
def nativeScanMetrics(sc: SparkContext): Map[String, SQLMetric] = {
125144
Map(
126-
// Spark metrics for streaming pipelines
127-
"numOutputRows" -> SQLMetrics.createMetric(sc, "number of output rows"),
128-
"scanTime" -> SQLMetrics.createNanoTimingMetric(sc, "scan time"),
129-
// Datafusion reader metrics
130145
"output_rows" -> SQLMetrics.createMetric(sc, "number of output rows"),
131146
"time_elapsed_opening" ->
132147
SQLMetrics.createNanoTimingMetric(sc, "Wall clock time elapsed for file opening"),

spark/src/main/scala/org/apache/spark/sql/comet/CometScanExec.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,8 @@ case class CometScanExec(
247247
}
248248

249249
override lazy val metrics: Map[String, SQLMetric] =
250-
wrapped.driverMetrics ++ (relation.fileFormat match {
250+
wrapped.driverMetrics ++ CometMetricNode.baseScanMetrics(
251+
session.sparkContext) ++ (relation.fileFormat match {
251252
case m: MetricsSupport => m.getMetrics
252253
case _ => Map.empty
253254
})

0 commit comments

Comments
 (0)