rdblue commented on code in PR #4575:
URL: https://github.com/apache/iceberg/pull/4575#discussion_r852443989


##########
core/src/main/java/org/apache/iceberg/rest/RESTSessionCatalog.java:
##########
@@ -0,0 +1,479 @@
+/*
+ * 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.rest;
+
+import com.github.benmanes.caffeine.cache.Cache;
+import com.github.benmanes.caffeine.cache.Caffeine;
+import java.io.Closeable;
+import java.io.IOException;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.function.Function;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.iceberg.BaseTable;
+import org.apache.iceberg.CatalogProperties;
+import org.apache.iceberg.CatalogUtil;
+import org.apache.iceberg.MetadataUpdate;
+import org.apache.iceberg.PartitionSpec;
+import org.apache.iceberg.Schema;
+import org.apache.iceberg.SortOrder;
+import org.apache.iceberg.Table;
+import org.apache.iceberg.TableMetadata;
+import org.apache.iceberg.Transaction;
+import org.apache.iceberg.Transactions;
+import org.apache.iceberg.catalog.BaseSessionCatalog;
+import org.apache.iceberg.catalog.Catalog;
+import org.apache.iceberg.catalog.Namespace;
+import org.apache.iceberg.catalog.TableIdentifier;
+import org.apache.iceberg.exceptions.NoSuchNamespaceException;
+import org.apache.iceberg.exceptions.NoSuchTableException;
+import org.apache.iceberg.hadoop.Configurable;
+import org.apache.iceberg.io.FileIO;
+import org.apache.iceberg.io.ResolvingFileIO;
+import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
+import org.apache.iceberg.relocated.com.google.common.collect.ImmutableList;
+import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap;
+import org.apache.iceberg.relocated.com.google.common.collect.Maps;
+import org.apache.iceberg.rest.requests.CreateNamespaceRequest;
+import org.apache.iceberg.rest.requests.CreateTableRequest;
+import org.apache.iceberg.rest.requests.UpdateNamespacePropertiesRequest;
+import org.apache.iceberg.rest.responses.ConfigResponse;
+import org.apache.iceberg.rest.responses.CreateNamespaceResponse;
+import org.apache.iceberg.rest.responses.GetNamespaceResponse;
+import org.apache.iceberg.rest.responses.ListNamespacesResponse;
+import org.apache.iceberg.rest.responses.ListTablesResponse;
+import org.apache.iceberg.rest.responses.LoadTableResponse;
+import org.apache.iceberg.rest.responses.UpdateNamespacePropertiesResponse;
+import org.apache.iceberg.util.Pair;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class RESTSessionCatalog extends BaseSessionCatalog implements 
Configurable<Configuration>, Closeable {
+  private static final Logger LOG = 
LoggerFactory.getLogger(RESTSessionCatalog.class);
+  private final Function<Map<String, String>, RESTClient> clientBuilder;
+  private final Cache<String, Map<String, String>> headers = 
Caffeine.newBuilder().build();
+  private Map<String, String> baseHeaders = ImmutableMap.of();
+  private RESTClient client = null;
+  private String catalogName = null;
+  private Map<String, String> properties = null;
+  private ResourcePaths paths = null;
+  private Object conf = null;
+  private FileIO io = null;
+
+  public RESTSessionCatalog() {
+    this(new HTTPClientFactory());
+  }
+
+  RESTSessionCatalog(Function<Map<String, String>, RESTClient> clientBuilder) {
+    this.clientBuilder = clientBuilder;
+  }
+
+  @Override
+  public void initialize(String name, Map<String, String> props) {
+    Preconditions.checkArgument(props != null, "Invalid configuration: null");
+    this.baseHeaders = RESTUtil.extractPrefixMap(props, "header.");
+    ConfigResponse config = fetchConfig(props);
+    Map<String, String> mergedProps = config.merge(props);
+    this.client = clientBuilder.apply(mergedProps);
+    this.catalogName = name;
+    this.properties = mergedProps;
+    this.paths = ResourcePaths.forCatalogProperties(properties);
+    String ioImpl = properties.get(CatalogProperties.FILE_IO_IMPL);
+    this.io = CatalogUtil.loadFileIO(ioImpl != null ? ioImpl : 
ResolvingFileIO.class.getName(), properties, conf);
+  }
+
+  Map<String, String> headers(SessionContext context) {
+    return headers.get(context.sessionId(), id -> {
+      ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
+      builder.putAll(baseHeaders);
+
+      if (context.identity() != null) {

Review Comment:
   Yes, I agree that this is probably going to change. I'm not sure if 
`identity` and `credential` are the right things to track here. And in Trino we 
would probably want to set session ID to one or both of them to have sessions 
that are not simply single queries. I'm definitely open to suggestions!
   
   My main concern right now was to get people looking at the new catalog 
interface and make sure we have consensus that it's a good idea. What metadata 
we track in a session is important, but secondary if we don't end up going this 
direction.



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