Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suppress ForbiddenException when listing tables in Iceberg REST #22680

Merged
merged 2 commits into from
Jul 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -75,6 +76,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;
Expand Down Expand Up @@ -207,24 +209,33 @@ public List<TableInfo> listTables(ConnectorSession session, Optional<String> nam

ImmutableList.Builder<TableInfo> 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<TableIdentifier> listTableIdentifiers(Namespace restNamespace, Supplier<List<TableIdentifier>> tableIdentifiersProvider)
{
try {
return tableIdentifiersProvider.get();
}
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);
}
return ImmutableList.of();
}

@Override
public Optional<Iterator<RelationColumnsMetadata>> streamRelationColumns(
ConnectorSession session,
Expand Down