diff --git a/hudi-common/src/main/java/org/apache/hudi/common/fs/HoodieWrapperFileSystem.java b/hudi-common/src/main/java/org/apache/hudi/common/fs/HoodieWrapperFileSystem.java index bceea8e3671c..2979696be715 100644 --- a/hudi-common/src/main/java/org/apache/hudi/common/fs/HoodieWrapperFileSystem.java +++ b/hudi-common/src/main/java/org/apache/hudi/common/fs/HoodieWrapperFileSystem.java @@ -145,8 +145,11 @@ public static Path convertPathWithScheme(Path oldPath, String newScheme) { URI oldURI = oldPath.toUri(); URI newURI; try { - newURI = new URI(newScheme, oldURI.getUserInfo(), oldURI.getHost(), oldURI.getPort(), oldURI.getPath(), - oldURI.getQuery(), oldURI.getFragment()); + newURI = new URI(newScheme, + oldURI.getAuthority(), + oldURI.getPath(), + oldURI.getQuery(), + oldURI.getFragment()); return new CachingPath(newURI); } catch (URISyntaxException e) { // TODO - Better Exception handling diff --git a/hudi-common/src/test/java/org/apache/hudi/common/fs/TestStorageSchemes.java b/hudi-common/src/test/java/org/apache/hudi/common/fs/TestStorageSchemes.java index 85f3ce65ec27..9b173254ac1c 100644 --- a/hudi-common/src/test/java/org/apache/hudi/common/fs/TestStorageSchemes.java +++ b/hudi-common/src/test/java/org/apache/hudi/common/fs/TestStorageSchemes.java @@ -18,8 +18,10 @@ package org.apache.hudi.common.fs; +import org.apache.hadoop.fs.Path; import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -54,4 +56,19 @@ public void testStorageSchemes() { StorageSchemes.isAppendSupported("s2"); }, "Should throw exception for unsupported schemes"); } + + @Test + public void testConversionToNewSchema() { + Path s3TablePath1 = new Path("s3://test.1234/table1"); + assertEquals(s3TablePath1, HoodieWrapperFileSystem.convertPathWithScheme(s3TablePath1, "s3")); + + Path s3TablePath2 = new Path("s3://1234.test/table1"); + assertEquals(s3TablePath2, HoodieWrapperFileSystem.convertPathWithScheme(s3TablePath2, "s3")); + + Path s3TablePath3 = new Path("s3://test1234/table1"); + assertEquals(s3TablePath3, HoodieWrapperFileSystem.convertPathWithScheme(s3TablePath3, "s3")); + + Path hdfsTablePath = new Path("hdfs://sandbox.foo.com:8020/test.1234/table1"); + System.out.println(HoodieWrapperFileSystem.convertPathWithScheme(hdfsTablePath, "hdfs")); + } }