FelixYBW opened a new pull request, #13801:
URL: https://github.com/apache/gluten/pull/13801

   ## What changes are proposed in this pull request?
   
   Spark's `InMemoryTableScanExec` only reports `numOutputRows`, and the 
`CachedBatchSerializer` API has no access to the plan node, so the cost of 
reading a Velox columnar table cache does not show up in the SQL UI. When a 
query over a Velox cache falls back to vanilla Spark, the Velox-to-row 
conversion of the whole cache also runs inside the scan node, and its time is 
reported by the parent operator (for example as `time in aggregation build` of 
a vanilla `HashAggregate`), which makes it hard to diagnose.
   
   This PR adds `VeloxInMemoryTableScanExec`, which replaces 
`InMemoryTableScanExec` when the scan reads a Velox columnar table cache 
(`PlanUtil.isGlutenTableCache`), and reports:
   
   | Metric | Meaning |
   |---|---|
   | `numOutputRows` | Unchanged from Spark |
   | `numCachedBatches` | Cached batches in the scanned partitions, before 
partition-stats pruning |
   | `numCachedBatchesRead` | Cached batches left after pruning |
   | `cachedBytesRead` | Sum of `CachedBatch.sizeInBytes` of the batches read |
   | `readTime` | Time spent getting batches from the serializer (cache 
iteration plus native deserialization) |
   | `numInputBatches`, `convertTime` | Batches converted and time spent in 
`VeloxColumnarToRowExec` when a row-based consumer reads the cache; zero for 
columnar consumers |
   
   Design notes:
   
   - **Subclass, not a new node.** `VeloxInMemoryTableScanExec` extends 
`InMemoryTableScanExec` and overrides only `metrics`, `doExecute` and 
`doExecuteColumnar`, re-implementing Spark's private `filteredCachedBatches` 
(about ten lines). Spark still matches the concrete class in `SparkPlanInfo` 
(the cached plan shown under the scan in the SQL UI), `CollectMetricsExec`, 
`InsertAdaptiveSparkPlan` and AQE's table cache stages, and so does Gluten 
(`PlanUtil`, `VeloxBackend.batchTypeOf`, `ExpandFallbackPolicy`, ...). A 
separate `InMemoryTableScanLike` node would lose those, and the trait does not 
exist on Spark 3.4. The constructor of `InMemoryTableScanExec` is the same from 
Spark 3.4 to master.
   - **`InheritFromCaseClass` is suppressed on this one class.** The wart 
exists because a subclass is equal to its parent under case-class equality. 
That matters here: `TreeNode.transform` keeps the original node when the rule's 
result `fastEquals` it, so the replacement would be dropped silently. 
`canEqual` and `equals` are overridden so the two classes are never equal.
   - **Rule placement.** Under AQE, the scan is wrapped in a 
`TableCacheQueryStageExec` before Gluten's columnar rules run, and 
`postStageCreationRules` are not applied to it. `VeloxTableCacheScanRule` is 
therefore registered as a query stage preparation rule (runs before stage 
creation) and as a final Gluten columnar rule (non-AQE plans).
   - Spark's test-only accumulators (`readPartitions`, `readBatches`) and the 
row-path `numOutputRows` accounting are kept as in Spark.
   
   ## How was this patch tested?
   
   Built in `apache/gluten:vcpkg-almalinux-8-gcc13` (native Velox build plus 
Maven):
   
   - New tests in `VeloxColumnarCacheSuite`: read metrics with AQE on and off, 
columnar-to-row metrics for a vanilla consumer, and batches pruned by partition 
statistics. The suite passes (14 tests, including the 11 existing ones).
   - Spark cache UTs through `gluten-ut` on Spark 3.5: `GlutenCachedTableSuite` 
and `GlutenDatasetCacheSuite` pass (85 succeeded, 4 ignored by the existing 
test settings).
   - `backends-velox` compiles with `-Pspark-3.4` and with `-Pspark-4.0 
-Pjava-17 -Pscala-2.13`.
   - `./dev/format-scala-code.sh` and the license header check pass.
   
   ## Was this patch authored or co-authored using generative AI tooling?
   
   Generated-by: Claude Code (Claude Opus 5.5)
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


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