|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. The ASF licenses this file |
| 6 | + * to you under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | + |
| 20 | +package org.apache.spark.sql.comet |
| 21 | + |
| 22 | +import scala.jdk.CollectionConverters._ |
| 23 | + |
| 24 | +import org.apache.spark.rdd.RDD |
| 25 | +import org.apache.spark.sql.catalyst.expressions.{Attribute, SortOrder} |
| 26 | +import org.apache.spark.sql.catalyst.plans.QueryPlan |
| 27 | +import org.apache.spark.sql.catalyst.plans.physical.{Partitioning, UnknownPartitioning} |
| 28 | +import org.apache.spark.sql.execution.FileSourceScanExec |
| 29 | +import org.apache.spark.sql.vectorized.ColumnarBatch |
| 30 | + |
| 31 | +import com.google.common.base.Objects |
| 32 | + |
| 33 | +import org.apache.comet.serde.OperatorOuterClass.Operator |
| 34 | + |
| 35 | +/** |
| 36 | + * Native Delta Lake scan that reads a table through delta-kernel-rs (behind the `delta` cargo |
| 37 | + * feature). The native `DeltaScan` operator is self-contained - it carries the table URI and the |
| 38 | + * kernel performs log replay, deletion-vector and column-mapping application, and partition-value |
| 39 | + * injection - so this leaf needs no per-partition planning data and reads the table as a single |
| 40 | + * partition. Projection, partition pruning, and predicate pushdown are follow-ups. |
| 41 | + */ |
| 42 | +case class CometDeltaNativeScanExec( |
| 43 | + override val nativeOp: Operator, |
| 44 | + override val output: Seq[Attribute], |
| 45 | + tableUri: String, |
| 46 | + @transient originalPlan: FileSourceScanExec, |
| 47 | + override val serializedPlanOpt: SerializedPlan) |
| 48 | + extends CometLeafExec { |
| 49 | + |
| 50 | + override val supportsColumnar: Boolean = true |
| 51 | + |
| 52 | + override val nodeName: String = s"CometDeltaNativeScan $tableUri" |
| 53 | + |
| 54 | + override lazy val outputPartitioning: Partitioning = UnknownPartitioning(1) |
| 55 | + |
| 56 | + override lazy val outputOrdering: Seq[SortOrder] = Nil |
| 57 | + |
| 58 | + override def doExecuteColumnar(): RDD[ColumnarBatch] = { |
| 59 | + val nativeMetrics = CometMetricNode.fromCometPlan(this) |
| 60 | + val serializedPlan = CometExec.serializeNativePlan(nativeOp) |
| 61 | + CometExecRDD( |
| 62 | + sparkContext, |
| 63 | + inputRDDs = Seq.empty, |
| 64 | + commonByKey = Map.empty, |
| 65 | + perPartitionByKey = Map.empty, |
| 66 | + serializedPlan = serializedPlan, |
| 67 | + numPartitions = 1, |
| 68 | + numOutputCols = output.length, |
| 69 | + nativeMetrics = nativeMetrics, |
| 70 | + subqueries = Seq.empty) |
| 71 | + } |
| 72 | + |
| 73 | + override def convertBlock(): CometDeltaNativeScanExec = { |
| 74 | + val newSerializedPlan = if (serializedPlanOpt.isEmpty) { |
| 75 | + SerializedPlan(Some(CometExec.serializeNativePlan(nativeOp))) |
| 76 | + } else { |
| 77 | + serializedPlanOpt |
| 78 | + } |
| 79 | + CometDeltaNativeScanExec(nativeOp, output, tableUri, originalPlan, newSerializedPlan) |
| 80 | + } |
| 81 | + |
| 82 | + override protected def doCanonicalize(): CometDeltaNativeScanExec = { |
| 83 | + CometDeltaNativeScanExec( |
| 84 | + nativeOp, |
| 85 | + output.map(QueryPlan.normalizeExpressions(_, output)), |
| 86 | + tableUri, |
| 87 | + null, |
| 88 | + SerializedPlan(None)) |
| 89 | + } |
| 90 | + |
| 91 | + override def stringArgs: Iterator[Any] = Iterator(output, tableUri) |
| 92 | + |
| 93 | + override def equals(obj: Any): Boolean = obj match { |
| 94 | + case other: CometDeltaNativeScanExec => |
| 95 | + tableUri == other.tableUri && output == other.output && |
| 96 | + serializedPlanOpt == other.serializedPlanOpt |
| 97 | + case _ => false |
| 98 | + } |
| 99 | + |
| 100 | + override def hashCode(): Int = Objects.hashCode(tableUri, output.asJava, serializedPlanOpt) |
| 101 | +} |
0 commit comments