Kimahriman commented on code in PR #3035:
URL: https://github.com/apache/datafusion-comet/pull/3035#discussion_r2878424383


##########
spark/src/main/scala/org/apache/comet/delta/DeltaReflection.scala:
##########
@@ -0,0 +1,121 @@
+/*
+ * 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.comet.delta
+
+import org.apache.spark.internal.Logging
+
+/**
+ * Shared reflection utilities for Delta operations.
+ *
+ * This object provides common reflection methods used across Comet for 
interacting with Delta
+ * classes without requiring a runtime dependency on Delta
+ */
+object DeltaReflection extends Logging {
+
+  /**
+   * Gets the Delta Protocol from a Spark FileFormat
+   */
+  def getProtocol(fileFormat: Any): Option[Any] = {
+    try {
+      val field = fileFormat.getClass.getDeclaredField("protocol")
+      field.setAccessible(true)
+      Some(field.get(fileFormat))
+    } catch {
+      case e: Exception =>
+        logError(
+          s"Delta reflection failure: Failed to get protocol from FileFormat: 
${e.getMessage}")
+        None
+    }
+  }
+
+  /**
+   * Gets the tasks from a SparkScan.
+   *
+   * The tasks() method is protected in SparkScan, requiring reflection to 
access.
+   */

Review Comment:
   Copy pasta, fixed



##########
spark/src/main/scala/org/apache/spark/sql/comet/CometScanExec.scala:
##########
@@ -583,7 +584,33 @@ object CometScanExec {
   def isFileFormatSupported(fileFormat: FileFormat): Boolean = {
     // Only support Spark's built-in Parquet scans, not others such as Delta 
which use a subclass
     // of ParquetFileFormat.
-    fileFormat.getClass().equals(classOf[ParquetFileFormat])
+    fileFormat.getClass().equals(classOf[ParquetFileFormat]) || 
isSupportedDeltaScan(fileFormat)
+  }
+
+  val unsupportedDeltaReaderFeatures: Set[String] = Set("columnMapping", 
"deletionVectors")
+
+  def isSupportedDeltaScan(fileFormat: FileFormat): Boolean = {
+    if (fileFormat.getClass().getName() != 
"org.apache.spark.sql.delta.DeltaParquetFileFormat") {
+      return false
+    }
+
+    // Delta scans without certain features enabled are simply normal Parquet 
scans that can
+    // take advantage of the native scan, so check to see if it is compatible
+    val deltaMetadata = CometDeltaNativeScanMetadata.extract(fileFormat) match 
{
+      case Some(m) => m
+      case None => return false
+    }
+
+    // Version 1 has no special features
+    // Version 2 introduced column mapping, which is not supported
+    // Version 3 changes to use the readerFeatures list instead, so we check 
for incompatible
+    // features
+    deltaMetadata.minReaderVersion match {
+      case 1 => true
+      case 2 => false
+      case 3 =>

Review Comment:
   Reader version 3 switched to named features instead of incremental versions, 
so there will never be another reader version. I can still handle more 
gracefully if you would like though



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