From 620e9cb9c9edd91ffd8b4003c5b14d1fc9c312a2 Mon Sep 17 00:00:00 2001 From: Piotr Findeisen Date: Wed, 19 Jul 2023 13:27:38 +0200 Subject: [PATCH] Short-circuit IcebergMetadata.redirectTable when redirects not configured --- .../java/io/trino/plugin/iceberg/IcebergMetadata.java | 7 ++++++- .../io/trino/plugin/iceberg/catalog/TrinoCatalog.java | 2 +- .../plugin/iceberg/catalog/glue/TrinoGlueCatalog.java | 11 ++++------- .../plugin/iceberg/catalog/hms/TrinoHiveCatalog.java | 11 ++++------- .../plugin/iceberg/catalog/jdbc/TrinoJdbcCatalog.java | 2 +- .../iceberg/catalog/nessie/TrinoNessieCatalog.java | 2 +- .../plugin/iceberg/catalog/rest/TrinoRestCatalog.java | 2 +- 7 files changed, 18 insertions(+), 19 deletions(-) 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 7356bfc86631..540a138461fc 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 @@ -136,5 +136,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 a2e63378e892..ee06343c23e3 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 91e3f1c6fd6e..dcb9866c2f79 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; @@ -603,14 +602,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(); } @@ -628,7 +625,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 783866d227f9..93c53ca75fc5 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 e3889c119ea5..fbc56cc73419 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 3f30343e54d0..fc44482ce592 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 @@ -390,7 +390,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(); }