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

xiangfu0 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pinot.git


The following commit(s) were added to refs/heads/master by this push:
     new 62958d8ff1b Throw FileNotFoundException from 
GcsPinotFS.copyToLocalFile for a missing object (#20026)
62958d8ff1b is described below

commit 62958d8ff1bb90a84b6324466a4cbcab943191c2
Author: Suvodeep Pyne <[email protected]>
AuthorDate: Sat Oct 24 13:59:19 2026 -0700

    Throw FileNotFoundException from GcsPinotFS.copyToLocalFile for a missing 
object (#20026)
    
    copyToLocalFile reported a missing source object through 
Preconditions.checkState,
    so callers saw an IllegalStateException ("File '...' does not exists") that 
is
    indistinguishable from a code bug. It now throws FileNotFoundException 
naming the
    source URI, matching open() and copyFile() in the same class, so callers 
can tell
    a missing object apart from other failures.
    
    Adds a unit test that copies a missing blob and asserts the exception type 
and message.
---
 .../apache/pinot/plugin/filesystem/GcsPinotFS.java |  4 +++-
 .../filesystem/GcsPinotFSNullSafetyTest.java       | 22 ++++++++++++++++++++++
 2 files changed, 25 insertions(+), 1 deletion(-)

diff --git 
a/pinot-plugins/pinot-file-system/pinot-gcs/src/main/java/org/apache/pinot/plugin/filesystem/GcsPinotFS.java
 
b/pinot-plugins/pinot-file-system/pinot-gcs/src/main/java/org/apache/pinot/plugin/filesystem/GcsPinotFS.java
index 8be710e30ed..5beb3da0ce5 100644
--- 
a/pinot-plugins/pinot-file-system/pinot-gcs/src/main/java/org/apache/pinot/plugin/filesystem/GcsPinotFS.java
+++ 
b/pinot-plugins/pinot-file-system/pinot-gcs/src/main/java/org/apache/pinot/plugin/filesystem/GcsPinotFS.java
@@ -323,7 +323,9 @@ public class GcsPinotFS extends BasePinotFS {
     checkState(!dstFile.isDirectory(), "File '%s' must not be a directory", 
dstFile);
     FileUtils.forceMkdir(dstFile.getParentFile());
     Blob blob = getBlob(new GcsUri(srcUri));
-    checkState(existsBlob(blob), "File '%s' does not exists", srcUri);
+    if (!existsBlob(blob)) {
+      throw new FileNotFoundException("File '" + srcUri + "' does not exist");
+    }
     blob.downloadTo(dstFile.toPath());
   }
 
diff --git 
a/pinot-plugins/pinot-file-system/pinot-gcs/src/test/java/org/apache/pinot/plugin/filesystem/GcsPinotFSNullSafetyTest.java
 
b/pinot-plugins/pinot-file-system/pinot-gcs/src/test/java/org/apache/pinot/plugin/filesystem/GcsPinotFSNullSafetyTest.java
index a83f98fe2cf..4a70c846c90 100644
--- 
a/pinot-plugins/pinot-file-system/pinot-gcs/src/test/java/org/apache/pinot/plugin/filesystem/GcsPinotFSNullSafetyTest.java
+++ 
b/pinot-plugins/pinot-file-system/pinot-gcs/src/test/java/org/apache/pinot/plugin/filesystem/GcsPinotFSNullSafetyTest.java
@@ -22,11 +22,14 @@ import com.google.api.gax.paging.Page;
 import com.google.cloud.storage.Blob;
 import com.google.cloud.storage.BlobId;
 import com.google.cloud.storage.Storage;
+import java.io.File;
 import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.lang.reflect.Field;
 import java.net.URI;
+import java.nio.file.Files;
 import java.util.List;
+import org.apache.commons.io.FileUtils;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
@@ -42,6 +45,7 @@ import static org.testng.Assert.fail;
 /// Unit tests verifying null-safety fixes in GcsPinotFS:
 /// - open() throws FileNotFoundException (not NPE) when the blob does not 
exist
 /// - copy() throws FileNotFoundException (not NPE) when the source blob does 
not exist
+/// - copyToLocalFile() throws FileNotFoundException when the source blob does 
not exist
 public class GcsPinotFSNullSafetyTest {
 
   private Storage _mockStorage;
@@ -133,4 +137,22 @@ public class GcsPinotFSNullSafetyTest {
     // Must throw FileNotFoundException, not NullPointerException
     assertThrows(FileNotFoundException.class, () -> 
_gcsPinotFS.copyDir(srcUri, dstUri));
   }
+
+  @Test
+  public void 
testCopyToLocalFileThrowsFileNotFoundExceptionWhenBlobDoesNotExist()
+      throws Exception {
+    URI srcUri = URI.create("gs://test-bucket/missing-file");
+    File tempDir = 
Files.createTempDirectory("GcsPinotFSNullSafetyTest").toFile();
+    File dstFile = new File(tempDir, "missing-file");
+    when(_mockStorage.get(any(BlobId.class))).thenReturn(null);
+
+    try {
+      _gcsPinotFS.copyToLocalFile(srcUri, dstFile);
+      fail("Expected FileNotFoundException");
+    } catch (FileNotFoundException ex) {
+      assertEquals(ex.getMessage(), "File '" + srcUri + "' does not exist");
+    } finally {
+      FileUtils.deleteQuietly(tempDir);
+    }
+  }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to