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
Expand Up @@ -237,8 +237,12 @@ public synchronized void renameDatabase(String databaseName, String newDatabaseN
getRequiredDatabase(databaseName);
verifyDatabaseNotExists(newDatabaseName);

Path oldDatabaseMetadataDirectory = getDatabaseMetadataDirectory(databaseName);
Path newDatabaseMetadataDirectory = getDatabaseMetadataDirectory(newDatabaseName);
try {
if (!metadataFileSystem.rename(getDatabaseMetadataDirectory(databaseName), getDatabaseMetadataDirectory(newDatabaseName))) {
renameSchemaFile(DATABASE, oldDatabaseMetadataDirectory, newDatabaseMetadataDirectory);

if (!metadataFileSystem.rename(oldDatabaseMetadataDirectory, newDatabaseMetadataDirectory)) {
throw new TrinoException(HIVE_METASTORE_ERROR, "Could not rename database metadata directory");
}
}
Expand Down Expand Up @@ -1331,6 +1335,18 @@ private <T> void writeFile(String type, Path path, JsonCodec<T> codec, T value,
}
}

private void renameSchemaFile(SchemaType type, Path oldMetadataDirectory, Path newMetadataDirectory)
{
try {
if (!metadataFileSystem.rename(getSchemaPath(type, oldMetadataDirectory), getSchemaPath(type, newMetadataDirectory))) {
throw new TrinoException(HIVE_METASTORE_ERROR, "Could not rename " + type + " schema");
}
}
catch (IOException e) {
throw new TrinoException(HIVE_METASTORE_ERROR, "Could not rename " + type + " schema", e);
}
}

private void deleteSchemaFile(SchemaType type, Path metadataDirectory)
{
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1792,6 +1792,7 @@ public void testRenameSchema()
try {
assertUpdate("CREATE SCHEMA " + schemaName);
assertUpdate("ALTER SCHEMA " + schemaName + " RENAME TO " + schemaName + "_renamed");
assertThat(computeActual("SHOW SCHEMAS").getOnlyColumnAsSet()).contains(schemaName + "_renamed");
}
finally {
assertUpdate("DROP SCHEMA IF EXISTS " + schemaName);
Expand Down