diff --git a/plugin/trino-delta-lake/src/main/java/io/trino/plugin/deltalake/AllowDeltaLakeManagedTableRename.java b/plugin/trino-delta-lake/src/main/java/io/trino/plugin/deltalake/AllowDeltaLakeManagedTableRename.java new file mode 100644 index 000000000000..46d3528d4545 --- /dev/null +++ b/plugin/trino-delta-lake/src/main/java/io/trino/plugin/deltalake/AllowDeltaLakeManagedTableRename.java @@ -0,0 +1,29 @@ +/* + * 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.deltalake; + +import javax.inject.Qualifier; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +@Retention(RUNTIME) +@Target({FIELD, PARAMETER, METHOD}) +@Qualifier +public @interface AllowDeltaLakeManagedTableRename {} diff --git a/plugin/trino-delta-lake/src/main/java/io/trino/plugin/deltalake/DeltaLakeMetadata.java b/plugin/trino-delta-lake/src/main/java/io/trino/plugin/deltalake/DeltaLakeMetadata.java index 04792d1dfc5a..e0d32af040fe 100644 --- a/plugin/trino-delta-lake/src/main/java/io/trino/plugin/deltalake/DeltaLakeMetadata.java +++ b/plugin/trino-delta-lake/src/main/java/io/trino/plugin/deltalake/DeltaLakeMetadata.java @@ -284,7 +284,7 @@ public class DeltaLakeMetadata private final ExtendedStatisticsAccess statisticsAccess; private final boolean deleteSchemaLocationsFallback; private final boolean useUniqueTableLocation; - private final String metastoreType; + private final boolean allowManagedTableRename; public DeltaLakeMetadata( DeltaLakeMetastore metastore, @@ -305,7 +305,7 @@ public DeltaLakeMetadata( DeltaLakeRedirectionsProvider deltaLakeRedirectionsProvider, ExtendedStatisticsAccess statisticsAccess, boolean useUniqueTableLocation, - String metastoreType) + boolean allowManagedTableRename) { this.metastore = requireNonNull(metastore, "metastore is null"); this.fileSystemFactory = requireNonNull(fileSystemFactory, "fileSystemFactory is null"); @@ -326,7 +326,7 @@ public DeltaLakeMetadata( this.statisticsAccess = requireNonNull(statisticsAccess, "statisticsAccess is null"); this.deleteSchemaLocationsFallback = deleteSchemaLocationsFallback; this.useUniqueTableLocation = useUniqueTableLocation; - this.metastoreType = requireNonNull(metastoreType, "metastoreType is null"); + this.allowManagedTableRename = allowManagedTableRename; } @Override @@ -1984,9 +1984,8 @@ public void renameTable(ConnectorSession session, ConnectorTableHandle tableHand DeltaLakeTableHandle handle = (DeltaLakeTableHandle) tableHandle; Table table = metastore.getTable(handle.getSchemaName(), handle.getTableName()) .orElseThrow(() -> new TableNotFoundException(handle.getSchemaTableName())); - if (table.getTableType().equals(MANAGED_TABLE.name()) && - !(metastoreType.equalsIgnoreCase("glue") || metastoreType.equalsIgnoreCase("file"))) { - throw new TrinoException(NOT_SUPPORTED, format("Renaming managed tables is not supported for %s metastore", metastoreType)); + if (table.getTableType().equals(MANAGED_TABLE.name()) && !allowManagedTableRename) { + throw new TrinoException(NOT_SUPPORTED, "Renaming managed tables is not allowed with current metastore configuration"); } metastore.renameTable(session, handle.getSchemaTableName(), newTableName); } diff --git a/plugin/trino-delta-lake/src/main/java/io/trino/plugin/deltalake/DeltaLakeMetadataFactory.java b/plugin/trino-delta-lake/src/main/java/io/trino/plugin/deltalake/DeltaLakeMetadataFactory.java index 4c0a999e1965..9209c45f9756 100644 --- a/plugin/trino-delta-lake/src/main/java/io/trino/plugin/deltalake/DeltaLakeMetadataFactory.java +++ b/plugin/trino-delta-lake/src/main/java/io/trino/plugin/deltalake/DeltaLakeMetadataFactory.java @@ -22,7 +22,6 @@ import io.trino.plugin.deltalake.transactionlog.checkpoint.CheckpointWriterManager; import io.trino.plugin.deltalake.transactionlog.writer.TransactionLogWriterFactory; import io.trino.plugin.hive.metastore.HiveMetastoreFactory; -import io.trino.plugin.hive.metastore.MetastoreTypeConfig; import io.trino.plugin.hive.metastore.cache.CachingHiveMetastore; import io.trino.spi.NodeManager; import io.trino.spi.security.ConnectorIdentity; @@ -58,7 +57,7 @@ public class DeltaLakeMetadataFactory private final boolean deleteSchemaLocationsFallback; private final boolean useUniqueTableLocation; - private final String metastoreType; + private final boolean allowManagedTableRename; @Inject public DeltaLakeMetadataFactory( @@ -76,7 +75,7 @@ public DeltaLakeMetadataFactory( CheckpointWriterManager checkpointWriterManager, DeltaLakeRedirectionsProvider deltaLakeRedirectionsProvider, CachingExtendedStatisticsAccess statisticsAccess, - MetastoreTypeConfig metastoreTypeConfig) + @AllowDeltaLakeManagedTableRename boolean allowManagedTableRename) { this.hiveMetastoreFactory = requireNonNull(hiveMetastoreFactory, "hiveMetastore is null"); this.fileSystemFactory = requireNonNull(fileSystemFactory, "fileSystemFactory is null"); @@ -99,8 +98,7 @@ public DeltaLakeMetadataFactory( this.perTransactionMetastoreCacheMaximumSize = deltaLakeConfig.getPerTransactionMetastoreCacheMaximumSize(); this.deleteSchemaLocationsFallback = deltaLakeConfig.isDeleteSchemaLocationsFallback(); this.useUniqueTableLocation = deltaLakeConfig.isUniqueTableLocation(); - requireNonNull(metastoreTypeConfig, "metastoreTypeConfig is null"); - this.metastoreType = requireNonNull(metastoreTypeConfig.getMetastoreType(), "metastoreType is null"); + this.allowManagedTableRename = allowManagedTableRename; } public DeltaLakeMetadata create(ConnectorIdentity identity) @@ -134,6 +132,6 @@ public DeltaLakeMetadata create(ConnectorIdentity identity) deltaLakeRedirectionsProvider, statisticsAccess, useUniqueTableLocation, - metastoreType); + allowManagedTableRename); } } diff --git a/plugin/trino-delta-lake/src/main/java/io/trino/plugin/deltalake/metastore/file/DeltaLakeFileMetastoreModule.java b/plugin/trino-delta-lake/src/main/java/io/trino/plugin/deltalake/metastore/file/DeltaLakeFileMetastoreModule.java index 225b8b578435..8c540afa471c 100644 --- a/plugin/trino-delta-lake/src/main/java/io/trino/plugin/deltalake/metastore/file/DeltaLakeFileMetastoreModule.java +++ b/plugin/trino-delta-lake/src/main/java/io/trino/plugin/deltalake/metastore/file/DeltaLakeFileMetastoreModule.java @@ -14,7 +14,9 @@ package io.trino.plugin.deltalake.metastore.file; import com.google.inject.Binder; +import com.google.inject.Key; import io.airlift.configuration.AbstractConfigurationAwareModule; +import io.trino.plugin.deltalake.AllowDeltaLakeManagedTableRename; import io.trino.plugin.hive.metastore.file.FileMetastoreModule; public class DeltaLakeFileMetastoreModule @@ -24,5 +26,6 @@ public class DeltaLakeFileMetastoreModule protected void setup(Binder binder) { install(new FileMetastoreModule()); + binder.bind(Key.get(boolean.class, AllowDeltaLakeManagedTableRename.class)).toInstance(true); } } diff --git a/plugin/trino-delta-lake/src/main/java/io/trino/plugin/deltalake/metastore/glue/DeltaLakeGlueMetastoreModule.java b/plugin/trino-delta-lake/src/main/java/io/trino/plugin/deltalake/metastore/glue/DeltaLakeGlueMetastoreModule.java index 6dbd56d63fb3..fa400129eea6 100644 --- a/plugin/trino-delta-lake/src/main/java/io/trino/plugin/deltalake/metastore/glue/DeltaLakeGlueMetastoreModule.java +++ b/plugin/trino-delta-lake/src/main/java/io/trino/plugin/deltalake/metastore/glue/DeltaLakeGlueMetastoreModule.java @@ -18,6 +18,7 @@ import com.google.inject.Key; import com.google.inject.TypeLiteral; import io.airlift.configuration.AbstractConfigurationAwareModule; +import io.trino.plugin.deltalake.AllowDeltaLakeManagedTableRename; import io.trino.plugin.hive.metastore.glue.ForGlueHiveMetastore; import io.trino.plugin.hive.metastore.glue.GlueMetastoreModule; @@ -38,5 +39,6 @@ protected void setup(Binder binder) .setBinding().toProvider(DeltaLakeGlueMetastoreTableFilterProvider.class); install(new GlueMetastoreModule()); + binder.bind(Key.get(boolean.class, AllowDeltaLakeManagedTableRename.class)).toInstance(true); } } diff --git a/plugin/trino-delta-lake/src/main/java/io/trino/plugin/deltalake/metastore/thrift/DeltaLakeThriftMetastoreModule.java b/plugin/trino-delta-lake/src/main/java/io/trino/plugin/deltalake/metastore/thrift/DeltaLakeThriftMetastoreModule.java index dd967be1d780..e9954d6d7c8d 100644 --- a/plugin/trino-delta-lake/src/main/java/io/trino/plugin/deltalake/metastore/thrift/DeltaLakeThriftMetastoreModule.java +++ b/plugin/trino-delta-lake/src/main/java/io/trino/plugin/deltalake/metastore/thrift/DeltaLakeThriftMetastoreModule.java @@ -14,7 +14,9 @@ package io.trino.plugin.deltalake.metastore.thrift; import com.google.inject.Binder; +import com.google.inject.Key; import io.airlift.configuration.AbstractConfigurationAwareModule; +import io.trino.plugin.deltalake.AllowDeltaLakeManagedTableRename; import io.trino.plugin.hive.metastore.thrift.ThriftMetastoreModule; public class DeltaLakeThriftMetastoreModule @@ -24,5 +26,6 @@ public class DeltaLakeThriftMetastoreModule protected void setup(Binder binder) { install(new ThriftMetastoreModule()); + binder.bind(Key.get(boolean.class, AllowDeltaLakeManagedTableRename.class)).toInstance(false); } } diff --git a/plugin/trino-delta-lake/src/test/java/io/trino/plugin/deltalake/BaseDeltaLakeConnectorSmokeTest.java b/plugin/trino-delta-lake/src/test/java/io/trino/plugin/deltalake/BaseDeltaLakeConnectorSmokeTest.java index 99d8addc7fdd..2e7433f9f2b5 100644 --- a/plugin/trino-delta-lake/src/test/java/io/trino/plugin/deltalake/BaseDeltaLakeConnectorSmokeTest.java +++ b/plugin/trino-delta-lake/src/test/java/io/trino/plugin/deltalake/BaseDeltaLakeConnectorSmokeTest.java @@ -632,7 +632,7 @@ private void validatePath(String schemaLocation, String schemaName, String table public void testRenameTable() { assertThatThrownBy(super::testRenameTable) - .hasMessage("Renaming managed tables is not supported for thrift metastore") + .hasMessage("Renaming managed tables is not allowed with current metastore configuration") .hasStackTraceContaining("SQL: ALTER TABLE test_rename_"); } @@ -668,7 +668,7 @@ public void testRenameExternalTable() public void testRenameTableAcrossSchemas() { assertThatThrownBy(super::testRenameTableAcrossSchemas) - .hasMessage("Renaming managed tables is not supported for thrift metastore") + .hasMessage("Renaming managed tables is not allowed with current metastore configuration") .hasStackTraceContaining("SQL: ALTER TABLE test_rename_"); } diff --git a/plugin/trino-delta-lake/src/test/java/io/trino/plugin/deltalake/BaseDeltaLakeMinioConnectorTest.java b/plugin/trino-delta-lake/src/test/java/io/trino/plugin/deltalake/BaseDeltaLakeMinioConnectorTest.java index b9986c516464..b18c5148abcf 100644 --- a/plugin/trino-delta-lake/src/test/java/io/trino/plugin/deltalake/BaseDeltaLakeMinioConnectorTest.java +++ b/plugin/trino-delta-lake/src/test/java/io/trino/plugin/deltalake/BaseDeltaLakeMinioConnectorTest.java @@ -312,7 +312,7 @@ public void testShowCreateSchema() public void testRenameTable() { assertThatThrownBy(super::testRenameTable) - .hasMessage("Renaming managed tables is not supported for thrift metastore") + .hasMessage("Renaming managed tables is not allowed with current metastore configuration") .hasStackTraceContaining("SQL: ALTER TABLE test_rename_"); } @@ -323,7 +323,7 @@ public void testRenameTable() public void testRenameTableAcrossSchema() { assertThatThrownBy(super::testRenameTableAcrossSchema) - .hasMessage("Renaming managed tables is not supported for thrift metastore") + .hasMessage("Renaming managed tables is not allowed with current metastore configuration") .hasStackTraceContaining("SQL: ALTER TABLE test_rename_"); } @@ -331,7 +331,7 @@ public void testRenameTableAcrossSchema() public void testRenameTableToUnqualifiedPreservesSchema() { assertThatThrownBy(super::testRenameTableToUnqualifiedPreservesSchema) - .hasMessage("Renaming managed tables is not supported for thrift metastore") + .hasMessage("Renaming managed tables is not allowed with current metastore configuration") .hasStackTraceContaining("SQL: ALTER TABLE test_source_schema_"); } @@ -339,7 +339,7 @@ public void testRenameTableToUnqualifiedPreservesSchema() public void testRenameTableToLongTableName() { assertThatThrownBy(super::testRenameTableToLongTableName) - .hasMessage("Renaming managed tables is not supported for thrift metastore") + .hasMessage("Renaming managed tables is not allowed with current metastore configuration") .hasStackTraceContaining("SQL: ALTER TABLE test_rename_"); } diff --git a/plugin/trino-delta-lake/src/test/java/io/trino/plugin/deltalake/TestDeltaLakePerTransactionMetastoreCache.java b/plugin/trino-delta-lake/src/test/java/io/trino/plugin/deltalake/TestDeltaLakePerTransactionMetastoreCache.java index bd80b88fe018..517fac702b79 100644 --- a/plugin/trino-delta-lake/src/test/java/io/trino/plugin/deltalake/TestDeltaLakePerTransactionMetastoreCache.java +++ b/plugin/trino-delta-lake/src/test/java/io/trino/plugin/deltalake/TestDeltaLakePerTransactionMetastoreCache.java @@ -16,6 +16,7 @@ import com.google.common.collect.ImmutableMap; import com.google.common.reflect.Reflection; import com.google.inject.Binder; +import com.google.inject.Key; import com.google.inject.Provides; import com.google.inject.Scopes; import io.airlift.configuration.AbstractConfigurationAwareModule; @@ -104,6 +105,7 @@ protected void setup(Binder binder) .as(generator -> generator.generatedNameOf(ThriftHiveMetastore.class)); install(new ThriftMetastoreAuthenticationModule()); binder.bind(BridgingHiveMetastoreFactory.class).in(Scopes.SINGLETON); + binder.bind(Key.get(boolean.class, AllowDeltaLakeManagedTableRename.class)).toInstance(false); } @Provides diff --git a/plugin/trino-delta-lake/src/test/java/io/trino/plugin/deltalake/metastore/TestDeltaLakeMetastoreAccessOperations.java b/plugin/trino-delta-lake/src/test/java/io/trino/plugin/deltalake/metastore/TestDeltaLakeMetastoreAccessOperations.java index db1a677741bf..d5e0c1bc67b8 100644 --- a/plugin/trino-delta-lake/src/test/java/io/trino/plugin/deltalake/metastore/TestDeltaLakeMetastoreAccessOperations.java +++ b/plugin/trino-delta-lake/src/test/java/io/trino/plugin/deltalake/metastore/TestDeltaLakeMetastoreAccessOperations.java @@ -18,8 +18,10 @@ import com.google.common.collect.Multiset; import com.google.common.collect.Sets; import com.google.inject.Binder; +import com.google.inject.Key; import io.airlift.configuration.AbstractConfigurationAwareModule; import io.trino.Session; +import io.trino.plugin.deltalake.AllowDeltaLakeManagedTableRename; import io.trino.plugin.deltalake.TestingDeltaLakePlugin; import io.trino.plugin.hive.NodeVersion; import io.trino.plugin.hive.metastore.CountingAccessHiveMetastore; @@ -98,6 +100,7 @@ public CountingAccessMetastoreModule(CountingAccessHiveMetastore metastore) protected void setup(Binder binder) { binder.bind(HiveMetastoreFactory.class).annotatedWith(RawHiveMetastoreFactory.class).toInstance(HiveMetastoreFactory.ofInstance(metastore)); + binder.bind(Key.get(boolean.class, AllowDeltaLakeManagedTableRename.class)).toInstance(false); } }