You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by GitBox <gi...@apache.org> on 2022/04/17 23:11:29 UTC
[GitHub] [iceberg] rdblue opened a new pull request, #4575: Core: Add context headers to RESTCatalog
rdblue opened a new pull request, #4575:
URL: https://github.com/apache/iceberg/pull/4575
This adds `withHeaders` to `RESTCatalog` that can set contextual headers. The new method returns a wrapper `Catalog` that will set the headers and then call the base `RESTCatalog`. This allows customizing headers sent to the REST catalog service based on context rather than fixed configuration.
--
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-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
[GitHub] [iceberg] kbendick commented on a diff in pull request #4575: Core: Add context headers to RESTCatalog
Posted by GitBox <gi...@apache.org>.
kbendick commented on code in PR #4575:
URL: https://github.com/apache/iceberg/pull/4575#discussion_r863571715
##########
core/src/main/java/org/apache/iceberg/catalog/BaseSessionCatalog.java:
##########
@@ -0,0 +1,170 @@
+/*
+ * 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.catalog;
+
+import com.github.benmanes.caffeine.cache.Cache;
+import com.github.benmanes.caffeine.cache.Caffeine;
+import java.io.Closeable;
+import java.io.IOException;
+import java.io.UncheckedIOException;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
+import java.util.function.Function;
+import org.apache.iceberg.Schema;
+import org.apache.iceberg.Table;
+import org.apache.iceberg.exceptions.NamespaceNotEmptyException;
+import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap;
+import org.apache.iceberg.relocated.com.google.common.collect.ImmutableSet;
+
+public abstract class BaseSessionCatalog implements SessionCatalog {
+ private final Cache<String, Catalog> catalogs = Caffeine.newBuilder()
+ .expireAfterAccess(10, TimeUnit.MINUTES)
+ .removalListener((id, catalog, cause) -> {
+ if (catalog instanceof Closeable) {
+ try {
+ ((Closeable) catalog).close();
+ } catch (IOException e) {
+ throw new UncheckedIOException(String.format("Failed to close catalog: %s", catalog), e);
+ }
+ }
+ })
+ .build();
+
+ private String name = null;
+ private Map<String, String> properties = null;
+
+ @Override
+ public void initialize(String catalogName, Map<String, String> props) {
+ this.name = catalogName;
+ this.properties = props;
+ }
Review Comment:
Should we be inserting the catalog into the `catalogs` cache? I don't see where that is happening.
--
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-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
[GitHub] [iceberg] danielcweeks commented on a diff in pull request #4575: Core: Add context headers to RESTCatalog
Posted by GitBox <gi...@apache.org>.
danielcweeks commented on code in PR #4575:
URL: https://github.com/apache/iceberg/pull/4575#discussion_r853249916
##########
api/src/main/java/org/apache/iceberg/catalog/SessionCatalog.java:
##########
@@ -0,0 +1,323 @@
+/*
+ * 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.catalog;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.UUID;
+import org.apache.iceberg.Schema;
+import org.apache.iceberg.Table;
+import org.apache.iceberg.exceptions.AlreadyExistsException;
+import org.apache.iceberg.exceptions.NamespaceNotEmptyException;
+import org.apache.iceberg.exceptions.NoSuchNamespaceException;
+import org.apache.iceberg.exceptions.NoSuchTableException;
+import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap;
+
+/**
+ * A Catalog API for table and namespace operations that includes session context.
+ */
+public interface SessionCatalog {
+ /**
+ * Context for a session.
+ */
+ final class SessionContext {
+ private final String sessionId;
+ private final String identity;
+ private final String credential;
Review Comment:
Java's Subject represents them as Set<Object> and Trino has Map<String,String> for various "extra" credentials
--
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-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
[GitHub] [iceberg] jackye1995 commented on a diff in pull request #4575: Core: Add context headers to RESTCatalog
Posted by GitBox <gi...@apache.org>.
jackye1995 commented on code in PR #4575:
URL: https://github.com/apache/iceberg/pull/4575#discussion_r853339764
##########
api/src/main/java/org/apache/iceberg/catalog/SessionCatalog.java:
##########
@@ -0,0 +1,323 @@
+/*
+ * 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.catalog;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.UUID;
+import org.apache.iceberg.Schema;
+import org.apache.iceberg.Table;
+import org.apache.iceberg.exceptions.AlreadyExistsException;
+import org.apache.iceberg.exceptions.NamespaceNotEmptyException;
+import org.apache.iceberg.exceptions.NoSuchNamespaceException;
+import org.apache.iceberg.exceptions.NoSuchTableException;
+import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap;
+
+/**
+ * A Catalog API for table and namespace operations that includes session context.
+ */
+public interface SessionCatalog {
+ /**
+ * Context for a session.
+ */
+ final class SessionContext {
+ private final String sessionId;
+ private final String identity;
+ private final String credential;
Review Comment:
The credential is also a part of identity, for reference: https://github.com/trinodb/trino/blob/master/core/trino-spi/src/main/java/io/trino/spi/security/ConnectorIdentity.java
--
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-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
[GitHub] [iceberg] rdblue commented on a diff in pull request #4575: Core: Add context headers to RESTCatalog
Posted by GitBox <gi...@apache.org>.
rdblue commented on code in PR #4575:
URL: https://github.com/apache/iceberg/pull/4575#discussion_r852353457
##########
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 {
Review Comment:
This class is the original `RESTCatalog`. The logic is unchanged other than to pass headers into the `RESTClient`.
--
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-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
[GitHub] [iceberg] rdblue commented on a diff in pull request #4575: Core: Add context headers to RESTCatalog
Posted by GitBox <gi...@apache.org>.
rdblue commented on code in PR #4575:
URL: https://github.com/apache/iceberg/pull/4575#discussion_r873229652
##########
core/src/main/java/org/apache/iceberg/catalog/BaseSessionCatalog.java:
##########
@@ -0,0 +1,170 @@
+/*
+ * 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.catalog;
+
+import com.github.benmanes.caffeine.cache.Cache;
+import com.github.benmanes.caffeine.cache.Caffeine;
+import java.io.Closeable;
+import java.io.IOException;
+import java.io.UncheckedIOException;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
+import java.util.function.Function;
+import org.apache.iceberg.Schema;
+import org.apache.iceberg.Table;
+import org.apache.iceberg.exceptions.NamespaceNotEmptyException;
+import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap;
+import org.apache.iceberg.relocated.com.google.common.collect.ImmutableSet;
+
+public abstract class BaseSessionCatalog implements SessionCatalog {
+ private final Cache<String, Catalog> catalogs = Caffeine.newBuilder()
+ .expireAfterAccess(10, TimeUnit.MINUTES)
+ .removalListener((id, catalog, cause) -> {
+ if (catalog instanceof Closeable) {
+ try {
+ ((Closeable) catalog).close();
+ } catch (IOException e) {
+ throw new UncheckedIOException(String.format("Failed to close catalog: %s", catalog), e);
+ }
+ }
+ })
+ .build();
+
+ private String name = null;
+ private Map<String, String> properties = null;
+
+ @Override
+ public void initialize(String catalogName, Map<String, String> props) {
+ this.name = catalogName;
+ this.properties = props;
+ }
Review Comment:
The cache is creating the catalog if it doesn't exist when `get` is called.
--
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-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
[GitHub] [iceberg] rdblue commented on pull request #4575: Core: Add context headers to RESTCatalog
Posted by GitBox <gi...@apache.org>.
rdblue commented on PR #4575:
URL: https://github.com/apache/iceberg/pull/4575#issuecomment-1100967612
An alternative to this that we should also consider is adding `SessionContext` to catalog calls. That would add an interface like this:
```java
public interface SessionCatalog extends Catalog {
final class SessionContext {
private final String sessionId;
private final String identity;
private final String credential;
private final Map<String, String> sessionConfig;
public SessionContext(String sessionId, String identity, String credential, Map<String, String> sessionConfig) {
this.sessionId = sessionId;
this.identity = identity;
this.credential = credential;
this.sessionConfig = sessionConfig;
}
public String sessionId() {
return sessionId;
}
public String identity() {
return identity;
}
public String credential() {
return credential;
}
public Map<String, String> sessionConfig() {
return sessionConfig;
}
}
void initialize(String name, Map<String, String> properties);
String name();
Catalog withContext(SessionContext context);
List<TableIdentifier> listTables(SessionContext context, Namespace namespace);
TableBuilder buildTable(SessionContext context, TableIdentifier ident, Schema schema);
Table registerTable(TableIdentifier ident, String metadataFileLocation);
default boolean tableExists(SessionContext context, TableIdentifier ident) {
try {
loadTable(context, ident);
return true;
} catch (NoSuchTableException e) {
return false;
}
}
Table loadTable(SessionContext context, TableIdentifier ident);
boolean dropTable(SessionContext context, TableIdentifier ident);
boolean purgeTable(SessionContext context, TableIdentifier ident);
void renameTable(SessionContext context, TableIdentifier from, TableIdentifier to);
void invalidateTable(SessionContext context, TableIdentifier ident);
}
```
--
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-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
[GitHub] [iceberg] jackye1995 commented on a diff in pull request #4575: Core: Add context headers to RESTCatalog
Posted by GitBox <gi...@apache.org>.
jackye1995 commented on code in PR #4575:
URL: https://github.com/apache/iceberg/pull/4575#discussion_r852429805
##########
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:
I notice here that although we use session Id as the cache key for the headers map, what we are setting are just headers for identity and credentials. Basically the identity and credentials are the determining factor of the cache content (`Catalog` in the `BaseSessionCatalog`, and header map here). This is very similar to https://github.com/prestodb/presto/blob/master/presto-iceberg/src/main/java/com/facebook/presto/iceberg/IcebergResourceFactory.java#L88.
That means if those information do not change, the same cached content could be shared across sessions. For example, here if 2 sessions have the same identity and credential, they actually have the same headers. So does it make more sense to use `content.identity() + content.credential()` as the cache key? This could greatly improve the cache hit rate, instead of creating something new for each session. This is especially helpful if the session is short-lived, but the caller credential is shared across sessions.
--
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-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
[GitHub] [iceberg] jackye1995 commented on a diff in pull request #4575: Core: Add context headers to RESTCatalog
Posted by GitBox <gi...@apache.org>.
jackye1995 commented on code in PR #4575:
URL: https://github.com/apache/iceberg/pull/4575#discussion_r852429805
##########
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:
I notice here that although we use session Id as the key for the headers map, what we are setting are just headers for identity and credentials. Basically the identity and credentials are the determining factor of the cache content (`Catalog` in the `BaseSessionCatalog`, and header map here). This is very similar to https://github.com/prestodb/presto/blob/master/presto-iceberg/src/main/java/com/facebook/presto/iceberg/IcebergResourceFactory.java#L88.
That means if those information do not change, the same cached content could be shared across sessions. For example, here if 2 sessions have the same identity and credential, they actually have the same headers. So does it make more sense to use `content.identity() + content.credential()` as the cache key? This could greatly improve the cache hit rate, instead of creating something new for each session. This is especially helpful if the session is short-lived, but the caller credential is shared across sessions.
--
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-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
[GitHub] [iceberg] rdblue closed pull request #4575: Core: Add context headers to RESTCatalog
Posted by GitBox <gi...@apache.org>.
rdblue closed pull request #4575: Core: Add context headers to RESTCatalog
URL: https://github.com/apache/iceberg/pull/4575
--
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-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
[GitHub] [iceberg] rdblue commented on pull request #4575: Core: Add context headers to RESTCatalog
Posted by GitBox <gi...@apache.org>.
rdblue commented on PR #4575:
URL: https://github.com/apache/iceberg/pull/4575#issuecomment-1133762779
This has been fully replaced now that #4830 is posted. I'm going to close it.
--
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-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
[GitHub] [iceberg] rdblue commented on a diff in pull request #4575: Core: Add context headers to RESTCatalog
Posted by GitBox <gi...@apache.org>.
rdblue commented on code in PR #4575:
URL: https://github.com/apache/iceberg/pull/4575#discussion_r853253104
##########
api/src/main/java/org/apache/iceberg/catalog/SessionCatalog.java:
##########
@@ -0,0 +1,323 @@
+/*
+ * 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.catalog;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.UUID;
+import org.apache.iceberg.Schema;
+import org.apache.iceberg.Table;
+import org.apache.iceberg.exceptions.AlreadyExistsException;
+import org.apache.iceberg.exceptions.NamespaceNotEmptyException;
+import org.apache.iceberg.exceptions.NoSuchNamespaceException;
+import org.apache.iceberg.exceptions.NoSuchTableException;
+import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap;
+
+/**
+ * A Catalog API for table and namespace operations that includes session context.
+ */
+public interface SessionCatalog {
+ /**
+ * Context for a session.
+ */
+ final class SessionContext {
+ private final String sessionId;
+ private final String identity;
+ private final String credential;
Review Comment:
This is really helpful. I'm not at all sure how we want to track credentials and identity, so more ideas here are great.
--
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-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
[GitHub] [iceberg] rdblue commented on pull request #4575: Core: Add context headers to RESTCatalog
Posted by GitBox <gi...@apache.org>.
rdblue commented on PR #4575:
URL: https://github.com/apache/iceberg/pull/4575#issuecomment-1127042878
I've separated this into #4773 for the session catalog interface and #4772 for adding headers to the `HTTPClient`. I'll follow up to #4773 with an implementation of the new interface for `RESTCatalog`.
--
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-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
[GitHub] [iceberg] kbendick commented on a diff in pull request #4575: Core: Add context headers to RESTCatalog
Posted by GitBox <gi...@apache.org>.
kbendick commented on code in PR #4575:
URL: https://github.com/apache/iceberg/pull/4575#discussion_r863572639
##########
core/src/main/java/org/apache/iceberg/catalog/BaseSessionCatalog.java:
##########
@@ -0,0 +1,170 @@
+/*
+ * 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.catalog;
+
+import com.github.benmanes.caffeine.cache.Cache;
+import com.github.benmanes.caffeine.cache.Caffeine;
+import java.io.Closeable;
+import java.io.IOException;
+import java.io.UncheckedIOException;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
+import java.util.function.Function;
+import org.apache.iceberg.Schema;
+import org.apache.iceberg.Table;
+import org.apache.iceberg.exceptions.NamespaceNotEmptyException;
+import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap;
+import org.apache.iceberg.relocated.com.google.common.collect.ImmutableSet;
+
+public abstract class BaseSessionCatalog implements SessionCatalog {
+ private final Cache<String, Catalog> catalogs = Caffeine.newBuilder()
+ .expireAfterAccess(10, TimeUnit.MINUTES)
+ .removalListener((id, catalog, cause) -> {
+ if (catalog instanceof Closeable) {
+ try {
+ ((Closeable) catalog).close();
Review Comment:
Can we add a debug logging statement here? This seems like something that might wind up being hard to debug.
--
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-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
[GitHub] [iceberg] rdblue commented on a diff in pull request #4575: Core: Add context headers to RESTCatalog
Posted by GitBox <gi...@apache.org>.
rdblue commented on code in PR #4575:
URL: https://github.com/apache/iceberg/pull/4575#discussion_r852354177
##########
core/src/main/java/org/apache/iceberg/rest/RESTCatalog.java:
##########
@@ -26,425 +26,217 @@
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.Catalog;
import org.apache.iceberg.catalog.Namespace;
+import org.apache.iceberg.catalog.SessionCatalog;
import org.apache.iceberg.catalog.SupportsNamespaces;
import org.apache.iceberg.catalog.TableIdentifier;
import org.apache.iceberg.exceptions.NamespaceNotEmptyException;
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 RESTCatalog implements Catalog, SupportsNamespaces, Configurable<Configuration>, Closeable {
- private static final Logger LOG = LoggerFactory.getLogger(RESTCatalog.class);
- private final Function<Map<String, String>, RESTClient> clientBuilder;
- 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;
+ private final RESTSessionCatalog sessionCatalog;
+ private final SessionCatalog.SessionContext context;
+ private final Catalog delegate;
+ private final SupportsNamespaces nsDelegate;
+ private String name;
+ private Map<String, String> properties;
public RESTCatalog() {
- this(new HTTPClientFactory());
+ this(SessionCatalog.SessionContext.createEmpty(), new HTTPClientFactory());
Review Comment:
This class was moved to be `RESTSessionCatalog`. The implementation here is completely new. The purpose of this class is to wrap a `RESTSessionCatalog` and always pass a global session context.
--
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-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
[GitHub] [iceberg] RussellSpitzer commented on a diff in pull request #4575: Core: Add context headers to RESTCatalog
Posted by GitBox <gi...@apache.org>.
RussellSpitzer commented on code in PR #4575:
URL: https://github.com/apache/iceberg/pull/4575#discussion_r853442456
##########
core/src/main/java/org/apache/iceberg/catalog/BaseSessionCatalog.java:
##########
@@ -0,0 +1,170 @@
+/*
+ * 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.catalog;
+
+import com.github.benmanes.caffeine.cache.Cache;
+import com.github.benmanes.caffeine.cache.Caffeine;
+import java.io.Closeable;
+import java.io.IOException;
+import java.io.UncheckedIOException;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
+import java.util.function.Function;
+import org.apache.iceberg.Schema;
+import org.apache.iceberg.Table;
+import org.apache.iceberg.exceptions.NamespaceNotEmptyException;
+import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap;
+import org.apache.iceberg.relocated.com.google.common.collect.ImmutableSet;
+
+public abstract class BaseSessionCatalog implements SessionCatalog {
+ private final Cache<String, Catalog> catalogs = Caffeine.newBuilder()
+ .expireAfterAccess(10, TimeUnit.MINUTES)
+ .removalListener((id, catalog, cause) -> {
+ if (catalog instanceof Closeable) {
+ try {
+ ((Closeable) catalog).close();
Review Comment:
Does this mean any session is closed after 10 minutes of idle time? or that the session may not be closed but the Catalog will need to be reinitialized again?
--
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-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
[GitHub] [iceberg] rdblue commented on a diff in pull request #4575: Core: Add context headers to RESTCatalog
Posted by GitBox <gi...@apache.org>.
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
[GitHub] [iceberg] jackye1995 commented on a diff in pull request #4575: Core: Add context headers to RESTCatalog
Posted by GitBox <gi...@apache.org>.
jackye1995 commented on code in PR #4575:
URL: https://github.com/apache/iceberg/pull/4575#discussion_r853347091
##########
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:
I see. If we are focusing on the consensus part, I think it is pretty aligned with the [TrinoCatalog](https://github.com/trinodb/trino/blob/master/plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/catalog/TrinoCatalog.java) interface, there is a converter needed for a Trino [ConnectorSession](https://github.com/trinodb/trino/blob/master/core/trino-spi/src/main/java/io/trino/spi/connector/ConnectorSession.java) but that is overall straightforward.
The reason I bring up this identity and credential part here is that maybe Iceberg's `SessionContext` can be an interface but not an implementation, and we have `SessionCatalog<T extends SessionContext>`, and `SessionContext` has one important method `cacheKey()` that can be used to define if 2 sessions could share the same underlying catalog, and the cache key can on the extreme end be the session ID to have 1 different catalog for each session, or be a composite of identity and credential values.
In Trino, then we can have `IcebergConnectorSession implements SessionContext` and `TrinoCatalog implements SessionCatalog<IcebergConnectorSession>` as a way to simplify the `TrinoCatalog` class.
--
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-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
[GitHub] [iceberg] RussellSpitzer commented on a diff in pull request #4575: Core: Add context headers to RESTCatalog
Posted by GitBox <gi...@apache.org>.
RussellSpitzer commented on code in PR #4575:
URL: https://github.com/apache/iceberg/pull/4575#discussion_r853238699
##########
api/src/main/java/org/apache/iceberg/catalog/SessionCatalog.java:
##########
@@ -0,0 +1,323 @@
+/*
+ * 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.catalog;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.UUID;
+import org.apache.iceberg.Schema;
+import org.apache.iceberg.Table;
+import org.apache.iceberg.exceptions.AlreadyExistsException;
+import org.apache.iceberg.exceptions.NamespaceNotEmptyException;
+import org.apache.iceberg.exceptions.NoSuchNamespaceException;
+import org.apache.iceberg.exceptions.NoSuchTableException;
+import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap;
+
+/**
+ * A Catalog API for table and namespace operations that includes session context.
+ */
+public interface SessionCatalog {
+ /**
+ * Context for a session.
+ */
+ final class SessionContext {
+ private final String sessionId;
+ private final String identity;
+ private final String credential;
+ private final Map<String, String> properties;
+
+ public static SessionContext createEmpty() {
+ return new SessionContext(UUID.randomUUID().toString(), null, null, ImmutableMap.of());
+ }
+
+ public SessionContext(String sessionId, String identity, String credential, Map<String, String> properties) {
+ this.sessionId = sessionId;
+ this.identity = identity;
+ this.credential = credential;
+ this.properties = properties;
+ }
+
+ /**
+ * Returns a string that identifies this session.
+ * <p>
+ * This can be used for caching state within a session.
+ *
+ * @return a string that identifies this session
+ */
+ public String sessionId() {
+ return sessionId;
+ }
+
+ /**
+ * Returns a string that identifies the current user or principal.
+ * <p>
+ * This identity cannot change for a given session ID.
+ *
+ * @return a user or principal identity string
+ */
+ public String identity() {
+ return identity;
+ }
+
+ /**
+ * Returns a credential string.
+ * <p>
+ * This cannot change for a given session ID.
+ *
+ * @return a credential string
+ */
+ public String credential() {
+ return credential;
+ }
+
+ /**
+ * Returns a map of properties currently set for the session.
+ *
+ * @return a map of properties
+ */
+ public Map<String, String> properties() {
+ return properties;
+ }
+ }
+
+ /**
+ * Initialize given a custom name and a map of catalog properties.
+ *
+ * @param name a custom name for the catalog
+ * @param properties catalog properties
+ */
+ void initialize(String name, Map<String, String> properties);
+
+ /**
+ * Return the name for this catalog.
+ *
+ * @return this catalog's name
+ */
+ String name();
+
+ /**
+ * Return the properties for this catalog.
+ *
+ * @return this catalog's config properties
+ */
+ Map<String, String> properties();
+
+ /**
+ * Return all the identifiers under this namespace.
Review Comment:
nit: under a given namespace
Since this object doesn't have a specific namespace
--
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-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
[GitHub] [iceberg] danielcweeks commented on a diff in pull request #4575: Core: Add context headers to RESTCatalog
Posted by GitBox <gi...@apache.org>.
danielcweeks commented on code in PR #4575:
URL: https://github.com/apache/iceberg/pull/4575#discussion_r853249916
##########
api/src/main/java/org/apache/iceberg/catalog/SessionCatalog.java:
##########
@@ -0,0 +1,323 @@
+/*
+ * 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.catalog;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.UUID;
+import org.apache.iceberg.Schema;
+import org.apache.iceberg.Table;
+import org.apache.iceberg.exceptions.AlreadyExistsException;
+import org.apache.iceberg.exceptions.NamespaceNotEmptyException;
+import org.apache.iceberg.exceptions.NoSuchNamespaceException;
+import org.apache.iceberg.exceptions.NoSuchTableException;
+import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap;
+
+/**
+ * A Catalog API for table and namespace operations that includes session context.
+ */
+public interface SessionCatalog {
+ /**
+ * Context for a session.
+ */
+ final class SessionContext {
+ private final String sessionId;
+ private final String identity;
+ private final String credential;
Review Comment:
Java's Subject represents them as `Set<Object>` and Trino has `Map<String,String>` for various "extra" credentials
--
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-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
[GitHub] [iceberg] danielcweeks commented on a diff in pull request #4575: Core: Add context headers to RESTCatalog
Posted by GitBox <gi...@apache.org>.
danielcweeks commented on code in PR #4575:
URL: https://github.com/apache/iceberg/pull/4575#discussion_r853244316
##########
api/src/main/java/org/apache/iceberg/catalog/SessionCatalog.java:
##########
@@ -0,0 +1,323 @@
+/*
+ * 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.catalog;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.UUID;
+import org.apache.iceberg.Schema;
+import org.apache.iceberg.Table;
+import org.apache.iceberg.exceptions.AlreadyExistsException;
+import org.apache.iceberg.exceptions.NamespaceNotEmptyException;
+import org.apache.iceberg.exceptions.NoSuchNamespaceException;
+import org.apache.iceberg.exceptions.NoSuchTableException;
+import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap;
+
+/**
+ * A Catalog API for table and namespace operations that includes session context.
+ */
+public interface SessionCatalog {
+ /**
+ * Context for a session.
+ */
+ final class SessionContext {
+ private final String sessionId;
+ private final String identity;
+ private final String credential;
Review Comment:
We might want to consider making credentials a map (this is pretty common and also how Trino represents credentials).
--
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-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
[GitHub] [iceberg] jackye1995 commented on a diff in pull request #4575: Core: Add context headers to RESTCatalog
Posted by GitBox <gi...@apache.org>.
jackye1995 commented on code in PR #4575:
URL: https://github.com/apache/iceberg/pull/4575#discussion_r853347091
##########
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:
I see. If we are focusing on the consensus part, I think it is pretty aligned with the [TrinoCatalog](https://github.com/trinodb/trino/blob/master/plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/catalog/TrinoCatalog.java) interface, there is a converter needed for a Trino [ConnectorSession](https://github.com/trinodb/trino/blob/master/core/trino-spi/src/main/java/io/trino/spi/connector/ConnectorSession.java) but that is overall straightforward.
The reason I bring up this identity and credential part here is that maybe Iceberg's `SessionContext` can be an interface but not an implementation, and we have `SessionCatalog<T extends SessionContext>`, and `SessionContext` has one important method `cacheKey()` that can be used to define if 2 sessions should use the same underlying catalog, and the cache key can on the extreme end be the session ID to have 1 different catalog for each session, or be a composite of identity and credential values.
In Trino, then we can have `IcebergConnectorSession implements SessionContext` and `TrinoCatalog implements SessionCatalog<IcebergConnectorSession>` as a way to simplify the `TrinoCatalog` class.
--
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-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
[GitHub] [iceberg] rdblue commented on a diff in pull request #4575: Core: Add context headers to RESTCatalog
Posted by GitBox <gi...@apache.org>.
rdblue commented on code in PR #4575:
URL: https://github.com/apache/iceberg/pull/4575#discussion_r855434855
##########
core/src/main/java/org/apache/iceberg/catalog/BaseSessionCatalog.java:
##########
@@ -0,0 +1,170 @@
+/*
+ * 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.catalog;
+
+import com.github.benmanes.caffeine.cache.Cache;
+import com.github.benmanes.caffeine.cache.Caffeine;
+import java.io.Closeable;
+import java.io.IOException;
+import java.io.UncheckedIOException;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
+import java.util.function.Function;
+import org.apache.iceberg.Schema;
+import org.apache.iceberg.Table;
+import org.apache.iceberg.exceptions.NamespaceNotEmptyException;
+import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap;
+import org.apache.iceberg.relocated.com.google.common.collect.ImmutableSet;
+
+public abstract class BaseSessionCatalog implements SessionCatalog {
+ private final Cache<String, Catalog> catalogs = Caffeine.newBuilder()
+ .expireAfterAccess(10, TimeUnit.MINUTES)
+ .removalListener((id, catalog, cause) -> {
+ if (catalog instanceof Closeable) {
+ try {
+ ((Closeable) catalog).close();
Review Comment:
This closes the catalog, but we don't control anything about the session. We're just caching a catalog instance to use with a session. If we have to create a new one because it timed out, it should be initialized with the session details so nothing would change in the catalog's behavior.
--
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-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
[GitHub] [iceberg] rdblue commented on a diff in pull request #4575: Core: Add context headers to RESTCatalog
Posted by GitBox <gi...@apache.org>.
rdblue commented on code in PR #4575:
URL: https://github.com/apache/iceberg/pull/4575#discussion_r873229820
##########
core/src/main/java/org/apache/iceberg/catalog/BaseSessionCatalog.java:
##########
@@ -0,0 +1,170 @@
+/*
+ * 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.catalog;
+
+import com.github.benmanes.caffeine.cache.Cache;
+import com.github.benmanes.caffeine.cache.Caffeine;
+import java.io.Closeable;
+import java.io.IOException;
+import java.io.UncheckedIOException;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
+import java.util.function.Function;
+import org.apache.iceberg.Schema;
+import org.apache.iceberg.Table;
+import org.apache.iceberg.exceptions.NamespaceNotEmptyException;
+import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap;
+import org.apache.iceberg.relocated.com.google.common.collect.ImmutableSet;
+
+public abstract class BaseSessionCatalog implements SessionCatalog {
+ private final Cache<String, Catalog> catalogs = Caffeine.newBuilder()
+ .expireAfterAccess(10, TimeUnit.MINUTES)
+ .removalListener((id, catalog, cause) -> {
+ if (catalog instanceof Closeable) {
+ try {
+ ((Closeable) catalog).close();
Review Comment:
I've moved this interface and base class into its own PR, #4773.
I also removed this `close` call because it doesn't need to close. The `AsCatalog` adapter doesn't have any resources of its own. It's just a light wrapper to use a session context with the `SessionCatalog`.
--
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-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
[GitHub] [iceberg] jackye1995 commented on a diff in pull request #4575: Core: Add context headers to RESTCatalog
Posted by GitBox <gi...@apache.org>.
jackye1995 commented on code in PR #4575:
URL: https://github.com/apache/iceberg/pull/4575#discussion_r853339764
##########
api/src/main/java/org/apache/iceberg/catalog/SessionCatalog.java:
##########
@@ -0,0 +1,323 @@
+/*
+ * 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.catalog;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.UUID;
+import org.apache.iceberg.Schema;
+import org.apache.iceberg.Table;
+import org.apache.iceberg.exceptions.AlreadyExistsException;
+import org.apache.iceberg.exceptions.NamespaceNotEmptyException;
+import org.apache.iceberg.exceptions.NoSuchNamespaceException;
+import org.apache.iceberg.exceptions.NoSuchTableException;
+import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap;
+
+/**
+ * A Catalog API for table and namespace operations that includes session context.
+ */
+public interface SessionCatalog {
+ /**
+ * Context for a session.
+ */
+ final class SessionContext {
+ private final String sessionId;
+ private final String identity;
+ private final String credential;
Review Comment:
The credential is also a part of identity, for reference: https://github.com/trinodb/trino/blob/master/core/trino-spi/src/main/java/io/trino/spi/security/Identity.java
--
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-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org