Ver Fonte

HADOOP-15753. ABFS: support path "abfs://mycluster/file/path"
Contributed by Da Zhou.

Thomas Marquardt há 6 anos atrás
pai
commit
26211019c8

+ 23 - 0
hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/AzureBlobFileSystem.java

@@ -366,6 +366,29 @@ public class AzureBlobFileSystem extends FileSystem {
     }
   }
 
+  /**
+   * Qualify a path to one which uses this FileSystem and, if relative,
+   * made absolute.
+   * @param path to qualify.
+   * @return this path if it contains a scheme and authority and is absolute, or
+   * a new path that includes a path and authority and is fully qualified
+   * @see Path#makeQualified(URI, Path)
+   * @throws IllegalArgumentException if the path has a schema/URI different
+   * from this FileSystem.
+   */
+  @Override
+  public Path makeQualified(Path path) {
+    // To support format: abfs://{dfs.nameservices}/file/path,
+    // path need to be first converted to URI, then get the raw path string,
+    // during which {dfs.nameservices} will be omitted.
+    if (path != null ) {
+      String uriPath = path.toUri().getPath();
+      path = uriPath.isEmpty() ? path : new Path(uriPath);
+    }
+    return super.makeQualified(path);
+  }
+
+
   @Override
   public Path getWorkingDirectory() {
     return this.workingDir;

+ 24 - 0
hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/ITestAzureBlobFileSystemFileStatus.java

@@ -98,4 +98,28 @@ public class ITestAzureBlobFileSystemFileStatus extends
     validateStatus(fs, TEST_FOLDER, true);
   }
 
+  @Test
+  public void testAbfsPathWithHost() throws IOException {
+    AzureBlobFileSystem fs = this.getFileSystem();
+    Path pathWithHost1 = new Path("abfs://mycluster/abfs/file1.txt");
+    Path pathwithouthost1 = new Path("/abfs/file1.txt");
+
+    Path pathWithHost2 = new Path("abfs://mycluster/abfs/file2.txt");
+    Path pathwithouthost2 = new Path("/abfs/file2.txt");
+
+    // verify compatibility of this path format
+    fs.create(pathWithHost1);
+    assertTrue(fs.exists(pathwithouthost1));
+
+    fs.create(pathwithouthost2);
+    assertTrue(fs.exists(pathWithHost2));
+
+    // verify get
+    FileStatus fileStatus1 = fs.getFileStatus(pathWithHost1);
+    assertEquals(pathwithouthost1.getName(), fileStatus1.getPath().getName());
+
+    FileStatus fileStatus2 = fs.getFileStatus(pathwithouthost2);
+    assertEquals(pathWithHost2.getName(), fileStatus2.getPath().getName());
+  }
+
 }