andygrove commented on code in PR #5051: URL: https://github.com/apache/datafusion-comet/pull/5051#discussion_r3872507896
########## spark/src/main/scala/org/apache/spark/sql/comet/CometInMemoryTableScanExec.scala: ########## @@ -0,0 +1,142 @@ +/* + * 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.comet + +import scala.collection.JavaConverters._ + +import org.apache.spark.rdd.RDD +import org.apache.spark.sql.catalyst.expressions.Attribute +import org.apache.spark.sql.columnar.CachedBatchSerializer +import org.apache.spark.sql.execution.LeafExecNode +import org.apache.spark.sql.execution.columnar.{CachedRDDBuilder, InMemoryTableScanExec} +import org.apache.spark.sql.execution.metric.{SQLMetric, SQLMetrics} +import org.apache.spark.sql.vectorized.ColumnarBatch + +import org.apache.comet.CometConf +import org.apache.comet.serde.CometOperatorSerde +import org.apache.comet.serde.OperatorOuterClass +import org.apache.comet.serde.OperatorOuterClass.Operator +import org.apache.comet.serde.QueryPlanSerde.serializeDataType + +/** + * Reads Spark cached table data when the cache was written by Comet's cache serializer. + * + * Spark stores cached data through `CachedBatchSerializer`. This node keeps the scan inside Comet + * by asking the serializer to decode cached batches directly into `ColumnarBatch` output, + * avoiding the extra Spark columnar-to-Comet columnar conversion used by the default path. + * + * `relationOutput` is the full schema stored in the cache. `scanOutput` is the subset requested + * by this scan after pruning. + */ +case class CometInMemoryTableScanExec( + originalPlan: InMemoryTableScanExec, + serializer: CachedBatchSerializer, + cacheBuilder: CachedRDDBuilder, Review Comment: Fixed in 70f046abf. `CometInMemoryTableScanExec` now overrides `doCanonicalize` and canonicalizes `originalPlan` by deferring to `InMemoryTableScanExec`, which normalizes its own attributes and predicates against the relation's output. `relationOutput` and `scanOutput` were already normalized by `QueryPlan`, and `cacheBuilder` and `serializer` are the same instances, so that one field was the whole difference. Regression test: `Comet in-memory cache scans of one cache canonicalize equal, so exchanges are reused`, using your UNION-of-two-aggregates shape. It asserts one exchange plus one `ReusedExchangeExec`; reverted, it finds two exchanges and no reuse. It also asserts that two scans differing only in their pushed predicates still canonicalize unequal. That is the reason for deferring rather than nulling the field the way `CometNativeExec.canonicalizePlans` does for embedded plans, which would have equated those as well. -- 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]
