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


##########
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.
+   */
+  def getMinReaderVersion(protocol: Any): Option[Int] = {
+    try {
+      val field = protocol.getClass.getDeclaredField("minReaderVersion")
+      field.setAccessible(true)
+      Some(field.get(protocol).asInstanceOf[Int])
+    } catch {
+      case e: Exception =>
+        logError(
+          "Delta reflection failure: Failed to get minReaderVersion from 
protocol: " +
+            s"${e.getMessage}")
+        None
+    }
+  }
+
+  def getReaderFeatures(protocol: Any): Option[Set[String]] = {
+    try {
+      val field = protocol.getClass.getDeclaredField("readerFeatures")
+      field.setAccessible(true)
+      
Some(field.get(protocol).asInstanceOf[Option[Set[String]]].getOrElse(Set.empty))
+    } catch {
+      case e: Exception =>
+        logError(
+          "Delta reflection failure: Failed to get minReaderVersion from 
protocol: " +

Review Comment:
   ```suggestion
             "Delta reflection failure: Failed to get readerFeatures from 
protocol: " +
   ```



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