diff --git a/plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/IcebergMetadata.java b/plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/IcebergMetadata.java index aa089b337f1b..3bc3cb118cdf 100644 --- a/plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/IcebergMetadata.java +++ b/plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/IcebergMetadata.java @@ -207,6 +207,7 @@ import static io.trino.plugin.iceberg.IcebergMetadataColumn.FILE_PATH; import static io.trino.plugin.iceberg.IcebergMetadataColumn.isMetadataColumnId; import static io.trino.plugin.iceberg.IcebergSessionProperties.getExpireSnapshotMinRetention; +import static io.trino.plugin.iceberg.IcebergSessionProperties.getHiveCatalogName; import static io.trino.plugin.iceberg.IcebergSessionProperties.getRemoveOrphanFilesMinRetention; import static io.trino.plugin.iceberg.IcebergSessionProperties.isCollectExtendedStatisticsOnWrite; import static io.trino.plugin.iceberg.IcebergSessionProperties.isExtendedStatisticsEnabled; @@ -2879,7 +2880,11 @@ public void setColumnComment(ConnectorSession session, ConnectorTableHandle tabl @Override public Optional redirectTable(ConnectorSession session, SchemaTableName tableName) { - return catalog.redirectTable(session, tableName); + Optional targetCatalogName = getHiveCatalogName(session); + if (targetCatalogName.isEmpty()) { + return Optional.empty(); + } + return catalog.redirectTable(session, tableName, targetCatalogName.get()); } private static CollectedStatistics processComputedTableStatistics(Table table, Collection computedStatistics) diff --git a/plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/catalog/TrinoCatalog.java b/plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/catalog/TrinoCatalog.java index dbc78b7a14f1..e01ff66d88f8 100644 --- a/plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/catalog/TrinoCatalog.java +++ b/plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/catalog/TrinoCatalog.java @@ -137,5 +137,5 @@ void createMaterializedView( void updateColumnComment(ConnectorSession session, SchemaTableName schemaTableName, ColumnIdentity columnIdentity, Optional comment); - Optional redirectTable(ConnectorSession session, SchemaTableName tableName); + Optional redirectTable(ConnectorSession session, SchemaTableName tableName, String hiveCatalogName); } diff --git a/plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/catalog/glue/TrinoGlueCatalog.java b/plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/catalog/glue/TrinoGlueCatalog.java index 2e737fb348c8..d773cffb72fd 100644 --- a/plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/catalog/glue/TrinoGlueCatalog.java +++ b/plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/catalog/glue/TrinoGlueCatalog.java @@ -102,7 +102,6 @@ import static io.trino.plugin.iceberg.IcebergMaterializedViewDefinition.encodeMaterializedViewData; import static io.trino.plugin.iceberg.IcebergMaterializedViewDefinition.fromConnectorMaterializedViewDefinition; import static io.trino.plugin.iceberg.IcebergSchemaProperties.LOCATION_PROPERTY; -import static io.trino.plugin.iceberg.IcebergSessionProperties.getHiveCatalogName; import static io.trino.plugin.iceberg.IcebergUtil.getIcebergTableWithMetadata; import static io.trino.plugin.iceberg.IcebergUtil.quotedTableName; import static io.trino.plugin.iceberg.IcebergUtil.validateTableCanBeDropped; @@ -1019,14 +1018,12 @@ public void renameMaterializedView(ConnectorSession session, SchemaTableName sou } @Override - public Optional redirectTable(ConnectorSession session, SchemaTableName tableName) + public Optional redirectTable(ConnectorSession session, SchemaTableName tableName, String hiveCatalogName) { requireNonNull(session, "session is null"); requireNonNull(tableName, "tableName is null"); - Optional targetCatalogName = getHiveCatalogName(session); - if (targetCatalogName.isEmpty()) { - return Optional.empty(); - } + requireNonNull(hiveCatalogName, "hiveCatalogName is null"); + if (isHiveSystemSchema(tableName.getSchemaName())) { return Optional.empty(); } @@ -1044,7 +1041,7 @@ public Optional redirectTable(ConnectorSession session, } if (!isIcebergTable(getTableParameters(table.get()))) { // After redirecting, use the original table name, with "$partitions" and similar suffixes - return targetCatalogName.map(catalog -> new CatalogSchemaTableName(catalog, tableName)); + return Optional.of(new CatalogSchemaTableName(hiveCatalogName, tableName)); } return Optional.empty(); } diff --git a/plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/catalog/hms/TrinoHiveCatalog.java b/plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/catalog/hms/TrinoHiveCatalog.java index 4aedbdc94869..9c2efec1a1cc 100644 --- a/plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/catalog/hms/TrinoHiveCatalog.java +++ b/plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/catalog/hms/TrinoHiveCatalog.java @@ -80,7 +80,6 @@ import static io.trino.plugin.iceberg.IcebergMaterializedViewDefinition.encodeMaterializedViewData; import static io.trino.plugin.iceberg.IcebergMaterializedViewDefinition.fromConnectorMaterializedViewDefinition; import static io.trino.plugin.iceberg.IcebergSchemaProperties.LOCATION_PROPERTY; -import static io.trino.plugin.iceberg.IcebergSessionProperties.getHiveCatalogName; import static io.trino.plugin.iceberg.IcebergUtil.getIcebergTableWithMetadata; import static io.trino.plugin.iceberg.IcebergUtil.loadIcebergTable; import static io.trino.plugin.iceberg.IcebergUtil.validateTableCanBeDropped; @@ -605,14 +604,12 @@ private List listNamespaces(ConnectorSession session, Optional n } @Override - public Optional redirectTable(ConnectorSession session, SchemaTableName tableName) + public Optional redirectTable(ConnectorSession session, SchemaTableName tableName, String hiveCatalogName) { requireNonNull(session, "session is null"); requireNonNull(tableName, "tableName is null"); - Optional targetCatalogName = getHiveCatalogName(session); - if (targetCatalogName.isEmpty()) { - return Optional.empty(); - } + requireNonNull(hiveCatalogName, "hiveCatalogName is null"); + if (isHiveSystemSchema(tableName.getSchemaName())) { return Optional.empty(); } @@ -630,7 +627,7 @@ public Optional redirectTable(ConnectorSession session, } if (!isIcebergTable(table.get())) { // After redirecting, use the original table name, with "$partitions" and similar suffixes - return targetCatalogName.map(catalog -> new CatalogSchemaTableName(catalog, tableName)); + return Optional.of(new CatalogSchemaTableName(hiveCatalogName, tableName)); } return Optional.empty(); } diff --git a/plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/catalog/jdbc/TrinoJdbcCatalog.java b/plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/catalog/jdbc/TrinoJdbcCatalog.java index c8f5b5d2aedd..543e7f7a4606 100644 --- a/plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/catalog/jdbc/TrinoJdbcCatalog.java +++ b/plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/catalog/jdbc/TrinoJdbcCatalog.java @@ -380,7 +380,7 @@ public void renameMaterializedView(ConnectorSession session, SchemaTableName sou } @Override - public Optional redirectTable(ConnectorSession session, SchemaTableName tableName) + public Optional redirectTable(ConnectorSession session, SchemaTableName tableName, String hiveCatalogName) { return Optional.empty(); } diff --git a/plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/catalog/nessie/TrinoNessieCatalog.java b/plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/catalog/nessie/TrinoNessieCatalog.java index 72ee10a29286..e8c783660d9e 100644 --- a/plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/catalog/nessie/TrinoNessieCatalog.java +++ b/plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/catalog/nessie/TrinoNessieCatalog.java @@ -349,7 +349,7 @@ public void renameMaterializedView(ConnectorSession session, SchemaTableName sou } @Override - public Optional redirectTable(ConnectorSession session, SchemaTableName tableName) + public Optional redirectTable(ConnectorSession session, SchemaTableName tableName, String hiveCatalogName) { return Optional.empty(); } 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 ab7846730244..4b226a4856c8 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 @@ -391,7 +391,7 @@ public void updateColumnComment(ConnectorSession session, SchemaTableName schema } @Override - public Optional redirectTable(ConnectorSession session, SchemaTableName tableName) + public Optional redirectTable(ConnectorSession session, SchemaTableName tableName, String hiveCatalogName) { return Optional.empty(); }