FelixYBW commented on code in PR #13801:
URL: https://github.com/apache/gluten/pull/13801#discussion_r4704146598


##########
backends-velox/src/main/scala/org/apache/spark/sql/execution/columnar/VeloxInMemoryTableScanExec.scala:
##########
@@ -0,0 +1,186 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.spark.sql.execution.columnar
+
+import org.apache.gluten.execution.VeloxColumnarToRowExec
+
+import org.apache.spark.rdd.RDD
+import org.apache.spark.sql.catalyst.InternalRow
+import org.apache.spark.sql.catalyst.expressions.{Attribute, Expression}
+import org.apache.spark.sql.columnar.CachedBatch
+import org.apache.spark.sql.execution.metric.{SQLMetric, SQLMetrics}
+import org.apache.spark.sql.vectorized.ColumnarBatch
+
+/**
+ * [[InMemoryTableScanExec]] over a Velox columnar table cache, with read 
metrics.
+ *
+ * Spark's [[InMemoryTableScanExec]] only reports `numOutputRows`, and the 
[[CachedBatchSerializer]]
+ * API has no access to the plan node, so the cost of reading a Velox cache is 
invisible in the SQL
+ * UI. When a vanilla Spark operator reads the cache, the Velox-to-row 
conversion happens inside
+ * this node and is reported by the parent operator instead.
+ *
+ * This node subclasses [[InMemoryTableScanExec]] rather than implementing
+ * [[InMemoryTableScanLike]], so code in Spark and Gluten that matches the 
concrete class (AQE table
+ * cache stages, the SQL UI plan graph, `CollectMetricsExec`, 
`PlanUtil.isGlutenTableCache`) keeps
+ * working on every supported Spark version. It re-implements Spark's private
+ * `filteredCachedBatches` and the two execute paths to add the metrics; 
everything else is
+ * inherited.
+ *
+ * Gluten forbids inheriting from case classes because the subclass would be 
equal to its parent
+ * under case-class equality. Spark still matches the concrete 
[[InMemoryTableScanExec]] class (for
+ * example `SparkPlanInfo`, which shows the cached plan in the SQL UI, and 
`CollectMetricsExec`), so
+ * a separate [[InMemoryTableScanLike]] node would lose those features. The 
rule is suppressed here
+ * and equality is handled explicitly by `canEqual` and `equals` below.
+ */
+@SuppressWarnings(Array("io.github.zhztheplayer.scalawarts.InheritFromCaseClass"))
+class VeloxInMemoryTableScanExec(
+    attrs: Seq[Attribute],
+    preds: Seq[Expression],
+    @transient rel: InMemoryRelation)
+  extends InMemoryTableScanExec(attrs, preds, rel) {
+
+  override lazy val metrics: Map[String, SQLMetric] = Map(
+    "numOutputRows" -> SQLMetrics.createMetric(sparkContext, "number of output 
rows"),
+    "numCachedBatches" -> SQLMetrics.createMetric(sparkContext, "number of 
cached batches"),
+    "numCachedBatchesRead" ->
+      SQLMetrics.createMetric(sparkContext, "number of cached batches read 
after pruning"),
+    "cachedBytesRead" -> SQLMetrics.createSizeMetric(sparkContext, "cached 
bytes read"),
+    "readTime" -> SQLMetrics.createNanoTimingMetric(sparkContext, "time to 
read cached batches"),
+    "numInputBatches" -> SQLMetrics.createMetric(sparkContext, "number of 
columnar to row batches"),
+    "convertTime" -> SQLMetrics.createNanoTimingMetric(sparkContext, "time of 
columnar to row")

Review Comment:
   Good catch, thanks. `toRowIterator` adds milliseconds, so `convertTime` now 
uses `createTimingMetric`, the same as `genColumnarToRowMetrics`. I also 
relaxed the test assertion to `>= 0`, because millisecond increments can round 
to 0 on the small test table. The row path is still checked through 
`numInputBatches`. Fixed in ae5a7ef00.



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