diff --git a/hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/AzureBlobFileSystem.java b/hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/AzureBlobFileSystem.java index 7cbf4d7d3f..2e8de78288 100644 --- a/hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/AzureBlobFileSystem.java +++ b/hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/AzureBlobFileSystem.java @@ -366,6 +366,29 @@ public FileStatus getFileStatus(final Path f) throws IOException { } } + /** + * 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; diff --git a/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/ITestAzureBlobFileSystemFileStatus.java b/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/ITestAzureBlobFileSystemFileStatus.java index b08b9202dd..02f938f19f 100644 --- a/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/ITestAzureBlobFileSystemFileStatus.java +++ b/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/ITestAzureBlobFileSystemFileStatus.java @@ -98,4 +98,28 @@ public void testFolderStatusPermissionsAndOwnerAndGroup() throws Exception { 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()); + } + }