zachjsh commented on code in PR #15630:
URL: https://github.com/apache/druid/pull/15630#discussion_r1464024170


##########
extensions-core/azure-extensions/src/main/java/org/apache/druid/data/input/azure/AzureStorageAccountInputSource.java:
##########
@@ -0,0 +1,253 @@
+/*
+ * 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.druid.data.input.azure;
+
+import com.azure.storage.blob.models.BlobStorageException;
+import com.azure.storage.blob.specialized.BlockBlobClient;
+import com.fasterxml.jackson.annotation.JacksonInject;
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.google.common.base.Preconditions;
+import com.google.common.collect.Iterators;
+import org.apache.druid.data.input.InputEntity;
+import org.apache.druid.data.input.InputSplit;
+import org.apache.druid.data.input.impl.CloudObjectInputSource;
+import org.apache.druid.data.input.impl.CloudObjectLocation;
+import org.apache.druid.data.input.impl.CloudObjectSplitWidget;
+import org.apache.druid.data.input.impl.SplittableInputSource;
+import org.apache.druid.data.input.impl.systemfield.SystemField;
+import org.apache.druid.data.input.impl.systemfield.SystemFields;
+import org.apache.druid.java.util.common.Pair;
+import org.apache.druid.storage.azure.AzureAccountConfig;
+import org.apache.druid.storage.azure.AzureCloudBlobIterableFactory;
+import org.apache.druid.storage.azure.AzureIngestClientFactory;
+import org.apache.druid.storage.azure.AzureInputDataConfig;
+import org.apache.druid.storage.azure.AzureStorage;
+
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+import java.net.URI;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Objects;
+import java.util.Set;
+
+/**
+ * Abstracts the Azure storage system where input data is stored. Allows users 
to retrieve entities in
+ * the storage system that match either a particular uri, prefix, or object.
+ */
+public class AzureStorageAccountInputSource extends CloudObjectInputSource
+{
+  public static final String SCHEME = "azureStorage";
+
+  private final AzureEntityFactory entityFactory;
+  private final AzureCloudBlobIterableFactory azureCloudBlobIterableFactory;
+  private final AzureInputDataConfig inputDataConfig;
+  private final AzureInputSourceConfig azureInputSourceConfig;
+  private final AzureAccountConfig azureAccountConfig;
+
+  private final AzureIngestClientFactory azureIngestClientFactory;
+
+  @JsonCreator
+  public AzureStorageAccountInputSource(
+      @JacksonInject AzureEntityFactory entityFactory,
+      @JacksonInject AzureCloudBlobIterableFactory 
azureCloudBlobIterableFactory,
+      @JacksonInject AzureInputDataConfig inputDataConfig,
+      @JacksonInject AzureAccountConfig azureAccountConfig,
+      @JsonProperty("uris") @Nullable List<URI> uris,
+      @JsonProperty("prefixes") @Nullable List<URI> prefixes,
+      @JsonProperty("objects") @Nullable List<CloudObjectLocation> objects,
+      @JsonProperty("objectGlob") @Nullable String objectGlob,
+      @JsonProperty("properties") @Nullable AzureInputSourceConfig 
azureInputSourceConfig,
+      @JsonProperty(SYSTEM_FIELDS_PROPERTY) @Nullable SystemFields systemFields
+  )
+  {
+    super(SCHEME, uris, prefixes, objects, objectGlob, systemFields);
+    this.entityFactory = Preconditions.checkNotNull(entityFactory, 
"AzureEntityFactory");
+    this.azureCloudBlobIterableFactory = Preconditions.checkNotNull(
+        azureCloudBlobIterableFactory,
+        "AzureCloudBlobIterableFactory"
+    );
+    this.inputDataConfig = Preconditions.checkNotNull(inputDataConfig, 
"AzureInputDataConfig");
+    this.azureInputSourceConfig = azureInputSourceConfig;
+    this.azureAccountConfig = azureAccountConfig;
+    this.azureIngestClientFactory = new AzureIngestClientFactory(
+        azureAccountConfig,
+        azureInputSourceConfig
+    );
+  }
+
+  @JsonIgnore
+  @Nonnull
+  @Override
+  public Set<String> getTypes()
+  {
+    return Collections.singleton(SCHEME);
+  }
+
+  @Override
+  public SplittableInputSource<List<CloudObjectLocation>> 
withSplit(InputSplit<List<CloudObjectLocation>> split)
+  {
+    return new AzureStorageAccountInputSource(
+        entityFactory,
+        azureCloudBlobIterableFactory,
+        inputDataConfig,
+        azureAccountConfig,
+        null,
+        null,
+        split.get(),
+        getObjectGlob(),
+        azureInputSourceConfig,
+        systemFields
+    );
+  }
+
+  @Override
+  public Object getSystemFieldValue(InputEntity entity, SystemField field)
+  {
+    final AzureEntity azureEntity = (AzureEntity) entity;
+
+    switch (field) {
+      case URI:
+        return azureEntity.getUri().toString();
+      case BUCKET:
+        return azureEntity.getLocation().getBucket();
+      case PATH:
+        return azureEntity.getLocation().getPath();
+      default:
+        return null;
+    }
+  }
+
+  @Override
+  protected AzureEntity createEntity(CloudObjectLocation location)
+  {
+    return entityFactory.create(
+        location,
+        new AzureStorage(azureIngestClientFactory, location.getBucket()),
+        SCHEME
+    );
+  }
+
+  @Override
+  protected CloudObjectSplitWidget getSplitWidget()
+  {
+    class SplitWidget implements CloudObjectSplitWidget
+    {
+      @Override
+      public Iterator<LocationWithSize> 
getDescriptorIteratorForPrefixes(List<URI> prefixes)
+      {
+        return Iterators.transform(
+            azureCloudBlobIterableFactory.create(prefixes, 
inputDataConfig.getMaxListingLength(), new 
AzureStorage(azureIngestClientFactory, null)).iterator(),

Review Comment:
   Do you need to create a new `AzureStorage` instance for each prefix? Or can 
we instantiate one and reuse it for all? Seems that the AzureStorage is 
instantiated with exactly the same parameters for each.



-- 
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.

To unsubscribe, e-mail: [email protected]

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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to