diff --git a/plugin/trino-hive/src/main/java/io/trino/plugin/hive/DefaultHiveTableRedirectionsProvider.java b/plugin/trino-hive/src/main/java/io/trino/plugin/hive/DefaultHiveTableRedirectionsProvider.java deleted file mode 100644 index 23a4913f3c21..000000000000 --- a/plugin/trino-hive/src/main/java/io/trino/plugin/hive/DefaultHiveTableRedirectionsProvider.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.trino.plugin.hive; - -import io.trino.plugin.hive.metastore.Table; -import io.trino.spi.connector.CatalogSchemaTableName; -import io.trino.spi.connector.ConnectorSession; - -import java.util.Optional; - -import static io.trino.plugin.hive.HiveSessionProperties.getDeltaLakeCatalogName; -import static io.trino.plugin.hive.HiveSessionProperties.getIcebergCatalogName; -import static io.trino.plugin.hive.util.HiveUtil.isDeltaLakeTable; -import static io.trino.plugin.hive.util.HiveUtil.isIcebergTable; - -public class DefaultHiveTableRedirectionsProvider - implements HiveTableRedirectionsProvider -{ - @Override - public Optional redirectTable(ConnectorSession session, Table table) - { - return redirectTableToIceberg(session, table) - .or(() -> redirectTableToDeltaLake(session, table)); - } - - private Optional redirectTableToIceberg(ConnectorSession session, Table table) - { - Optional targetCatalogName = getIcebergCatalogName(session); - if (targetCatalogName.isEmpty()) { - return Optional.empty(); - } - if (isIcebergTable(table)) { - return targetCatalogName.map(catalog -> new CatalogSchemaTableName(catalog, table.getSchemaTableName())); - } - return Optional.empty(); - } - - private Optional redirectTableToDeltaLake(ConnectorSession session, Table table) - { - Optional targetCatalogName = getDeltaLakeCatalogName(session); - if (targetCatalogName.isEmpty()) { - return Optional.empty(); - } - if (isDeltaLakeTable(table)) { - return targetCatalogName.map(catalog -> new CatalogSchemaTableName(catalog, table.getSchemaTableName())); - } - return Optional.empty(); - } -} diff --git a/plugin/trino-hive/src/main/java/io/trino/plugin/hive/HiveMetadata.java b/plugin/trino-hive/src/main/java/io/trino/plugin/hive/HiveMetadata.java index 537c13d76b52..b5c90795c572 100644 --- a/plugin/trino-hive/src/main/java/io/trino/plugin/hive/HiveMetadata.java +++ b/plugin/trino-hive/src/main/java/io/trino/plugin/hive/HiveMetadata.java @@ -185,7 +185,9 @@ import static io.trino.plugin.hive.HivePartitionManager.extractPartitionValues; import static io.trino.plugin.hive.HiveSessionProperties.NON_TRANSACTIONAL_OPTIMIZE_ENABLED; import static io.trino.plugin.hive.HiveSessionProperties.getCompressionCodec; +import static io.trino.plugin.hive.HiveSessionProperties.getDeltaLakeCatalogName; import static io.trino.plugin.hive.HiveSessionProperties.getHiveStorageFormat; +import static io.trino.plugin.hive.HiveSessionProperties.getIcebergCatalogName; import static io.trino.plugin.hive.HiveSessionProperties.getInsertExistingPartitionsBehavior; import static io.trino.plugin.hive.HiveSessionProperties.getQueryPartitionFilterRequiredSchemas; import static io.trino.plugin.hive.HiveSessionProperties.getTimestampPrecision; @@ -364,7 +366,6 @@ public class HiveMetadata private final Set systemTableProviders; private final HiveMaterializedViewMetadata hiveMaterializedViewMetadata; private final AccessControlMetadata accessControlMetadata; - private final HiveTableRedirectionsProvider tableRedirectionsProvider; private final DirectoryLister directoryLister; public HiveMetadata( @@ -387,7 +388,6 @@ public HiveMetadata( Set systemTableProviders, HiveMaterializedViewMetadata hiveMaterializedViewMetadata, AccessControlMetadata accessControlMetadata, - HiveTableRedirectionsProvider tableRedirectionsProvider, DirectoryLister directoryLister) { this.catalogName = requireNonNull(catalogName, "catalogName is null"); @@ -409,7 +409,6 @@ public HiveMetadata( this.systemTableProviders = requireNonNull(systemTableProviders, "systemTableProviders is null"); this.hiveMaterializedViewMetadata = requireNonNull(hiveMaterializedViewMetadata, "hiveMaterializedViewMetadata is null"); this.accessControlMetadata = requireNonNull(accessControlMetadata, "accessControlMetadata is null"); - this.tableRedirectionsProvider = requireNonNull(tableRedirectionsProvider, "tableRedirectionsProvider is null"); this.directoryLister = requireNonNull(directoryLister, "directoryLister is null"); } @@ -3534,7 +3533,8 @@ public Optional redirectTable(ConnectorSession session, return Optional.empty(); } - Optional catalogSchemaTableName = tableRedirectionsProvider.redirectTable(session, table.get()); + Optional catalogSchemaTableName = redirectTableToIceberg(session, table.get()) + .or(() -> redirectTableToDeltaLake(session, table.get())); // stitch back the suffix we cut off. return catalogSchemaTableName.map(name -> new CatalogSchemaTableName( @@ -3544,6 +3544,30 @@ public Optional redirectTable(ConnectorSession session, name.getSchemaTableName().getTableName() + tableNameSplit.getSuffix().orElse("")))); } + private Optional redirectTableToIceberg(ConnectorSession session, Table table) + { + Optional targetCatalogName = getIcebergCatalogName(session); + if (targetCatalogName.isEmpty()) { + return Optional.empty(); + } + if (isIcebergTable(table)) { + return targetCatalogName.map(catalog -> new CatalogSchemaTableName(catalog, table.getSchemaTableName())); + } + return Optional.empty(); + } + + private Optional redirectTableToDeltaLake(ConnectorSession session, Table table) + { + Optional targetCatalogName = getDeltaLakeCatalogName(session); + if (targetCatalogName.isEmpty()) { + return Optional.empty(); + } + if (isDeltaLakeTable(table)) { + return targetCatalogName.map(catalog -> new CatalogSchemaTableName(catalog, table.getSchemaTableName())); + } + return Optional.empty(); + } + private static TableNameSplitResult splitTableName(String tableName) { int metadataMarkerIndex = tableName.lastIndexOf('$'); diff --git a/plugin/trino-hive/src/main/java/io/trino/plugin/hive/HiveMetadataFactory.java b/plugin/trino-hive/src/main/java/io/trino/plugin/hive/HiveMetadataFactory.java index da120c183a8a..17f2bb7353c4 100644 --- a/plugin/trino-hive/src/main/java/io/trino/plugin/hive/HiveMetadataFactory.java +++ b/plugin/trino-hive/src/main/java/io/trino/plugin/hive/HiveMetadataFactory.java @@ -68,7 +68,6 @@ public class HiveMetadataFactory private final HiveMaterializedViewMetadataFactory hiveMaterializedViewMetadataFactory; private final AccessControlMetadataFactory accessControlMetadataFactory; private final Optional hiveTransactionHeartbeatInterval; - private final HiveTableRedirectionsProvider tableRedirectionsProvider; private final ScheduledExecutorService heartbeatService; private final DirectoryLister directoryLister; private final long perTransactionFileStatusCacheMaximumSize; @@ -92,7 +91,6 @@ public HiveMetadataFactory( Set systemTableProviders, HiveMaterializedViewMetadataFactory hiveMaterializedViewMetadataFactory, AccessControlMetadataFactory accessControlMetadataFactory, - HiveTableRedirectionsProvider tableRedirectionsProvider, DirectoryLister directoryLister) { this( @@ -123,7 +121,6 @@ public HiveMetadataFactory( systemTableProviders, hiveMaterializedViewMetadataFactory, accessControlMetadataFactory, - tableRedirectionsProvider, directoryLister, hiveConfig.getPerTransactionFileStatusCacheMaximumSize()); } @@ -156,7 +153,6 @@ public HiveMetadataFactory( Set systemTableProviders, HiveMaterializedViewMetadataFactory hiveMaterializedViewMetadataFactory, AccessControlMetadataFactory accessControlMetadataFactory, - HiveTableRedirectionsProvider tableRedirectionsProvider, DirectoryLister directoryLister, long perTransactionFileStatusCacheMaximumSize) { @@ -182,7 +178,6 @@ public HiveMetadataFactory( this.systemTableProviders = requireNonNull(systemTableProviders, "systemTableProviders is null"); this.hiveMaterializedViewMetadataFactory = requireNonNull(hiveMaterializedViewMetadataFactory, "hiveMaterializedViewMetadataFactory is null"); this.accessControlMetadataFactory = requireNonNull(accessControlMetadataFactory, "accessControlMetadataFactory is null"); - this.tableRedirectionsProvider = requireNonNull(tableRedirectionsProvider, "tableRedirectionsProvider is null"); this.hiveTransactionHeartbeatInterval = requireNonNull(hiveTransactionHeartbeatInterval, "hiveTransactionHeartbeatInterval is null"); renameExecution = new BoundedExecutor(executorService, maxConcurrentFileRenames); @@ -240,7 +235,6 @@ public TransactionalMetadata create(ConnectorIdentity identity, boolean autoComm systemTableProviders, hiveMaterializedViewMetadataFactory.create(hiveMetastoreClosure), accessControlMetadataFactory.create(metastore), - tableRedirectionsProvider, directoryLister); } } diff --git a/plugin/trino-hive/src/main/java/io/trino/plugin/hive/HiveModule.java b/plugin/trino-hive/src/main/java/io/trino/plugin/hive/HiveModule.java index 3680832a1234..6f8868ef99b4 100644 --- a/plugin/trino-hive/src/main/java/io/trino/plugin/hive/HiveModule.java +++ b/plugin/trino-hive/src/main/java/io/trino/plugin/hive/HiveModule.java @@ -88,8 +88,6 @@ public void configure(Binder binder) .setDefault().to(DefaultHiveMaterializedViewMetadataFactory.class).in(Scopes.SINGLETON); newOptionalBinder(binder, TransactionalMetadataFactory.class) .setDefault().to(HiveMetadataFactory.class).in(Scopes.SINGLETON); - newOptionalBinder(binder, HiveTableRedirectionsProvider.class) - .setDefault().to(DefaultHiveTableRedirectionsProvider.class); binder.bind(HiveTransactionManager.class).in(Scopes.SINGLETON); binder.bind(ConnectorSplitManager.class).to(HiveSplitManager.class).in(Scopes.SINGLETON); newExporter(binder).export(ConnectorSplitManager.class).as(generator -> generator.generatedNameOf(HiveSplitManager.class)); diff --git a/plugin/trino-hive/src/main/java/io/trino/plugin/hive/HiveTableRedirectionsProvider.java b/plugin/trino-hive/src/main/java/io/trino/plugin/hive/HiveTableRedirectionsProvider.java deleted file mode 100644 index 85446c71429e..000000000000 --- a/plugin/trino-hive/src/main/java/io/trino/plugin/hive/HiveTableRedirectionsProvider.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.trino.plugin.hive; - -import io.trino.plugin.hive.metastore.Table; -import io.trino.spi.connector.CatalogSchemaTableName; -import io.trino.spi.connector.ConnectorSession; - -import java.util.Optional; - -public interface HiveTableRedirectionsProvider -{ - HiveTableRedirectionsProvider NO_REDIRECTIONS = (session, table) -> Optional.empty(); - - Optional redirectTable(ConnectorSession session, Table table); -} diff --git a/plugin/trino-hive/src/test/java/io/trino/plugin/hive/AbstractTestHive.java b/plugin/trino-hive/src/test/java/io/trino/plugin/hive/AbstractTestHive.java index e7cb993ff37f..4b38a65dab5f 100644 --- a/plugin/trino-hive/src/test/java/io/trino/plugin/hive/AbstractTestHive.java +++ b/plugin/trino-hive/src/test/java/io/trino/plugin/hive/AbstractTestHive.java @@ -233,7 +233,6 @@ import static io.trino.plugin.hive.HiveTableProperties.SORTED_BY_PROPERTY; import static io.trino.plugin.hive.HiveTableProperties.STORAGE_FORMAT_PROPERTY; import static io.trino.plugin.hive.HiveTableProperties.TRANSACTIONAL; -import static io.trino.plugin.hive.HiveTableRedirectionsProvider.NO_REDIRECTIONS; import static io.trino.plugin.hive.HiveTestUtils.PAGE_SORTER; import static io.trino.plugin.hive.HiveTestUtils.SESSION; import static io.trino.plugin.hive.HiveTestUtils.arrayType; @@ -871,7 +870,6 @@ public Optional getMaterializedView(Connect } }, SqlStandardAccessControlMetadata::new, - NO_REDIRECTIONS, countingDirectoryLister, 1000); transactionManager = new HiveTransactionManager(metadataFactory); diff --git a/plugin/trino-hive/src/test/java/io/trino/plugin/hive/AbstractTestHiveFileSystem.java b/plugin/trino-hive/src/test/java/io/trino/plugin/hive/AbstractTestHiveFileSystem.java index 39dbd8fe07ac..baaa382e5922 100644 --- a/plugin/trino-hive/src/test/java/io/trino/plugin/hive/AbstractTestHiveFileSystem.java +++ b/plugin/trino-hive/src/test/java/io/trino/plugin/hive/AbstractTestHiveFileSystem.java @@ -95,7 +95,6 @@ import static io.trino.plugin.hive.AbstractTestHive.filterNonHiddenColumnMetadata; import static io.trino.plugin.hive.AbstractTestHive.getAllSplits; import static io.trino.plugin.hive.AbstractTestHive.getSplits; -import static io.trino.plugin.hive.HiveTableRedirectionsProvider.NO_REDIRECTIONS; import static io.trino.plugin.hive.HiveTestUtils.PAGE_SORTER; import static io.trino.plugin.hive.HiveTestUtils.getDefaultHiveFileWriterFactories; import static io.trino.plugin.hive.HiveTestUtils.getDefaultHivePageSourceFactories; @@ -221,7 +220,6 @@ protected void setup(String host, int port, String databaseName, boolean s3Selec new PropertiesSystemTableProvider()), new DefaultHiveMaterializedViewMetadataFactory(), SqlStandardAccessControlMetadata::new, - NO_REDIRECTIONS, new FileSystemDirectoryLister()); transactionManager = new HiveTransactionManager(metadataFactory); splitManager = new HiveSplitManager(