From 79a29472b6b62ca9f9214dd4fb3d8e1ce4eb722c Mon Sep 17 00:00:00 2001 From: Yuya Ebihara Date: Tue, 16 Jul 2024 18:58:19 +0900 Subject: [PATCH 1/2] Extract method in TrinoRestCatalog --- .../catalog/rest/TrinoRestCatalog.java | 35 +++++++++++-------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/catalog/rest/TrinoRestCatalog.java b/plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/catalog/rest/TrinoRestCatalog.java index ca1c18135e71..1903fd6a3212 100644 --- a/plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/catalog/rest/TrinoRestCatalog.java +++ b/plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/catalog/rest/TrinoRestCatalog.java @@ -75,6 +75,7 @@ import java.util.Optional; import java.util.Set; import java.util.function.Predicate; +import java.util.function.Supplier; import java.util.function.UnaryOperator; import static com.google.common.base.Preconditions.checkArgument; @@ -207,24 +208,30 @@ public List listTables(ConnectorSession session, Optional nam ImmutableList.Builder tables = ImmutableList.builder(); for (Namespace restNamespace : namespaces) { - try { - restSessionCatalog.listTables(sessionContext, restNamespace).stream() - .map(id -> new TableInfo(SchemaTableName.schemaTableName(id.namespace().toString(), id.name()), TableInfo.ExtendedRelationType.TABLE)) - .forEach(tables::add); - restSessionCatalog.listViews(sessionContext, restNamespace).stream() - .map(id -> new TableInfo(SchemaTableName.schemaTableName(id.namespace().toString(), id.name()), TableInfo.ExtendedRelationType.OTHER_VIEW)) - .forEach(tables::add); - } - catch (NoSuchNamespaceException e) { - // Namespace may have been deleted during listing - } - catch (RESTException e) { - throw new TrinoException(ICEBERG_CATALOG_ERROR, format("Failed to list tables from namespace: %s", restNamespace), e); - } + listTableIdentifiers(restNamespace, () -> restSessionCatalog.listTables(sessionContext, restNamespace)).stream() + .map(id -> new TableInfo(SchemaTableName.schemaTableName(id.namespace().toString(), id.name()), TableInfo.ExtendedRelationType.TABLE)) + .forEach(tables::add); + listTableIdentifiers(restNamespace, () -> restSessionCatalog.listViews(sessionContext, restNamespace)).stream() + .map(id -> new TableInfo(SchemaTableName.schemaTableName(id.namespace().toString(), id.name()), TableInfo.ExtendedRelationType.OTHER_VIEW)) + .forEach(tables::add); } return tables.build(); } + private static List listTableIdentifiers(Namespace restNamespace, Supplier> tableIdentifiersProvider) + { + try { + return tableIdentifiersProvider.get(); + } + catch (NoSuchNamespaceException e) { + // Namespace may have been deleted during listing + } + catch (RESTException e) { + throw new TrinoException(ICEBERG_CATALOG_ERROR, format("Failed to list tables from namespace: %s", restNamespace), e); + } + return ImmutableList.of(); + } + @Override public Optional> streamRelationColumns( ConnectorSession session, From 7365ee9e533eb7be698e7eb07aee89c1189cbd6a Mon Sep 17 00:00:00 2001 From: Yuya Ebihara Date: Tue, 16 Jul 2024 18:59:45 +0900 Subject: [PATCH 2/2] Suppress ForbiddenException when listing tables in Iceberg REST --- .../trino/plugin/iceberg/catalog/rest/TrinoRestCatalog.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/catalog/rest/TrinoRestCatalog.java b/plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/catalog/rest/TrinoRestCatalog.java index 1903fd6a3212..4ad77ea5849f 100644 --- a/plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/catalog/rest/TrinoRestCatalog.java +++ b/plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/catalog/rest/TrinoRestCatalog.java @@ -54,6 +54,7 @@ import org.apache.iceberg.catalog.SessionCatalog; import org.apache.iceberg.catalog.SessionCatalog.SessionContext; import org.apache.iceberg.catalog.TableIdentifier; +import org.apache.iceberg.exceptions.ForbiddenException; import org.apache.iceberg.exceptions.NoSuchNamespaceException; import org.apache.iceberg.exceptions.NoSuchTableException; import org.apache.iceberg.exceptions.NoSuchViewException; @@ -226,6 +227,9 @@ private static List listTableIdentifiers(Namespace restNamespac catch (NoSuchNamespaceException e) { // Namespace may have been deleted during listing } + catch (ForbiddenException e) { + log.debug(e, "Failed to list tables from %s namespace because of insufficient permissions", restNamespace); + } catch (RESTException e) { throw new TrinoException(ICEBERG_CATALOG_ERROR, format("Failed to list tables from namespace: %s", restNamespace), e); }