This is an automated email from the ASF dual-hosted git repository.

nastra pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/iceberg.git


The following commit(s) were added to refs/heads/main by this push:
     new 575446ebf4 Spark: Fix dropped file length in 
SerializableFileIOWithSize (#16284)
575446ebf4 is described below

commit 575446ebf47e450e4b0016323d490767d7e5707b
Author: Ajay Yadav <[email protected]>
AuthorDate: Tue May 12 20:55:58 2026 +0530

    Spark: Fix dropped file length in SerializableFileIOWithSize (#16284)
    
    When executing queries on cloud storage, SerializableFileIOWithSize
    dropped the file length when intercepting FileIO.newInputFile(path, length)
    requests. This caused underlying IO modules like GCSFileIO to execute
    expensive and synchronous object metadata API calls to determine file sizes
    when reading columnar footers.
    
    This PR adds the missing newInputFile(String path, long length) override
    to SerializableFileIOWithSize across all affected Spark modules, preserving
    the length parameter and eliminating the unnecessary metadata lookups.
---
 .../spark/source/SerializableFileIOWithSize.java   |  5 +++
 .../source/TestSerializableFileIOWithSize.java     | 51 ++++++++++++++++++++++
 .../spark/source/SerializableFileIOWithSize.java   |  5 +++
 .../source/TestSerializableFileIOWithSize.java     | 51 ++++++++++++++++++++++
 .../spark/source/SerializableFileIOWithSize.java   |  5 +++
 .../source/TestSerializableFileIOWithSize.java     | 51 ++++++++++++++++++++++
 6 files changed, 168 insertions(+)

diff --git 
a/spark/v3.5/spark/src/main/java/org/apache/iceberg/spark/source/SerializableFileIOWithSize.java
 
b/spark/v3.5/spark/src/main/java/org/apache/iceberg/spark/source/SerializableFileIOWithSize.java
index 49189d9d57..2a359110c8 100644
--- 
a/spark/v3.5/spark/src/main/java/org/apache/iceberg/spark/source/SerializableFileIOWithSize.java
+++ 
b/spark/v3.5/spark/src/main/java/org/apache/iceberg/spark/source/SerializableFileIOWithSize.java
@@ -74,6 +74,11 @@ class SerializableFileIOWithSize
     return fileIO.newInputFile(path);
   }
 
+  @Override
+  public InputFile newInputFile(String path, long length) {
+    return fileIO.newInputFile(path, length);
+  }
+
   @Override
   public OutputFile newOutputFile(String path) {
     return fileIO.newOutputFile(path);
diff --git 
a/spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/source/TestSerializableFileIOWithSize.java
 
b/spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/source/TestSerializableFileIOWithSize.java
new file mode 100644
index 0000000000..e025114f4f
--- /dev/null
+++ 
b/spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/source/TestSerializableFileIOWithSize.java
@@ -0,0 +1,51 @@
+/*
+ * 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.iceberg.spark.source;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+
+import org.apache.iceberg.io.FileIO;
+import org.junit.jupiter.api.Test;
+
+class TestSerializableFileIOWithSize {
+
+  @Test
+  void newInputFileWithLength() {
+    FileIO mockFileIO = mock(FileIO.class);
+    FileIO serializableFileIO = SerializableFileIOWithSize.wrap(mockFileIO);
+    String path = "gs://bucket/path/to/file.parquet";
+    long length = 1024L;
+
+    serializableFileIO.newInputFile(path, length);
+
+    verify(mockFileIO).newInputFile(path, length);
+  }
+
+  @Test
+  void newInputFileWithoutLength() {
+    FileIO mockFileIO = mock(FileIO.class);
+    FileIO serializableFileIO = SerializableFileIOWithSize.wrap(mockFileIO);
+    String path = "gs://bucket/path/to/file.parquet";
+
+    serializableFileIO.newInputFile(path);
+
+    verify(mockFileIO).newInputFile(path);
+  }
+}
diff --git 
a/spark/v4.0/spark/src/main/java/org/apache/iceberg/spark/source/SerializableFileIOWithSize.java
 
b/spark/v4.0/spark/src/main/java/org/apache/iceberg/spark/source/SerializableFileIOWithSize.java
index 49189d9d57..2a359110c8 100644
--- 
a/spark/v4.0/spark/src/main/java/org/apache/iceberg/spark/source/SerializableFileIOWithSize.java
+++ 
b/spark/v4.0/spark/src/main/java/org/apache/iceberg/spark/source/SerializableFileIOWithSize.java
@@ -74,6 +74,11 @@ class SerializableFileIOWithSize
     return fileIO.newInputFile(path);
   }
 
+  @Override
+  public InputFile newInputFile(String path, long length) {
+    return fileIO.newInputFile(path, length);
+  }
+
   @Override
   public OutputFile newOutputFile(String path) {
     return fileIO.newOutputFile(path);
diff --git 
a/spark/v4.0/spark/src/test/java/org/apache/iceberg/spark/source/TestSerializableFileIOWithSize.java
 
b/spark/v4.0/spark/src/test/java/org/apache/iceberg/spark/source/TestSerializableFileIOWithSize.java
new file mode 100644
index 0000000000..e025114f4f
--- /dev/null
+++ 
b/spark/v4.0/spark/src/test/java/org/apache/iceberg/spark/source/TestSerializableFileIOWithSize.java
@@ -0,0 +1,51 @@
+/*
+ * 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.iceberg.spark.source;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+
+import org.apache.iceberg.io.FileIO;
+import org.junit.jupiter.api.Test;
+
+class TestSerializableFileIOWithSize {
+
+  @Test
+  void newInputFileWithLength() {
+    FileIO mockFileIO = mock(FileIO.class);
+    FileIO serializableFileIO = SerializableFileIOWithSize.wrap(mockFileIO);
+    String path = "gs://bucket/path/to/file.parquet";
+    long length = 1024L;
+
+    serializableFileIO.newInputFile(path, length);
+
+    verify(mockFileIO).newInputFile(path, length);
+  }
+
+  @Test
+  void newInputFileWithoutLength() {
+    FileIO mockFileIO = mock(FileIO.class);
+    FileIO serializableFileIO = SerializableFileIOWithSize.wrap(mockFileIO);
+    String path = "gs://bucket/path/to/file.parquet";
+
+    serializableFileIO.newInputFile(path);
+
+    verify(mockFileIO).newInputFile(path);
+  }
+}
diff --git 
a/spark/v4.1/spark/src/main/java/org/apache/iceberg/spark/source/SerializableFileIOWithSize.java
 
b/spark/v4.1/spark/src/main/java/org/apache/iceberg/spark/source/SerializableFileIOWithSize.java
index 49189d9d57..2a359110c8 100644
--- 
a/spark/v4.1/spark/src/main/java/org/apache/iceberg/spark/source/SerializableFileIOWithSize.java
+++ 
b/spark/v4.1/spark/src/main/java/org/apache/iceberg/spark/source/SerializableFileIOWithSize.java
@@ -74,6 +74,11 @@ class SerializableFileIOWithSize
     return fileIO.newInputFile(path);
   }
 
+  @Override
+  public InputFile newInputFile(String path, long length) {
+    return fileIO.newInputFile(path, length);
+  }
+
   @Override
   public OutputFile newOutputFile(String path) {
     return fileIO.newOutputFile(path);
diff --git 
a/spark/v4.1/spark/src/test/java/org/apache/iceberg/spark/source/TestSerializableFileIOWithSize.java
 
b/spark/v4.1/spark/src/test/java/org/apache/iceberg/spark/source/TestSerializableFileIOWithSize.java
new file mode 100644
index 0000000000..e025114f4f
--- /dev/null
+++ 
b/spark/v4.1/spark/src/test/java/org/apache/iceberg/spark/source/TestSerializableFileIOWithSize.java
@@ -0,0 +1,51 @@
+/*
+ * 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.iceberg.spark.source;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+
+import org.apache.iceberg.io.FileIO;
+import org.junit.jupiter.api.Test;
+
+class TestSerializableFileIOWithSize {
+
+  @Test
+  void newInputFileWithLength() {
+    FileIO mockFileIO = mock(FileIO.class);
+    FileIO serializableFileIO = SerializableFileIOWithSize.wrap(mockFileIO);
+    String path = "gs://bucket/path/to/file.parquet";
+    long length = 1024L;
+
+    serializableFileIO.newInputFile(path, length);
+
+    verify(mockFileIO).newInputFile(path, length);
+  }
+
+  @Test
+  void newInputFileWithoutLength() {
+    FileIO mockFileIO = mock(FileIO.class);
+    FileIO serializableFileIO = SerializableFileIOWithSize.wrap(mockFileIO);
+    String path = "gs://bucket/path/to/file.parquet";
+
+    serializableFileIO.newInputFile(path);
+
+    verify(mockFileIO).newInputFile(path);
+  }
+}

Reply via email to