boyuanzz commented on a change in pull request #12335:
URL: https://github.com/apache/beam/pull/12335#discussion_r459119563



##########
File path: sdks/java/io/azure/build.gradle
##########
@@ -17,7 +17,9 @@
  */
 
 plugins { id 'org.apache.beam.module' }
-applyJavaNature(automaticModuleName: 'org.apache.beam.sdk.io.azure')
+applyJavaNature(automaticModuleName: 'org.apache.beam.sdk.io.azure', 
enableChecker: false)

Review comment:
       Any reason that we want to disable `enableChecker`?

##########
File path: 
sdks/java/io/azure/src/main/java/org/apache/beam/sdk/io/azure/blobstore/AzfsResourceId.java
##########
@@ -0,0 +1,219 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.beam.sdk.io.azure.blobstore;
+
+import static 
org.apache.beam.vendor.guava.v26_0_jre.com.google.common.base.Preconditions.checkArgument;
+import static 
org.apache.beam.vendor.guava.v26_0_jre.com.google.common.base.Preconditions.checkState;
+
+import java.util.Objects;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import javax.annotation.Nullable;
+import org.apache.beam.sdk.io.fs.ResolveOptions;
+import org.apache.beam.sdk.io.fs.ResourceId;
+import org.apache.beam.vendor.guava.v26_0_jre.com.google.common.base.Strings;
+
+class AzfsResourceId implements ResourceId {
+
+  static final String SCHEME = "azfs";
+
+  private static final Pattern AZFS_URI =
+      
Pattern.compile("(?<SCHEME>[^:]+)://(?<ACCOUNT>[^/]+)/(?<CONTAINER>[^/]+)(?:/(?<BLOB>.*))?");
+
+  /** Matches a glob containing a wildcard, capturing the portion before the 
first wildcard. */
+  private static final Pattern GLOB_PREFIX = 
Pattern.compile("(?<PREFIX>[^\\[*?]*)[\\[*?].*");
+
+  private final String account;
+  private final String container;
+  private final String blob;
+
+  private AzfsResourceId(String account, String container, @Nullable String 
blob) {
+    // We are assuming that every resource id is either a container or a blob 
in a container, not
+    // just an account.
+    // This is because we will not enable users to create Azure containers 
through beam at this
+    // time.
+    checkArgument(!Strings.isNullOrEmpty(container), "container");
+    checkArgument(!container.contains("/"), "container must not contain '/': 
[%s]", container);
+    this.account = account;
+    this.container = container;
+    this.blob = blob;
+  }
+
+  static AzfsResourceId fromComponents(String account, String container, 
String blob) {
+    return new AzfsResourceId(account, container, blob);
+  }
+
+  static AzfsResourceId fromComponents(String account, String container) {
+    return new AzfsResourceId(account, container, null);
+  }
+
+  static AzfsResourceId fromUri(String uri) {
+    Matcher m = AZFS_URI.matcher(uri);
+    checkArgument(m.matches(), "Invalid AZFS URI: [%s]", uri);
+    checkArgument(m.group("SCHEME").equalsIgnoreCase(SCHEME), "Invalid AZFS 
URI scheme: [%s]", uri);
+    String account = m.group("ACCOUNT");
+    String container = m.group("CONTAINER");
+    String blob = m.group("BLOB");
+    if (blob != null && blob.isEmpty()) {
+      blob = null;
+    }
+    return fromComponents(account, container, blob);
+  }
+
+  public String getAccount() {
+    return account;
+  }
+
+  public String getContainer() {
+    return container;
+  }
+
+  public String getBlob() {
+    return blob;
+  }
+
+  @Override
+  public String getScheme() {
+    return SCHEME;
+  }
+
+  @Override
+  public boolean isDirectory() {
+    return (blob == null) || (blob.endsWith("/"));

Review comment:
       What if blob is empty?

##########
File path: 
sdks/java/io/azure/src/main/java/org/apache/beam/sdk/io/azure/blobstore/AzfsResourceId.java
##########
@@ -0,0 +1,219 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.beam.sdk.io.azure.blobstore;
+
+import static 
org.apache.beam.vendor.guava.v26_0_jre.com.google.common.base.Preconditions.checkArgument;
+import static 
org.apache.beam.vendor.guava.v26_0_jre.com.google.common.base.Preconditions.checkState;
+
+import java.util.Objects;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import javax.annotation.Nullable;
+import org.apache.beam.sdk.io.fs.ResolveOptions;
+import org.apache.beam.sdk.io.fs.ResourceId;
+import org.apache.beam.vendor.guava.v26_0_jre.com.google.common.base.Strings;
+
+class AzfsResourceId implements ResourceId {
+
+  static final String SCHEME = "azfs";
+
+  private static final Pattern AZFS_URI =
+      
Pattern.compile("(?<SCHEME>[^:]+)://(?<ACCOUNT>[^/]+)/(?<CONTAINER>[^/]+)(?:/(?<BLOB>.*))?");
+
+  /** Matches a glob containing a wildcard, capturing the portion before the 
first wildcard. */
+  private static final Pattern GLOB_PREFIX = 
Pattern.compile("(?<PREFIX>[^\\[*?]*)[\\[*?].*");
+
+  private final String account;
+  private final String container;
+  private final String blob;
+
+  private AzfsResourceId(String account, String container, @Nullable String 
blob) {
+    // We are assuming that every resource id is either a container or a blob 
in a container, not
+    // just an account.
+    // This is because we will not enable users to create Azure containers 
through beam at this
+    // time.
+    checkArgument(!Strings.isNullOrEmpty(container), "container");
+    checkArgument(!container.contains("/"), "container must not contain '/': 
[%s]", container);
+    this.account = account;
+    this.container = container;
+    this.blob = blob;
+  }
+
+  static AzfsResourceId fromComponents(String account, String container, 
String blob) {
+    return new AzfsResourceId(account, container, blob);
+  }
+
+  static AzfsResourceId fromComponents(String account, String container) {
+    return new AzfsResourceId(account, container, null);
+  }
+
+  static AzfsResourceId fromUri(String uri) {
+    Matcher m = AZFS_URI.matcher(uri);
+    checkArgument(m.matches(), "Invalid AZFS URI: [%s]", uri);
+    checkArgument(m.group("SCHEME").equalsIgnoreCase(SCHEME), "Invalid AZFS 
URI scheme: [%s]", uri);
+    String account = m.group("ACCOUNT");
+    String container = m.group("CONTAINER");
+    String blob = m.group("BLOB");
+    if (blob != null && blob.isEmpty()) {
+      blob = null;
+    }
+    return fromComponents(account, container, blob);
+  }
+
+  public String getAccount() {
+    return account;
+  }
+
+  public String getContainer() {
+    return container;
+  }
+
+  public String getBlob() {
+    return blob;
+  }
+
+  @Override
+  public String getScheme() {
+    return SCHEME;
+  }
+
+  @Override
+  public boolean isDirectory() {
+    return (blob == null) || (blob.endsWith("/"));
+  }
+
+  boolean isWildcard() {
+    return GLOB_PREFIX.matcher(blob).matches();

Review comment:
       It seems like this function is not called anywhere. Also what if `blob` 
is `null`?

##########
File path: 
sdks/java/io/azure/src/main/java/org/apache/beam/sdk/io/azure/blobstore/AzureBlobStoreFileSystemRegistrar.java
##########
@@ -15,3 +15,20 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+package org.apache.beam.sdk.io.azure.blobstore;
+
+import static 
org.apache.beam.vendor.guava.v26_0_jre.com.google.common.base.Preconditions.checkNotNull;
+
+import javax.annotation.Nonnull;
+import org.apache.beam.sdk.io.FileSystem;
+import org.apache.beam.sdk.io.FileSystemRegistrar;
+import org.apache.beam.sdk.options.PipelineOptions;
+import 
org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.ImmutableList;
+
+public class AzureBlobStoreFileSystemRegistrar implements FileSystemRegistrar {
+  @Override
+  public Iterable<FileSystem> fromOptions(@Nonnull PipelineOptions options) {
+    checkNotNull(options, "Expect the runner have called 
FileSystems.setDefaultPipelineOptions().");
+    return ImmutableList.of();

Review comment:
       Add `// TODO`? Or you may want to have this file together with the file 
system changes later.

##########
File path: 
sdks/java/io/azure/src/main/java/org/apache/beam/sdk/io/azure/blobstore/AzfsResourceId.java
##########
@@ -0,0 +1,219 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.beam.sdk.io.azure.blobstore;
+
+import static 
org.apache.beam.vendor.guava.v26_0_jre.com.google.common.base.Preconditions.checkArgument;
+import static 
org.apache.beam.vendor.guava.v26_0_jre.com.google.common.base.Preconditions.checkState;
+
+import java.util.Objects;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import javax.annotation.Nullable;
+import org.apache.beam.sdk.io.fs.ResolveOptions;
+import org.apache.beam.sdk.io.fs.ResourceId;
+import org.apache.beam.vendor.guava.v26_0_jre.com.google.common.base.Strings;
+
+class AzfsResourceId implements ResourceId {
+
+  static final String SCHEME = "azfs";
+
+  private static final Pattern AZFS_URI =
+      
Pattern.compile("(?<SCHEME>[^:]+)://(?<ACCOUNT>[^/]+)/(?<CONTAINER>[^/]+)(?:/(?<BLOB>.*))?");
+
+  /** Matches a glob containing a wildcard, capturing the portion before the 
first wildcard. */
+  private static final Pattern GLOB_PREFIX = 
Pattern.compile("(?<PREFIX>[^\\[*?]*)[\\[*?].*");
+
+  private final String account;
+  private final String container;
+  private final String blob;
+
+  private AzfsResourceId(String account, String container, @Nullable String 
blob) {
+    // We are assuming that every resource id is either a container or a blob 
in a container, not
+    // just an account.
+    // This is because we will not enable users to create Azure containers 
through beam at this
+    // time.
+    checkArgument(!Strings.isNullOrEmpty(container), "container");
+    checkArgument(!container.contains("/"), "container must not contain '/': 
[%s]", container);
+    this.account = account;
+    this.container = container;
+    this.blob = blob;
+  }
+
+  static AzfsResourceId fromComponents(String account, String container, 
String blob) {
+    return new AzfsResourceId(account, container, blob);
+  }
+
+  static AzfsResourceId fromComponents(String account, String container) {
+    return new AzfsResourceId(account, container, null);
+  }
+
+  static AzfsResourceId fromUri(String uri) {
+    Matcher m = AZFS_URI.matcher(uri);
+    checkArgument(m.matches(), "Invalid AZFS URI: [%s]", uri);
+    checkArgument(m.group("SCHEME").equalsIgnoreCase(SCHEME), "Invalid AZFS 
URI scheme: [%s]", uri);
+    String account = m.group("ACCOUNT");
+    String container = m.group("CONTAINER");
+    String blob = m.group("BLOB");
+    if (blob != null && blob.isEmpty()) {
+      blob = null;
+    }
+    return fromComponents(account, container, blob);
+  }
+
+  public String getAccount() {
+    return account;
+  }
+
+  public String getContainer() {
+    return container;
+  }
+
+  public String getBlob() {
+    return blob;
+  }
+
+  @Override
+  public String getScheme() {
+    return SCHEME;
+  }
+
+  @Override
+  public boolean isDirectory() {
+    return (blob == null) || (blob.endsWith("/"));
+  }
+
+  boolean isWildcard() {
+    return GLOB_PREFIX.matcher(blob).matches();
+  }
+
+  String getBlobNonWildcardPrefix() {

Review comment:
       It seems like this function is not used?

##########
File path: 
sdks/java/io/azure/src/test/java/org/apache/beam/sdk/io/azure/blobstore/AzfsResourceIdTest.java
##########
@@ -0,0 +1,308 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.beam.sdk.io.azure.blobstore;
+
+import static 
org.apache.beam.sdk.io.fs.ResolveOptions.StandardResolveOptions.RESOLVE_DIRECTORY;
+import static 
org.apache.beam.sdk.io.fs.ResolveOptions.StandardResolveOptions.RESOLVE_FILE;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Arrays;
+import java.util.List;
+import org.apache.beam.sdk.io.fs.ResolveOptions;
+import org.apache.beam.sdk.io.fs.ResourceId;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+@RunWith(JUnit4.class)
+public class AzfsResourceIdTest {
+
+  @Rule public ExpectedException thrown = ExpectedException.none();
+
+  static final class TestCase {
+
+    final String baseUri;
+    final String relativePath;
+    final ResolveOptions.StandardResolveOptions resolveOptions;
+    final String expectedResult;
+
+    TestCase(
+        String baseUri,
+        String relativePath,
+        ResolveOptions.StandardResolveOptions resolveOptions,
+        String expectedResult) {
+      this.baseUri = baseUri;
+      this.relativePath = relativePath;
+      this.resolveOptions = resolveOptions;
+      this.expectedResult = expectedResult;
+    }
+  }
+
+  // Each test case is an expected URL, then the components used to build it.
+  // Empty components result in a double slash.
+  private static final List<TestCase> PATH_TEST_CASES =
+      Arrays.asList(
+          new TestCase(
+              "azfs://account/container/", "", RESOLVE_DIRECTORY, 
"azfs://account/container/"),
+          new TestCase(
+              "azfs://account/container", "", RESOLVE_DIRECTORY, 
"azfs://account/container/"),
+          new TestCase(
+              "azfs://account/container",
+              "path/to/dir",
+              RESOLVE_DIRECTORY,
+              "azfs://account/container/path/to/dir/"),
+          new TestCase(
+              "azfs://account/container",
+              "path/to/object",
+              RESOLVE_FILE,
+              "azfs://account/container/path/to/object"),
+          new TestCase(
+              "azfs://account/container/path/to/dir/",
+              "..",
+              RESOLVE_DIRECTORY,
+              "azfs://account/container/path/to/"));
+
+  @Test
+  public void testResolve() {
+    for (TestCase testCase : PATH_TEST_CASES) {
+      ResourceId resourceId = AzfsResourceId.fromUri(testCase.baseUri);
+      ResourceId resolved = resourceId.resolve(testCase.relativePath, 
testCase.resolveOptions);
+      assertEquals(testCase.expectedResult, resolved.toString());
+    }
+
+    // Tests for common Azure paths.
+    assertEquals(
+        AzfsResourceId.fromUri("azfs://account/container/tmp/aa"),
+        AzfsResourceId.fromUri("azfs://account/container/tmp/").resolve("aa", 
RESOLVE_FILE));
+    assertEquals(
+        AzfsResourceId.fromUri("azfs://account/container/tmp/aa/bb/cc/"),
+        AzfsResourceId.fromUri("azfs://account/container/tmp/")
+            .resolve("aa", RESOLVE_DIRECTORY)
+            .resolve("bb", RESOLVE_DIRECTORY)
+            .resolve("cc", RESOLVE_DIRECTORY));
+
+    // Tests absolute path.
+    assertEquals(
+        AzfsResourceId.fromUri("azfs://account/container/tmp/aa"),
+        AzfsResourceId.fromUri("azfs://account/container/tmp/bb/")
+            .resolve("azfs://account/container/tmp/aa", RESOLVE_FILE));
+
+    // Tests container with no ending '/'.
+    assertEquals(
+        AzfsResourceId.fromUri("azfs://account/my-container/tmp"),
+        AzfsResourceId.fromUri("azfs://account/my-container").resolve("tmp", 
RESOLVE_FILE));
+
+    // Tests path with unicode
+    assertEquals(
+        AzfsResourceId.fromUri("azfs://account/container/输出 目录/输出 文件01.txt"),
+        AzfsResourceId.fromUri("azfs://account/container/输出 目录/")
+            .resolve("输出 文件01.txt", RESOLVE_FILE));
+  }
+
+  @Test
+  public void testResolveInvalidInputs() {
+    thrown.expect(IllegalArgumentException.class);
+    thrown.expectMessage("Cannot resolve a file with a directory path: 
[tmp/]");
+    AzfsResourceId.fromUri("azfs://account/my_container/").resolve("tmp/", 
RESOLVE_FILE);
+  }
+
+  @Test
+  public void testResolveInvalidNotDirectory() {
+    ResourceId tmpDir =
+        AzfsResourceId.fromUri("azfs://account/my_container/").resolve("tmp 
dir", RESOLVE_FILE);
+
+    thrown.expect(IllegalStateException.class);
+    thrown.expectMessage(
+        "Expected this resource to be a directory, but was 
[azfs://account/my_container/tmp dir]");
+    tmpDir.resolve("aa", RESOLVE_FILE);
+  }
+
+  @Test
+  public void testS3ResolveWithFileBase() {
+    ResourceId resourceId = 
AzfsResourceId.fromUri("azfs://account/container/path/to/file");
+    thrown.expect(IllegalStateException.class);
+    resourceId.resolve("child-path", RESOLVE_DIRECTORY); // resource is not a 
directory
+  }
+
+  @Test
+  public void testResolveParentToFile() {
+    ResourceId resourceId = 
AzfsResourceId.fromUri("azfs://account/container/path/to/dir/");
+    thrown.expect(IllegalArgumentException.class);
+    resourceId.resolve("..", RESOLVE_FILE); // '..' only resolves as dir, not 
as file
+  }
+
+  @Test
+  public void testEquals() {
+    AzfsResourceId a = AzfsResourceId.fromComponents("account", "container", 
"a/b/c");
+    AzfsResourceId b = AzfsResourceId.fromComponents("account", "container", 
"a/b/c");
+    assertEquals(a, a);

Review comment:
       Why do we want to compare `a` and `a`?

##########
File path: 
sdks/java/io/azure/src/test/java/org/apache/beam/sdk/io/azure/blobstore/AzfsResourceIdTest.java
##########
@@ -0,0 +1,308 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.beam.sdk.io.azure.blobstore;
+
+import static 
org.apache.beam.sdk.io.fs.ResolveOptions.StandardResolveOptions.RESOLVE_DIRECTORY;
+import static 
org.apache.beam.sdk.io.fs.ResolveOptions.StandardResolveOptions.RESOLVE_FILE;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Arrays;
+import java.util.List;
+import org.apache.beam.sdk.io.fs.ResolveOptions;
+import org.apache.beam.sdk.io.fs.ResourceId;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+@RunWith(JUnit4.class)
+public class AzfsResourceIdTest {
+
+  @Rule public ExpectedException thrown = ExpectedException.none();
+
+  static final class TestCase {
+
+    final String baseUri;
+    final String relativePath;
+    final ResolveOptions.StandardResolveOptions resolveOptions;
+    final String expectedResult;
+
+    TestCase(
+        String baseUri,
+        String relativePath,
+        ResolveOptions.StandardResolveOptions resolveOptions,
+        String expectedResult) {
+      this.baseUri = baseUri;
+      this.relativePath = relativePath;
+      this.resolveOptions = resolveOptions;
+      this.expectedResult = expectedResult;
+    }
+  }
+
+  // Each test case is an expected URL, then the components used to build it.
+  // Empty components result in a double slash.
+  private static final List<TestCase> PATH_TEST_CASES =
+      Arrays.asList(
+          new TestCase(
+              "azfs://account/container/", "", RESOLVE_DIRECTORY, 
"azfs://account/container/"),
+          new TestCase(
+              "azfs://account/container", "", RESOLVE_DIRECTORY, 
"azfs://account/container/"),
+          new TestCase(
+              "azfs://account/container",
+              "path/to/dir",
+              RESOLVE_DIRECTORY,
+              "azfs://account/container/path/to/dir/"),
+          new TestCase(
+              "azfs://account/container",
+              "path/to/object",
+              RESOLVE_FILE,
+              "azfs://account/container/path/to/object"),
+          new TestCase(
+              "azfs://account/container/path/to/dir/",
+              "..",
+              RESOLVE_DIRECTORY,
+              "azfs://account/container/path/to/"));
+
+  @Test
+  public void testResolve() {
+    for (TestCase testCase : PATH_TEST_CASES) {

Review comment:
       Minor: You could do this by using `Parameterized ` but it's up to you.

##########
File path: 
sdks/java/io/azure/src/main/java/org/apache/beam/sdk/io/azure/blobstore/AzfsResourceId.java
##########
@@ -0,0 +1,219 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.beam.sdk.io.azure.blobstore;
+
+import static 
org.apache.beam.vendor.guava.v26_0_jre.com.google.common.base.Preconditions.checkArgument;
+import static 
org.apache.beam.vendor.guava.v26_0_jre.com.google.common.base.Preconditions.checkState;
+
+import java.util.Objects;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import javax.annotation.Nullable;
+import org.apache.beam.sdk.io.fs.ResolveOptions;
+import org.apache.beam.sdk.io.fs.ResourceId;
+import org.apache.beam.vendor.guava.v26_0_jre.com.google.common.base.Strings;
+
+class AzfsResourceId implements ResourceId {
+
+  static final String SCHEME = "azfs";
+
+  private static final Pattern AZFS_URI =
+      
Pattern.compile("(?<SCHEME>[^:]+)://(?<ACCOUNT>[^/]+)/(?<CONTAINER>[^/]+)(?:/(?<BLOB>.*))?");
+
+  /** Matches a glob containing a wildcard, capturing the portion before the 
first wildcard. */
+  private static final Pattern GLOB_PREFIX = 
Pattern.compile("(?<PREFIX>[^\\[*?]*)[\\[*?].*");
+
+  private final String account;
+  private final String container;
+  private final String blob;
+
+  private AzfsResourceId(String account, String container, @Nullable String 
blob) {
+    // We are assuming that every resource id is either a container or a blob 
in a container, not
+    // just an account.
+    // This is because we will not enable users to create Azure containers 
through beam at this
+    // time.
+    checkArgument(!Strings.isNullOrEmpty(container), "container");
+    checkArgument(!container.contains("/"), "container must not contain '/': 
[%s]", container);
+    this.account = account;
+    this.container = container;
+    this.blob = blob;
+  }
+
+  static AzfsResourceId fromComponents(String account, String container, 
String blob) {
+    return new AzfsResourceId(account, container, blob);
+  }
+
+  static AzfsResourceId fromComponents(String account, String container) {
+    return new AzfsResourceId(account, container, null);
+  }
+
+  static AzfsResourceId fromUri(String uri) {
+    Matcher m = AZFS_URI.matcher(uri);
+    checkArgument(m.matches(), "Invalid AZFS URI: [%s]", uri);
+    checkArgument(m.group("SCHEME").equalsIgnoreCase(SCHEME), "Invalid AZFS 
URI scheme: [%s]", uri);
+    String account = m.group("ACCOUNT");
+    String container = m.group("CONTAINER");
+    String blob = m.group("BLOB");
+    if (blob != null && blob.isEmpty()) {
+      blob = null;
+    }
+    return fromComponents(account, container, blob);
+  }
+
+  public String getAccount() {
+    return account;
+  }
+
+  public String getContainer() {
+    return container;
+  }
+
+  public String getBlob() {
+    return blob;
+  }
+
+  @Override
+  public String getScheme() {
+    return SCHEME;
+  }
+
+  @Override
+  public boolean isDirectory() {
+    return (blob == null) || (blob.endsWith("/"));
+  }
+
+  boolean isWildcard() {
+    return GLOB_PREFIX.matcher(blob).matches();
+  }
+
+  String getBlobNonWildcardPrefix() {
+    Matcher m = GLOB_PREFIX.matcher(blob);
+    checkArgument(m.matches(), String.format("Glob expression: [%s] is not 
expandable.", blob));
+    return m.group("PREFIX");
+  }
+
+  @Override
+  public ResourceId getCurrentDirectory() {
+    if (isDirectory()) {
+      return this;
+    }
+    if (blob.lastIndexOf('/') == -1) {
+      return fromComponents(account, container);
+    }
+    return fromComponents(account, container, blob.substring(0, 
blob.lastIndexOf('/') + 1));
+  }
+
+  @Nullable
+  @Override
+  public String getFilename() {
+    if (blob == null) {
+      return null;
+    }
+    if (!isDirectory()) {
+      return blob.substring(blob.lastIndexOf('/') + 1);
+    }
+    String blobWithoutTrailingSlash = blob.substring(0, blob.length() - 1);
+    return 
blobWithoutTrailingSlash.substring(blobWithoutTrailingSlash.lastIndexOf('/') + 
1);
+  }
+
+  // TODO: ensure that this function lines up with what the filesystem match 
method expects
+  @Override
+  public String toString() {
+    if (blob != null) {
+      return String.format("%s://%s/%s/%s", SCHEME, account, container, blob);
+    }
+    return String.format("%s://%s/%s/", SCHEME, account, container);
+  }
+
+  @Override
+  public boolean equals(Object obj) {
+    if (!(obj instanceof AzfsResourceId)) {
+      return false;
+    }
+    String otherBlob = ((AzfsResourceId) obj).blob;
+    boolean equalBlob = blob != null && otherBlob != null && 
blob.equals(otherBlob);
+    boolean noBlobs = blob == null && otherBlob == null;
+    return account.equals(((AzfsResourceId) obj).account)
+        && container.equals(((AzfsResourceId) obj).container)
+        && (equalBlob || noBlobs);
+  }
+
+  @Override
+  public int hashCode() {
+    return Objects.hash(account, container, blob);
+  }
+
+  @Override
+  public ResourceId resolve(String other, ResolveOptions resolveOptions) {
+    checkState(isDirectory(), "Expected this resource to be a directory, but 
was [%s]", toString());
+    // TODO: check if resolve options are an illegal name in any way, see:
+    // 
https://docs.microsoft.com/en-us/rest/api/storageservices/Naming-and-Referencing-Containers--Blobs--and-Metadata
+
+    if (resolveOptions == 
ResolveOptions.StandardResolveOptions.RESOLVE_DIRECTORY) {
+      if ("..".equals(other)) {
+        if ("/".equals(blob)) {
+          return this;
+        }
+        int parentStopsAt = blob.substring(0, blob.length() - 
1).lastIndexOf('/');
+        return fromComponents(account, container, blob.substring(0, 
parentStopsAt + 1));
+      }
+
+      if ("".equals(other)) {
+        return this;
+      }
+
+      if (!other.endsWith("/")) {
+        other += "/";
+      }
+      if (AZFS_URI.matcher(other).matches()) {
+        return fromUri(other);
+      }
+      if (blob == null) {
+        return fromComponents(account, container, other);
+      }
+      return fromComponents(account, container, blob + other);
+    }
+
+    if (resolveOptions == ResolveOptions.StandardResolveOptions.RESOLVE_FILE) {
+      checkArgument(
+          !other.endsWith("/"), "Cannot resolve a file with a directory path: 
[%s]", other);
+      checkArgument(!"..".equals(other), "Cannot resolve parent as file: 
[%s]", other);
+      if (AZFS_URI.matcher(other).matches()) {
+        return fromUri(other);
+      }
+      if (blob == null) {
+        return fromComponents(account, container, other);
+      }
+      return fromComponents(account, container, blob + other);
+    }
+
+    throw new UnsupportedOperationException(
+        String.format("Unexpected StandardResolveOptions [%s]", 
resolveOptions));
+  }
+
+  // url format to interact with Azure
+  public String toAzureUrl() {

Review comment:
       It seems like this function is not used.

##########
File path: 
sdks/java/io/azure/src/main/java/org/apache/beam/sdk/io/azure/blobstore/AzfsResourceId.java
##########
@@ -0,0 +1,219 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.beam.sdk.io.azure.blobstore;
+
+import static 
org.apache.beam.vendor.guava.v26_0_jre.com.google.common.base.Preconditions.checkArgument;
+import static 
org.apache.beam.vendor.guava.v26_0_jre.com.google.common.base.Preconditions.checkState;
+
+import java.util.Objects;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import javax.annotation.Nullable;
+import org.apache.beam.sdk.io.fs.ResolveOptions;
+import org.apache.beam.sdk.io.fs.ResourceId;
+import org.apache.beam.vendor.guava.v26_0_jre.com.google.common.base.Strings;
+
+class AzfsResourceId implements ResourceId {
+
+  static final String SCHEME = "azfs";
+
+  private static final Pattern AZFS_URI =
+      
Pattern.compile("(?<SCHEME>[^:]+)://(?<ACCOUNT>[^/]+)/(?<CONTAINER>[^/]+)(?:/(?<BLOB>.*))?");
+
+  /** Matches a glob containing a wildcard, capturing the portion before the 
first wildcard. */
+  private static final Pattern GLOB_PREFIX = 
Pattern.compile("(?<PREFIX>[^\\[*?]*)[\\[*?].*");
+
+  private final String account;
+  private final String container;
+  private final String blob;
+
+  private AzfsResourceId(String account, String container, @Nullable String 
blob) {
+    // We are assuming that every resource id is either a container or a blob 
in a container, not
+    // just an account.
+    // This is because we will not enable users to create Azure containers 
through beam at this
+    // time.
+    checkArgument(!Strings.isNullOrEmpty(container), "container");
+    checkArgument(!container.contains("/"), "container must not contain '/': 
[%s]", container);
+    this.account = account;
+    this.container = container;
+    this.blob = blob;
+  }
+
+  static AzfsResourceId fromComponents(String account, String container, 
String blob) {
+    return new AzfsResourceId(account, container, blob);
+  }
+
+  static AzfsResourceId fromComponents(String account, String container) {
+    return new AzfsResourceId(account, container, null);
+  }
+
+  static AzfsResourceId fromUri(String uri) {
+    Matcher m = AZFS_URI.matcher(uri);
+    checkArgument(m.matches(), "Invalid AZFS URI: [%s]", uri);
+    checkArgument(m.group("SCHEME").equalsIgnoreCase(SCHEME), "Invalid AZFS 
URI scheme: [%s]", uri);
+    String account = m.group("ACCOUNT");
+    String container = m.group("CONTAINER");
+    String blob = m.group("BLOB");
+    if (blob != null && blob.isEmpty()) {
+      blob = null;
+    }
+    return fromComponents(account, container, blob);
+  }
+
+  public String getAccount() {
+    return account;
+  }
+
+  public String getContainer() {
+    return container;
+  }
+
+  public String getBlob() {
+    return blob;
+  }
+
+  @Override
+  public String getScheme() {
+    return SCHEME;
+  }
+
+  @Override
+  public boolean isDirectory() {
+    return (blob == null) || (blob.endsWith("/"));
+  }
+
+  boolean isWildcard() {
+    return GLOB_PREFIX.matcher(blob).matches();
+  }
+
+  String getBlobNonWildcardPrefix() {
+    Matcher m = GLOB_PREFIX.matcher(blob);
+    checkArgument(m.matches(), String.format("Glob expression: [%s] is not 
expandable.", blob));
+    return m.group("PREFIX");
+  }
+
+  @Override
+  public ResourceId getCurrentDirectory() {
+    if (isDirectory()) {
+      return this;
+    }
+    if (blob.lastIndexOf('/') == -1) {

Review comment:
       What if `blob` is empty?

##########
File path: 
sdks/java/io/azure/src/main/java/org/apache/beam/sdk/io/azure/blobstore/AzfsResourceId.java
##########
@@ -0,0 +1,219 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.beam.sdk.io.azure.blobstore;
+
+import static 
org.apache.beam.vendor.guava.v26_0_jre.com.google.common.base.Preconditions.checkArgument;
+import static 
org.apache.beam.vendor.guava.v26_0_jre.com.google.common.base.Preconditions.checkState;
+
+import java.util.Objects;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import javax.annotation.Nullable;
+import org.apache.beam.sdk.io.fs.ResolveOptions;
+import org.apache.beam.sdk.io.fs.ResourceId;
+import org.apache.beam.vendor.guava.v26_0_jre.com.google.common.base.Strings;
+
+class AzfsResourceId implements ResourceId {
+
+  static final String SCHEME = "azfs";
+
+  private static final Pattern AZFS_URI =
+      
Pattern.compile("(?<SCHEME>[^:]+)://(?<ACCOUNT>[^/]+)/(?<CONTAINER>[^/]+)(?:/(?<BLOB>.*))?");
+
+  /** Matches a glob containing a wildcard, capturing the portion before the 
first wildcard. */
+  private static final Pattern GLOB_PREFIX = 
Pattern.compile("(?<PREFIX>[^\\[*?]*)[\\[*?].*");
+
+  private final String account;
+  private final String container;
+  private final String blob;
+
+  private AzfsResourceId(String account, String container, @Nullable String 
blob) {
+    // We are assuming that every resource id is either a container or a blob 
in a container, not
+    // just an account.
+    // This is because we will not enable users to create Azure containers 
through beam at this
+    // time.
+    checkArgument(!Strings.isNullOrEmpty(container), "container");
+    checkArgument(!container.contains("/"), "container must not contain '/': 
[%s]", container);
+    this.account = account;
+    this.container = container;
+    this.blob = blob;
+  }
+
+  static AzfsResourceId fromComponents(String account, String container, 
String blob) {
+    return new AzfsResourceId(account, container, blob);
+  }
+
+  static AzfsResourceId fromComponents(String account, String container) {
+    return new AzfsResourceId(account, container, null);
+  }
+
+  static AzfsResourceId fromUri(String uri) {
+    Matcher m = AZFS_URI.matcher(uri);
+    checkArgument(m.matches(), "Invalid AZFS URI: [%s]", uri);
+    checkArgument(m.group("SCHEME").equalsIgnoreCase(SCHEME), "Invalid AZFS 
URI scheme: [%s]", uri);
+    String account = m.group("ACCOUNT");
+    String container = m.group("CONTAINER");
+    String blob = m.group("BLOB");
+    if (blob != null && blob.isEmpty()) {
+      blob = null;
+    }
+    return fromComponents(account, container, blob);
+  }
+
+  public String getAccount() {
+    return account;
+  }
+
+  public String getContainer() {
+    return container;
+  }
+
+  public String getBlob() {
+    return blob;
+  }
+
+  @Override
+  public String getScheme() {
+    return SCHEME;
+  }
+
+  @Override
+  public boolean isDirectory() {
+    return (blob == null) || (blob.endsWith("/"));
+  }
+
+  boolean isWildcard() {
+    return GLOB_PREFIX.matcher(blob).matches();
+  }
+
+  String getBlobNonWildcardPrefix() {
+    Matcher m = GLOB_PREFIX.matcher(blob);
+    checkArgument(m.matches(), String.format("Glob expression: [%s] is not 
expandable.", blob));
+    return m.group("PREFIX");
+  }
+
+  @Override
+  public ResourceId getCurrentDirectory() {
+    if (isDirectory()) {
+      return this;
+    }
+    if (blob.lastIndexOf('/') == -1) {
+      return fromComponents(account, container);
+    }
+    return fromComponents(account, container, blob.substring(0, 
blob.lastIndexOf('/') + 1));
+  }
+
+  @Nullable
+  @Override
+  public String getFilename() {
+    if (blob == null) {
+      return null;
+    }
+    if (!isDirectory()) {
+      return blob.substring(blob.lastIndexOf('/') + 1);
+    }
+    String blobWithoutTrailingSlash = blob.substring(0, blob.length() - 1);
+    return 
blobWithoutTrailingSlash.substring(blobWithoutTrailingSlash.lastIndexOf('/') + 
1);
+  }
+
+  // TODO: ensure that this function lines up with what the filesystem match 
method expects
+  @Override
+  public String toString() {
+    if (blob != null) {
+      return String.format("%s://%s/%s/%s", SCHEME, account, container, blob);
+    }
+    return String.format("%s://%s/%s/", SCHEME, account, container);
+  }
+
+  @Override
+  public boolean equals(Object obj) {
+    if (!(obj instanceof AzfsResourceId)) {
+      return false;
+    }
+    String otherBlob = ((AzfsResourceId) obj).blob;
+    boolean equalBlob = blob != null && otherBlob != null && 
blob.equals(otherBlob);

Review comment:
       You could use `Objects.equals()`: 
https://docs.oracle.com/javase/8/docs/api/java/util/Objects.html#equals-java.lang.Object-java.lang.Object-

##########
File path: 
sdks/java/io/azure/src/test/java/org/apache/beam/sdk/io/azure/blobstore/AzfsResourceIdTest.java
##########
@@ -0,0 +1,308 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.beam.sdk.io.azure.blobstore;
+
+import static 
org.apache.beam.sdk.io.fs.ResolveOptions.StandardResolveOptions.RESOLVE_DIRECTORY;
+import static 
org.apache.beam.sdk.io.fs.ResolveOptions.StandardResolveOptions.RESOLVE_FILE;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Arrays;
+import java.util.List;
+import org.apache.beam.sdk.io.fs.ResolveOptions;
+import org.apache.beam.sdk.io.fs.ResourceId;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+@RunWith(JUnit4.class)
+public class AzfsResourceIdTest {
+
+  @Rule public ExpectedException thrown = ExpectedException.none();
+
+  static final class TestCase {
+
+    final String baseUri;
+    final String relativePath;
+    final ResolveOptions.StandardResolveOptions resolveOptions;
+    final String expectedResult;
+
+    TestCase(
+        String baseUri,
+        String relativePath,
+        ResolveOptions.StandardResolveOptions resolveOptions,
+        String expectedResult) {
+      this.baseUri = baseUri;
+      this.relativePath = relativePath;
+      this.resolveOptions = resolveOptions;
+      this.expectedResult = expectedResult;
+    }
+  }
+
+  // Each test case is an expected URL, then the components used to build it.
+  // Empty components result in a double slash.
+  private static final List<TestCase> PATH_TEST_CASES =
+      Arrays.asList(
+          new TestCase(
+              "azfs://account/container/", "", RESOLVE_DIRECTORY, 
"azfs://account/container/"),
+          new TestCase(
+              "azfs://account/container", "", RESOLVE_DIRECTORY, 
"azfs://account/container/"),
+          new TestCase(
+              "azfs://account/container",
+              "path/to/dir",
+              RESOLVE_DIRECTORY,
+              "azfs://account/container/path/to/dir/"),
+          new TestCase(
+              "azfs://account/container",
+              "path/to/object",
+              RESOLVE_FILE,
+              "azfs://account/container/path/to/object"),
+          new TestCase(
+              "azfs://account/container/path/to/dir/",
+              "..",
+              RESOLVE_DIRECTORY,
+              "azfs://account/container/path/to/"));
+
+  @Test
+  public void testResolve() {
+    for (TestCase testCase : PATH_TEST_CASES) {
+      ResourceId resourceId = AzfsResourceId.fromUri(testCase.baseUri);
+      ResourceId resolved = resourceId.resolve(testCase.relativePath, 
testCase.resolveOptions);
+      assertEquals(testCase.expectedResult, resolved.toString());
+    }
+
+    // Tests for common Azure paths.
+    assertEquals(
+        AzfsResourceId.fromUri("azfs://account/container/tmp/aa"),
+        AzfsResourceId.fromUri("azfs://account/container/tmp/").resolve("aa", 
RESOLVE_FILE));
+    assertEquals(
+        AzfsResourceId.fromUri("azfs://account/container/tmp/aa/bb/cc/"),
+        AzfsResourceId.fromUri("azfs://account/container/tmp/")
+            .resolve("aa", RESOLVE_DIRECTORY)
+            .resolve("bb", RESOLVE_DIRECTORY)
+            .resolve("cc", RESOLVE_DIRECTORY));
+
+    // Tests absolute path.
+    assertEquals(
+        AzfsResourceId.fromUri("azfs://account/container/tmp/aa"),
+        AzfsResourceId.fromUri("azfs://account/container/tmp/bb/")
+            .resolve("azfs://account/container/tmp/aa", RESOLVE_FILE));
+
+    // Tests container with no ending '/'.
+    assertEquals(
+        AzfsResourceId.fromUri("azfs://account/my-container/tmp"),
+        AzfsResourceId.fromUri("azfs://account/my-container").resolve("tmp", 
RESOLVE_FILE));
+
+    // Tests path with unicode
+    assertEquals(
+        AzfsResourceId.fromUri("azfs://account/container/输出 目录/输出 文件01.txt"),
+        AzfsResourceId.fromUri("azfs://account/container/输出 目录/")
+            .resolve("输出 文件01.txt", RESOLVE_FILE));
+  }
+
+  @Test
+  public void testResolveInvalidInputs() {
+    thrown.expect(IllegalArgumentException.class);
+    thrown.expectMessage("Cannot resolve a file with a directory path: 
[tmp/]");
+    AzfsResourceId.fromUri("azfs://account/my_container/").resolve("tmp/", 
RESOLVE_FILE);
+  }
+
+  @Test
+  public void testResolveInvalidNotDirectory() {
+    ResourceId tmpDir =
+        AzfsResourceId.fromUri("azfs://account/my_container/").resolve("tmp 
dir", RESOLVE_FILE);
+
+    thrown.expect(IllegalStateException.class);
+    thrown.expectMessage(
+        "Expected this resource to be a directory, but was 
[azfs://account/my_container/tmp dir]");
+    tmpDir.resolve("aa", RESOLVE_FILE);
+  }
+
+  @Test
+  public void testS3ResolveWithFileBase() {
+    ResourceId resourceId = 
AzfsResourceId.fromUri("azfs://account/container/path/to/file");
+    thrown.expect(IllegalStateException.class);
+    resourceId.resolve("child-path", RESOLVE_DIRECTORY); // resource is not a 
directory
+  }
+
+  @Test
+  public void testResolveParentToFile() {
+    ResourceId resourceId = 
AzfsResourceId.fromUri("azfs://account/container/path/to/dir/");
+    thrown.expect(IllegalArgumentException.class);
+    resourceId.resolve("..", RESOLVE_FILE); // '..' only resolves as dir, not 
as file
+  }
+
+  @Test
+  public void testEquals() {
+    AzfsResourceId a = AzfsResourceId.fromComponents("account", "container", 
"a/b/c");
+    AzfsResourceId b = AzfsResourceId.fromComponents("account", "container", 
"a/b/c");
+    assertEquals(a, a);
+    assertEquals(a, b);
+
+    b = AzfsResourceId.fromComponents(a.getAccount(), a.getContainer(), 
"a/b/c/");
+    assertNotEquals(a, b);

Review comment:
       `assertNotEquals(a, b)` means the same as ``assertNotEquals(b, a)

##########
File path: 
sdks/java/io/azure/src/test/java/org/apache/beam/sdk/io/azure/blobstore/AzfsResourceIdTest.java
##########
@@ -0,0 +1,308 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.beam.sdk.io.azure.blobstore;
+
+import static 
org.apache.beam.sdk.io.fs.ResolveOptions.StandardResolveOptions.RESOLVE_DIRECTORY;
+import static 
org.apache.beam.sdk.io.fs.ResolveOptions.StandardResolveOptions.RESOLVE_FILE;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Arrays;
+import java.util.List;
+import org.apache.beam.sdk.io.fs.ResolveOptions;
+import org.apache.beam.sdk.io.fs.ResourceId;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+@RunWith(JUnit4.class)
+public class AzfsResourceIdTest {
+
+  @Rule public ExpectedException thrown = ExpectedException.none();
+
+  static final class TestCase {
+
+    final String baseUri;
+    final String relativePath;
+    final ResolveOptions.StandardResolveOptions resolveOptions;
+    final String expectedResult;
+
+    TestCase(
+        String baseUri,
+        String relativePath,
+        ResolveOptions.StandardResolveOptions resolveOptions,
+        String expectedResult) {
+      this.baseUri = baseUri;
+      this.relativePath = relativePath;
+      this.resolveOptions = resolveOptions;
+      this.expectedResult = expectedResult;
+    }
+  }
+
+  // Each test case is an expected URL, then the components used to build it.
+  // Empty components result in a double slash.
+  private static final List<TestCase> PATH_TEST_CASES =
+      Arrays.asList(
+          new TestCase(
+              "azfs://account/container/", "", RESOLVE_DIRECTORY, 
"azfs://account/container/"),
+          new TestCase(
+              "azfs://account/container", "", RESOLVE_DIRECTORY, 
"azfs://account/container/"),
+          new TestCase(
+              "azfs://account/container",
+              "path/to/dir",
+              RESOLVE_DIRECTORY,
+              "azfs://account/container/path/to/dir/"),
+          new TestCase(
+              "azfs://account/container",
+              "path/to/object",
+              RESOLVE_FILE,
+              "azfs://account/container/path/to/object"),
+          new TestCase(
+              "azfs://account/container/path/to/dir/",
+              "..",
+              RESOLVE_DIRECTORY,
+              "azfs://account/container/path/to/"));
+
+  @Test
+  public void testResolve() {
+    for (TestCase testCase : PATH_TEST_CASES) {
+      ResourceId resourceId = AzfsResourceId.fromUri(testCase.baseUri);
+      ResourceId resolved = resourceId.resolve(testCase.relativePath, 
testCase.resolveOptions);
+      assertEquals(testCase.expectedResult, resolved.toString());
+    }
+
+    // Tests for common Azure paths.
+    assertEquals(
+        AzfsResourceId.fromUri("azfs://account/container/tmp/aa"),
+        AzfsResourceId.fromUri("azfs://account/container/tmp/").resolve("aa", 
RESOLVE_FILE));
+    assertEquals(
+        AzfsResourceId.fromUri("azfs://account/container/tmp/aa/bb/cc/"),
+        AzfsResourceId.fromUri("azfs://account/container/tmp/")
+            .resolve("aa", RESOLVE_DIRECTORY)
+            .resolve("bb", RESOLVE_DIRECTORY)
+            .resolve("cc", RESOLVE_DIRECTORY));
+
+    // Tests absolute path.
+    assertEquals(
+        AzfsResourceId.fromUri("azfs://account/container/tmp/aa"),
+        AzfsResourceId.fromUri("azfs://account/container/tmp/bb/")
+            .resolve("azfs://account/container/tmp/aa", RESOLVE_FILE));
+
+    // Tests container with no ending '/'.
+    assertEquals(
+        AzfsResourceId.fromUri("azfs://account/my-container/tmp"),
+        AzfsResourceId.fromUri("azfs://account/my-container").resolve("tmp", 
RESOLVE_FILE));
+
+    // Tests path with unicode
+    assertEquals(
+        AzfsResourceId.fromUri("azfs://account/container/输出 目录/输出 文件01.txt"),
+        AzfsResourceId.fromUri("azfs://account/container/输出 目录/")
+            .resolve("输出 文件01.txt", RESOLVE_FILE));
+  }
+
+  @Test
+  public void testResolveInvalidInputs() {
+    thrown.expect(IllegalArgumentException.class);
+    thrown.expectMessage("Cannot resolve a file with a directory path: 
[tmp/]");
+    AzfsResourceId.fromUri("azfs://account/my_container/").resolve("tmp/", 
RESOLVE_FILE);
+  }
+
+  @Test
+  public void testResolveInvalidNotDirectory() {
+    ResourceId tmpDir =
+        AzfsResourceId.fromUri("azfs://account/my_container/").resolve("tmp 
dir", RESOLVE_FILE);
+
+    thrown.expect(IllegalStateException.class);
+    thrown.expectMessage(
+        "Expected this resource to be a directory, but was 
[azfs://account/my_container/tmp dir]");
+    tmpDir.resolve("aa", RESOLVE_FILE);
+  }
+
+  @Test
+  public void testS3ResolveWithFileBase() {
+    ResourceId resourceId = 
AzfsResourceId.fromUri("azfs://account/container/path/to/file");
+    thrown.expect(IllegalStateException.class);
+    resourceId.resolve("child-path", RESOLVE_DIRECTORY); // resource is not a 
directory
+  }
+
+  @Test
+  public void testResolveParentToFile() {
+    ResourceId resourceId = 
AzfsResourceId.fromUri("azfs://account/container/path/to/dir/");
+    thrown.expect(IllegalArgumentException.class);
+    resourceId.resolve("..", RESOLVE_FILE); // '..' only resolves as dir, not 
as file
+  }
+
+  @Test
+  public void testEquals() {
+    AzfsResourceId a = AzfsResourceId.fromComponents("account", "container", 
"a/b/c");
+    AzfsResourceId b = AzfsResourceId.fromComponents("account", "container", 
"a/b/c");
+    assertEquals(a, a);
+    assertEquals(a, b);
+
+    b = AzfsResourceId.fromComponents(a.getAccount(), a.getContainer(), 
"a/b/c/");
+    assertNotEquals(a, b);
+    assertNotEquals(b, a);
+
+    b = AzfsResourceId.fromComponents(a.getAccount(), a.getContainer(), 
"x/y/z");
+    assertNotEquals(a, b);
+    assertNotEquals(b, a);
+
+    b = AzfsResourceId.fromComponents(a.getAccount(), "other-container", 
a.getBlob());
+    assertNotEquals(a, b);
+    assertNotEquals(b, a);
+
+    b = AzfsResourceId.fromComponents("other-account", a.getContainer(), 
a.getBlob());
+    assertNotEquals(a, b);
+    assertNotEquals(b, a);
+
+    assertEquals(
+        AzfsResourceId.fromUri("azfs://account/container"),
+        AzfsResourceId.fromUri("azfs://account/container/"));
+  }
+
+  @Test
+  public void testFromComponents() {

Review comment:
       Please also test when `blob` is null and when `blob` is empty.

##########
File path: 
sdks/java/io/azure/src/test/java/org/apache/beam/sdk/io/azure/blobstore/AzureBlobStoreFileSystemTest.java
##########
@@ -15,3 +15,4 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+package org.apache.beam.sdk.io.azure.blobstore;

Review comment:
       Remove the empty file?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to