You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@druid.apache.org by ni...@apache.org on 2023/04/19 05:56:25 UTC

[druid] branch master updated: fix npe with gs uri having underscores (#14107)

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

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


The following commit(s) were added to refs/heads/master by this push:
     new e8674e2a60 fix npe with gs uri having underscores (#14107)
e8674e2a60 is described below

commit e8674e2a60aed3b223809bbcb124d132634c19f8
Author: Parag Jain <pj...@apache.org>
AuthorDate: Wed Apr 19 11:26:18 2023 +0530

    fix npe with gs uri having underscores (#14107)
    
    * fix npe with gs uri having underscores
    
    * compile fix
---
 .../storage/google/GoogleDataSegmentPuller.java    |  4 +--
 .../google/GoogleDataSegmentPullerTest.java        | 37 ++++++++++++++++++++++
 2 files changed, 39 insertions(+), 2 deletions(-)

diff --git a/extensions-core/google-extensions/src/main/java/org/apache/druid/storage/google/GoogleDataSegmentPuller.java b/extensions-core/google-extensions/src/main/java/org/apache/druid/storage/google/GoogleDataSegmentPuller.java
index 40bd926b4b..fc3f7d371f 100644
--- a/extensions-core/google-extensions/src/main/java/org/apache/druid/storage/google/GoogleDataSegmentPuller.java
+++ b/extensions-core/google-extensions/src/main/java/org/apache/druid/storage/google/GoogleDataSegmentPuller.java
@@ -83,14 +83,14 @@ public class GoogleDataSegmentPuller implements URIDataPuller
   public InputStream getInputStream(URI uri) throws IOException
   {
     String path = StringUtils.maybeRemoveLeadingSlash(uri.getPath());
-    return storage.get(uri.getHost(), path);
+    return storage.get(uri.getHost() != null ? uri.getHost() : uri.getAuthority(), path);
   }
 
   @Override
   public String getVersion(URI uri) throws IOException
   {
     String path = StringUtils.maybeRemoveLeadingSlash(uri.getPath());
-    return storage.version(uri.getHost(), path);
+    return storage.version(uri.getHost() != null ? uri.getHost() : uri.getAuthority(), path);
   }
 
   @Override
diff --git a/extensions-core/google-extensions/src/test/java/org/apache/druid/storage/google/GoogleDataSegmentPullerTest.java b/extensions-core/google-extensions/src/test/java/org/apache/druid/storage/google/GoogleDataSegmentPullerTest.java
index 1c39be2a81..deb2383fd6 100644
--- a/extensions-core/google-extensions/src/test/java/org/apache/druid/storage/google/GoogleDataSegmentPullerTest.java
+++ b/extensions-core/google-extensions/src/test/java/org/apache/druid/storage/google/GoogleDataSegmentPullerTest.java
@@ -23,6 +23,7 @@ import com.google.api.client.googleapis.json.GoogleJsonResponseException;
 import com.google.api.client.googleapis.testing.json.GoogleJsonResponseExceptionFactoryTesting;
 import com.google.api.client.json.jackson2.JacksonFactory;
 import org.apache.druid.java.util.common.FileUtils;
+import org.apache.druid.java.util.common.StringUtils;
 import org.apache.druid.segment.loading.SegmentLoadingException;
 import org.easymock.EasyMock;
 import org.easymock.EasyMockSupport;
@@ -31,6 +32,8 @@ import org.junit.Test;
 
 import java.io.File;
 import java.io.IOException;
+import java.io.InputStream;
+import java.net.URI;
 
 public class GoogleDataSegmentPullerTest extends EasyMockSupport
 {
@@ -64,4 +67,38 @@ public class GoogleDataSegmentPullerTest extends EasyMockSupport
       FileUtils.deleteDirectory(outDir);
     }
   }
+
+  @Test
+  public void testGetVersionBucketNameWithUnderscores() throws IOException
+  {
+    String bucket = "bucket_test";
+    String prefix = "prefix/";
+    String version = "0";
+
+    GoogleStorage storage = createMock(GoogleStorage.class);
+    EasyMock.expect(storage.version(EasyMock.eq(bucket), EasyMock.eq(prefix))).andReturn("0");
+    EasyMock.replay(storage);
+
+    GoogleDataSegmentPuller puller = new GoogleDataSegmentPuller(storage);
+
+    String actual = puller.getVersion(URI.create(StringUtils.format("gs://%s/%s", bucket, prefix)));
+    Assert.assertEquals(version, actual);
+    EasyMock.verify(storage);
+  }
+
+  @Test
+  public void testGetInputStreamBucketNameWithUnderscores() throws IOException
+  {
+    String bucket = "bucket_test";
+    String prefix = "prefix/";
+
+    GoogleStorage storage = createMock(GoogleStorage.class);
+    EasyMock.expect(storage.get(EasyMock.eq(bucket), EasyMock.eq(prefix))).andReturn(EasyMock.createMock(InputStream.class));
+    EasyMock.replay(storage);
+
+    GoogleDataSegmentPuller puller = new GoogleDataSegmentPuller(storage);
+
+    puller.getInputStream(URI.create(StringUtils.format("gs://%s/%s", bucket, prefix)));
+    EasyMock.verify(storage);
+  }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org