sunchao commented on code in PR #5935:
URL: https://github.com/apache/datafusion-comet/pull/5935#discussion_r4012308240


##########
spark/src/main/scala/org/apache/comet/iceberg/IcebergReflection.scala:
##########
@@ -560,6 +562,27 @@ object IcebergReflection extends Logging {
     }
   }
 
+  /**
+   * The FileIO class that actually opens `location`: the delegate a 
`ResolvingFileIO` picks for
+   * it (`ResolvingFileIO.ioClass`), or the FileIO's own class otherwise. 
`None` on reflection
+   * failure; callers must fail closed.
+   */
+  def resolveFileIOClass(fileIO: Any, location: String): Option[Class[_]] =
+    if (!classNameInHierarchy(fileIO.getClass, 
Set(ClassNames.RESOLVING_FILE_IO))) {
+      Some(fileIO.getClass)
+    } else {
+      try {
+        val ioClassMethod = getMethod(fileIO.getClass, "ioClass", 
classOf[String])
+        Option(ioClassMethod.invoke(fileIO, location).asInstanceOf[Class[_]])

Review Comment:
   ### Correctness
   
   **[P2] Inspect the instantiated ResolvingFileIO delegate**
   
   `ioClass(location)` does not return the delegate that opens the file: it 
maps the scheme to a class and calls `Class.forName`, without consulting 
`ioInstances`. The actual `io(location)` separately initializes that class and 
catches `IllegalArgumentException` to cache a `HadoopFileIO`. See [Iceberg 
1.8.1](https://github.com/apache/iceberg/blob/9ce0fcf0af7becf25ad9fc996c3bad2afdcfd33d/core/src/main/java/org/apache/iceberg/io/ResolvingFileIO.java#L163-L237).
   
   For example, with the GCS libraries present, 
`gcs.channel.read.chunk-size-bytes=invalid` makes 1.8.1's 
`GCSFileIO.initialize` throw `NumberFormatException`, so JVM writes use the 
Hadoop fallback. This helper still returns `GCSFileIO`, and the new gate admits 
a native write that drops that delegate's `fs.gs.*` configuration. This 
recreates the identity/endpoint mismatch this PR is intended to prevent.
   
   Please inspect the actual delegate (including initialization fallback), or 
decline the unresolved case. Add a regression where the scheme-mapped class is 
GCSFileIO but the effective delegate is HadoopFileIO; deriving the test 
expectation from this same helper misses that distinction.



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