amogh-jahagirdar commented on code in PR #12799:
URL: https://github.com/apache/iceberg/pull/12799#discussion_r2070315105


##########
aws/src/main/java/org/apache/iceberg/aws/s3/PrefixedS3Client.java:
##########
@@ -0,0 +1,121 @@
+/*
+ * 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.iceberg.aws.s3;
+
+import java.util.Map;
+import org.apache.iceberg.aws.AwsClientFactory;
+import org.apache.iceberg.aws.S3FileIOAwsClientFactories;
+import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
+import org.apache.iceberg.relocated.com.google.common.base.Strings;
+import org.apache.iceberg.util.SerializableSupplier;
+import software.amazon.awssdk.services.s3.S3AsyncClient;
+import software.amazon.awssdk.services.s3.S3Client;
+
+public class PrefixedS3Client implements AutoCloseable {

Review Comment:
   Should this be package private instead? My thinking is that users who want 
to get the underlying S3 client from S3FileIO could just do something like 
`fileIO.clientFor(path)`  to get the underlying client or 
`fileIO.asyncClientFor(path)`  for the async case. It avoids having to leak the 
notion of a `PrefixedS3Client` to users who can just work with S3 clients 
directly as they are used to.



##########
aws/src/main/java/org/apache/iceberg/aws/s3/S3FileIO.java:
##########
@@ -384,30 +386,85 @@ public void deletePrefix(String prefix) {
     deleteFiles(() -> 
Streams.stream(listPrefix(prefix)).map(FileInfo::location).iterator());
   }
 
+  /**
+   * Returns the {@link S3Client} that is configured for this {@link 
org.apache.iceberg.io.FileIO}
+   * instance.
+   *
+   * @deprecated since 1.10.0, will be removed in 1.11.0; use {@link
+   *     S3FileIO#clientForStoragePath(String)} instead.
+   */
+  @Deprecated
   public S3Client client() {
-    if (client == null) {
-      synchronized (this) {
-        if (client == null) {
-          client = s3.get();
-        }
+    return clientForStoragePath("s3").s3();
+  }
+
+  /**
+   * Returns the {@link S3AsyncClient} that is configured for this {@link
+   * org.apache.iceberg.io.FileIO} instance.
+   *
+   * @deprecated since 1.10.0, will be removed in 1.11.0; use {@link
+   *     S3FileIO#clientForStoragePath(String)} instead.
+   */
+  @Deprecated
+  public S3AsyncClient asyncClient() {

Review Comment:
   Hm, I'm not sure about deprecating these. If I understand the intent behind 
deprecating this, the goal is to essentially make it explicit on a user to 
specify the desired path, and if it's the "root" s3 path they should still 
specify that. 
   
   In my mind, in general we won't have multiple storage credential prefixes 
and most use cases will be using the single root level credentials. So then 
what follows at least in my head is the API should be designed around the 
general case and exposing an additional API for the explicit storage path case.



##########
aws/src/main/java/org/apache/iceberg/aws/s3/S3FileIO.java:
##########
@@ -384,30 +386,85 @@ public void deletePrefix(String prefix) {
     deleteFiles(() -> 
Streams.stream(listPrefix(prefix)).map(FileInfo::location).iterator());
   }
 
+  /**
+   * Returns the {@link S3Client} that is configured for this {@link 
org.apache.iceberg.io.FileIO}
+   * instance.
+   *
+   * @deprecated since 1.10.0, will be removed in 1.11.0; use {@link
+   *     S3FileIO#clientForStoragePath(String)} instead.
+   */
+  @Deprecated
   public S3Client client() {
-    if (client == null) {
-      synchronized (this) {
-        if (client == null) {
-          client = s3.get();
-        }
+    return clientForStoragePath("s3").s3();
+  }
+
+  /**
+   * Returns the {@link S3AsyncClient} that is configured for this {@link
+   * org.apache.iceberg.io.FileIO} instance.
+   *
+   * @deprecated since 1.10.0, will be removed in 1.11.0; use {@link
+   *     S3FileIO#clientForStoragePath(String)} instead.
+   */
+  @Deprecated
+  public S3AsyncClient asyncClient() {

Review Comment:
   Well I guess one could make the argument that in the general case 
integrations are just going through `FileIO` and not extracing the underlying 
client typically. In that model, what this change is doing is fine since the 
FIleIO implementation hides that and for the users who do want the underlying 
client it's better to make them explicitly pass in the storage path



##########
aws/src/main/java/org/apache/iceberg/aws/s3/S3FileIO.java:
##########
@@ -384,30 +386,85 @@ public void deletePrefix(String prefix) {
     deleteFiles(() -> 
Streams.stream(listPrefix(prefix)).map(FileInfo::location).iterator());
   }
 
+  /**
+   * Returns the {@link S3Client} that is configured for this {@link 
org.apache.iceberg.io.FileIO}
+   * instance.
+   *
+   * @deprecated since 1.10.0, will be removed in 1.11.0; use {@link
+   *     S3FileIO#clientForStoragePath(String)} instead.
+   */
+  @Deprecated
   public S3Client client() {
-    if (client == null) {
-      synchronized (this) {
-        if (client == null) {
-          client = s3.get();
-        }
+    return clientForStoragePath("s3").s3();
+  }
+
+  /**
+   * Returns the {@link S3AsyncClient} that is configured for this {@link
+   * org.apache.iceberg.io.FileIO} instance.
+   *
+   * @deprecated since 1.10.0, will be removed in 1.11.0; use {@link
+   *     S3FileIO#clientForStoragePath(String)} instead.
+   */
+  @Deprecated
+  public S3AsyncClient asyncClient() {
+    return clientForStoragePath("s3").s3Async();
+  }
+
+  public PrefixedS3Client clientForStoragePath(String storagePath) {
+    PrefixedS3Client client;
+    String matchingPrefix = "s3";

Review Comment:
   Would it make sense to move all the references of "s3" to a constant in this 
file `ROOT_PREFIX`? 



-- 
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: issues-unsubscr...@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org
For additional commands, e-mail: issues-h...@iceberg.apache.org

Reply via email to