Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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 {}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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");
Expand All @@ -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
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(
Expand All @@ -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");
Expand All @@ -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)
Expand Down Expand Up @@ -134,6 +132,6 @@ public DeltaLakeMetadata create(ConnectorIdentity identity)
deltaLakeRedirectionsProvider,
statisticsAccess,
useUniqueTableLocation,
metastoreType);
allowManagedTableRename);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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_");
}

Expand Down Expand Up @@ -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_");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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_");
}

Expand All @@ -323,23 +323,23 @@ 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_");
}

@Override
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_");
}

@Override
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_");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}

Expand Down