ettirapp commented on a change in pull request #12335: URL: https://github.com/apache/beam/pull/12335#discussion_r459151578
########## 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: I just updated the constructor so that if blob is empty it is set to `null`. ---------------------------------------------------------------- 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]
