From 611b46811eb3810087e54c352f3281189ab438f6 Mon Sep 17 00:00:00 2001 From: Pratham Desai Date: Wed, 28 Jul 2021 23:23:40 -0400 Subject: [PATCH] Clarify comments around listing redirected tables --- .../src/main/java/io/trino/metadata/MetadataListing.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/core/trino-main/src/main/java/io/trino/metadata/MetadataListing.java b/core/trino-main/src/main/java/io/trino/metadata/MetadataListing.java index 57804742f106..a4851aa5b271 100644 --- a/core/trino-main/src/main/java/io/trino/metadata/MetadataListing.java +++ b/core/trino-main/src/main/java/io/trino/metadata/MetadataListing.java @@ -98,6 +98,10 @@ public static Set listTables(Session session, Metadata metadata Set tableNames = metadata.listTables(session, prefix).stream() .map(QualifiedObjectName::asSchemaTableName) .collect(toImmutableSet()); + + // Table listing operation only involves getting table names, but not any metadata. So redirected tables are not + // handled any differently. The target table or catalog are not involved. Thus the following filter is only called + // for the source catalog on source table names. return accessControl.filterTables(session.toSecurityContext(), prefix.getCatalogName(), tableNames); } @@ -185,7 +189,8 @@ public static Map> listTableColumns(Sessio boolean redirectionSucceeded = false; try { - // Handle redirection before filterColumns check + // For redirected tables, column listing requires special handling, because the column metadata is unavailable + // at the source table, and needs to be fetched from the target table. RedirectionAwareTableHandle redirection = metadata.getRedirectionAwareTableHandle(session, originalTableName); targetTableName = redirection.getRedirectedTableName(); @@ -213,7 +218,7 @@ public static Map> listTableColumns(Sessio Set allowedColumns = accessControl.filterColumns( session.toSecurityContext(), - // Use redirected table name for applying column filters + // Use redirected table name for applying column filters, since the source does not know the column metadata targetTableName.orElse(originalTableName).asCatalogSchemaTableName(), columns.stream() .map(ColumnMetadata::getName)