Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -76,4 +76,16 @@ public void renameColumn_ForIndexKeyColumn_ShouldRenameColumnAndIndexCorrectly()
admin.dropTable(getNamespace1(), getTable4(), true);
}
}

@Override
@Disabled("Cassandra does not support renaming tables")
public void renameTable_ForExistingTable_ShouldRenameTableCorrectly() {}

@Override
@Disabled("Cassandra does not support renaming tables")
public void renameTable_ForNonExistingTable_ShouldThrowIllegalArgumentException() {}

@Override
@Disabled("Cassandra does not support renaming tables")
public void renameTable_IfNewTableNameAlreadyExists_ShouldThrowIllegalArgumentException() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,16 @@ public void renameColumn_ForIndexKeyColumn_ShouldRenameColumnAndIndexCorrectly()
admin.dropTable(getNamespace1(), getTable4(), true);
}
}

@Override
@Disabled("Cassandra does not support renaming tables")
public void renameTable_ForExistingTable_ShouldRenameTableCorrectly() {}

@Override
@Disabled("Cassandra does not support renaming tables")
public void renameTable_ForNonExistingTable_ShouldThrowIllegalArgumentException() {}

@Override
@Disabled("Cassandra does not support renaming tables")
public void renameTable_IfNewTableNameAlreadyExists_ShouldThrowIllegalArgumentException() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,9 @@ public void renameColumn_WithSufficientPermission_ShouldSucceed() throws Executi
assertThatCode(() -> adminForNormalUser.renameColumn(NAMESPACE, TABLE, COL_NAME1, NEW_COL_NAME))
.doesNotThrowAnyException();
}

@Test
@Override
@Disabled("Cassandra does not support renaming tables")
public void renameTable_WithSufficientPermission_ShouldSucceed() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,16 @@ public void renameColumn_ForIndexKeyColumn_ShouldRenameColumnAndIndexCorrectly()
admin.dropTable(namespace1, TABLE4, true);
}
}

@Override
@Disabled("Cassandra does not support renaming tables")
public void renameTable_ForExistingTable_ShouldRenameTableCorrectly() {}

@Override
@Disabled("Cassandra does not support renaming tables")
public void renameTable_ForNonExistingTable_ShouldThrowIllegalArgumentException() {}

@Override
@Disabled("Cassandra does not support renaming tables")
public void renameTable_IfNewTableNameAlreadyExists_ShouldThrowIllegalArgumentException() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,16 @@ public void renameColumn_ForIndexKeyColumn_ShouldRenameColumnAndIndexCorrectly()
admin.dropTable(namespace1, TABLE4, true);
}
}

@Override
@Disabled("Cassandra does not support renaming tables")
public void renameTable_ForExistingTable_ShouldRenameTableCorrectly() {}

@Override
@Disabled("Cassandra does not support renaming tables")
public void renameTable_ForNonExistingTable_ShouldThrowIllegalArgumentException() {}

@Override
@Disabled("Cassandra does not support renaming tables")
public void renameTable_IfNewTableNameAlreadyExists_ShouldThrowIllegalArgumentException() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,16 @@ public void renameColumn_ForPrimaryKeyColumn_ShouldRenameColumnCorrectly() {}
@Override
@Disabled("Cosmos DB does not support renaming columns")
public void renameColumn_ForIndexKeyColumn_ShouldRenameColumnAndIndexCorrectly() {}

@Override
@Disabled("Cosmos DB does not support renaming tables")
public void renameTable_ForExistingTable_ShouldRenameTableCorrectly() {}

@Override
@Disabled("Cosmos DB does not support renaming tables")
public void renameTable_ForNonExistingTable_ShouldThrowIllegalArgumentException() {}

@Override
@Disabled("Cosmos DB does not support renaming tables")
public void renameTable_IfNewTableNameAlreadyExists_ShouldThrowIllegalArgumentException() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,16 @@ public void renameColumn_ForPrimaryKeyColumn_ShouldRenameColumnCorrectly() {}
@Override
@Disabled("Cosmos DB does not support renaming columns")
public void renameColumn_ForIndexKeyColumn_ShouldRenameColumnAndIndexCorrectly() {}

@Override
@Disabled("Cosmos DB does not support renaming tables")
public void renameTable_ForExistingTable_ShouldRenameTableCorrectly() {}

@Override
@Disabled("Cosmos DB does not support renaming tables")
public void renameTable_ForNonExistingTable_ShouldThrowIllegalArgumentException() {}

@Override
@Disabled("Cosmos DB does not support renaming tables")
public void renameTable_IfNewTableNameAlreadyExists_ShouldThrowIllegalArgumentException() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,16 @@ public void renameColumn_ForPrimaryKeyColumn_ShouldRenameColumnCorrectly() {}
@Override
@Disabled("Cosmos DB does not support renaming columns")
public void renameColumn_ForIndexKeyColumn_ShouldRenameColumnAndIndexCorrectly() {}

@Override
@Disabled("Cosmos DB does not support renaming tables")
public void renameTable_ForExistingTable_ShouldRenameTableCorrectly() {}

@Override
@Disabled("Cosmos DB does not support renaming tables")
public void renameTable_ForNonExistingTable_ShouldThrowIllegalArgumentException() {}

@Override
@Disabled("Cosmos DB does not support renaming tables")
public void renameTable_IfNewTableNameAlreadyExists_ShouldThrowIllegalArgumentException() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,16 @@ public void renameColumn_ForPrimaryKeyColumn_ShouldRenameColumnCorrectly() {}
@Override
@Disabled("Cosmos DB does not support renaming columns")
public void renameColumn_ForIndexKeyColumn_ShouldRenameColumnAndIndexCorrectly() {}

@Override
@Disabled("Cosmos DB does not support renaming tables")
public void renameTable_ForExistingTable_ShouldRenameTableCorrectly() {}

@Override
@Disabled("Cosmos DB does not support renaming tables")
public void renameTable_ForNonExistingTable_ShouldThrowIllegalArgumentException() {}

@Override
@Disabled("Cosmos DB does not support renaming tables")
public void renameTable_IfNewTableNameAlreadyExists_ShouldThrowIllegalArgumentException() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,16 @@ public void renameColumn_ForPrimaryKeyColumn_ShouldRenameColumnCorrectly() {}
@Override
@Disabled("DynamoDB does not support renaming columns")
public void renameColumn_ForIndexKeyColumn_ShouldRenameColumnAndIndexCorrectly() {}

@Override
@Disabled("DynamoDB does not support renaming tables")
public void renameTable_ForExistingTable_ShouldRenameTableCorrectly() {}

@Override
@Disabled("DynamoDB does not support renaming tables")
public void renameTable_ForNonExistingTable_ShouldThrowIllegalArgumentException() {}

@Override
@Disabled("DynamoDB does not support renaming tables")
public void renameTable_IfNewTableNameAlreadyExists_ShouldThrowIllegalArgumentException() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,16 @@ public void renameColumn_ForPrimaryKeyColumn_ShouldRenameColumnCorrectly() {}
@Override
@Disabled("DynamoDB does not support renaming columns")
public void renameColumn_ForIndexKeyColumn_ShouldRenameColumnAndIndexCorrectly() {}

@Override
@Disabled("DynamoDB does not support renaming tables")
public void renameTable_ForExistingTable_ShouldRenameTableCorrectly() {}

@Override
@Disabled("DynamoDB does not support renaming tables")
public void renameTable_ForNonExistingTable_ShouldThrowIllegalArgumentException() {}

@Override
@Disabled("DynamoDB does not support renaming tables")
public void renameTable_IfNewTableNameAlreadyExists_ShouldThrowIllegalArgumentException() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,16 @@ public void renameColumn_ForPrimaryKeyColumn_ShouldRenameColumnCorrectly() {}
@Override
@Disabled("DynamoDB does not support renaming columns")
public void renameColumn_ForIndexKeyColumn_ShouldRenameColumnAndIndexCorrectly() {}

@Override
@Disabled("DynamoDB does not support renaming tables")
public void renameTable_ForExistingTable_ShouldRenameTableCorrectly() {}

@Override
@Disabled("DynamoDB does not support renaming tables")
public void renameTable_ForNonExistingTable_ShouldThrowIllegalArgumentException() {}

@Override
@Disabled("DynamoDB does not support renaming tables")
public void renameTable_IfNewTableNameAlreadyExists_ShouldThrowIllegalArgumentException() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,9 @@ public void dropColumnFromTable_WithSufficientPermission_ShouldSucceed() {}
@Override
@Disabled("DynamoDB does not support renaming columns")
public void renameColumn_WithSufficientPermission_ShouldSucceed() {}

@Test
@Override
@Disabled("DynamoDB does not support renaming columns")
public void renameTable_WithSufficientPermission_ShouldSucceed() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,16 @@ public void renameColumn_ForPrimaryKeyColumn_ShouldRenameColumnCorrectly() {}
@Override
@Disabled("DynamoDB does not support renaming columns")
public void renameColumn_ForIndexKeyColumn_ShouldRenameColumnAndIndexCorrectly() {}

@Override
@Disabled("DynamoDB does not support renaming tables")
public void renameTable_ForExistingTable_ShouldRenameTableCorrectly() {}

@Override
@Disabled("DynamoDB does not support renaming tables")
public void renameTable_ForNonExistingTable_ShouldThrowIllegalArgumentException() {}

@Override
@Disabled("DynamoDB does not support renaming tables")
public void renameTable_IfNewTableNameAlreadyExists_ShouldThrowIllegalArgumentException() {}
}
13 changes: 13 additions & 0 deletions core/src/main/java/com/scalar/db/api/Admin.java
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,19 @@ default void dropColumnFromTable(
void renameColumn(String namespace, String table, String oldColumnName, String newColumnName)
throws ExecutionException;

/**
* Renames an existing table.
*
* @param namespace the table namespace
* @param oldTableName the current name of the table to rename
* @param newTableName the new name of the table
* @throws IllegalArgumentException if the table to rename does not exist or the table with the
* new name already exists
* @throws ExecutionException if the operation fails
*/
void renameTable(String namespace, String oldTableName, String newTableName)
throws ExecutionException;

/**
* Imports an existing table that is not managed by ScalarDB.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,33 @@ public void renameColumn(
}
}

@Override
public void renameTable(String namespace, String oldTableName, String newTableName)
throws ExecutionException {
TableMetadata tableMetadata = getTableMetadata(namespace, oldTableName);
if (tableMetadata == null) {
throw new IllegalArgumentException(
CoreError.TABLE_NOT_FOUND.buildMessage(
ScalarDbUtils.getFullTableName(namespace, oldTableName)));
}

if (tableExists(namespace, newTableName)) {
throw new IllegalArgumentException(
CoreError.TABLE_ALREADY_EXISTS.buildMessage(
ScalarDbUtils.getFullTableName(namespace, newTableName)));
}

try {
admin.renameTable(namespace, oldTableName, newTableName);
} catch (ExecutionException e) {
throw new ExecutionException(
CoreError.RENAMING_TABLE_FAILED.buildMessage(
ScalarDbUtils.getFullTableName(namespace, oldTableName),
ScalarDbUtils.getFullTableName(namespace, newTableName)),
e);
}
}

@Override
public Set<String> getNamespaceNames() throws ExecutionException {
try {
Expand Down
12 changes: 12 additions & 0 deletions core/src/main/java/com/scalar/db/common/CoreError.java
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,12 @@ public enum CoreError implements ScalarDbError {
"The BOOLEAN type is not supported for index columns in DynamoDB. Column: %s",
"",
""),
CASSANDRA_RENAME_TABLE_NOT_SUPPORTED(
Category.USER_ERROR, "0227", "Renaming tables is not supported in Cassandra", "", ""),
COSMOS_RENAME_TABLE_NOT_SUPPORTED(
Category.USER_ERROR, "0228", "Renaming tables is not supported in Cosmos DB", "", ""),
DYNAMO_RENAME_TABLE_NOT_SUPPORTED(
Category.USER_ERROR, "0229", "Renaming tables is not supported in DynamoDB", "", ""),

//
// Errors for the concurrency error category
Expand Down Expand Up @@ -1030,6 +1036,12 @@ public enum CoreError implements ScalarDbError {
"Renaming a column failed. Table: %s; Old column name: %s; New column name: %s",
"",
""),
RENAMING_TABLE_FAILED(
Category.INTERNAL_ERROR,
"0061",
"Renaming a table failed. Old table name: %s; New table name: %s",
"",
""),

//
// Errors for the unknown transaction status error category
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,12 @@ public void renameColumn(
distributedTransactionAdmin.renameColumn(namespace, table, oldColumnName, newColumnName);
}

@Override
public void renameTable(String namespace, String oldTableName, String newTableName)
throws ExecutionException {
distributedTransactionAdmin.renameTable(namespace, oldTableName, newTableName);
}

@Override
public void importTable(String namespace, String table, Map<String, String> options)
throws ExecutionException {
Expand Down
6 changes: 6 additions & 0 deletions core/src/main/java/com/scalar/db/service/AdminService.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@ public void renameColumn(
admin.renameColumn(namespace, table, oldColumnName, newColumnName);
}

@Override
public void renameTable(String namespace, String oldTableName, String newTableName)
throws ExecutionException {
admin.renameTable(namespace, oldTableName, newTableName);
}

@Override
public TableMetadata getImportTableMetadata(
String namespace, String table, Map<String, DataType> overrideColumnsType)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,13 @@ oldColumnName, newColumnName, getFullTableName(namespace, table)),
}
}

@Override
public void renameTable(String namespace, String oldTableName, String newTableName)
throws ExecutionException {
throw new UnsupportedOperationException(
CoreError.CASSANDRA_RENAME_TABLE_NOT_SUPPORTED.buildMessage());
}

@Override
public Set<String> getNamespaceNames() throws ExecutionException {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,13 @@ public void renameColumn(
CoreError.COSMOS_RENAME_COLUMN_NOT_SUPPORTED.buildMessage());
}

@Override
public void renameTable(String namespace, String oldTableName, String newTableName)
throws ExecutionException {
throw new UnsupportedOperationException(
CoreError.COSMOS_RENAME_TABLE_NOT_SUPPORTED.buildMessage());
}

@Override
public TableMetadata getImportTableMetadata(
String namespace, String table, Map<String, DataType> overrideColumnsType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1451,6 +1451,13 @@ public void renameColumn(
CoreError.DYNAMO_RENAME_COLUMN_NOT_SUPPORTED.buildMessage());
}

@Override
public void renameTable(String namespace, String oldTableName, String newTableName)
throws ExecutionException {
throw new UnsupportedOperationException(
CoreError.DYNAMO_RENAME_TABLE_NOT_SUPPORTED.buildMessage());
}

@Override
public TableMetadata getImportTableMetadata(
String namespace, String table, Map<String, DataType> overrideColumnsType) {
Expand Down
21 changes: 21 additions & 0 deletions core/src/main/java/com/scalar/db/storage/jdbc/JdbcAdmin.java
Original file line number Diff line number Diff line change
Expand Up @@ -927,6 +927,27 @@ oldColumnName, newColumnName, getFullTableName(namespace, table)),
}
}

@Override
public void renameTable(String namespace, String oldTableName, String newTableName)
throws ExecutionException {
try {
TableMetadata tableMetadata = getTableMetadata(namespace, oldTableName);
assert tableMetadata != null;
String renameTableStatement = rdbEngine.renameTableSql(namespace, oldTableName, newTableName);
try (Connection connection = dataSource.getConnection()) {
execute(connection, renameTableStatement);
execute(connection, getDeleteTableMetadataStatement(namespace, oldTableName));
addTableMetadata(connection, namespace, newTableName, tableMetadata, false, false);
}
} catch (SQLException e) {
throw new ExecutionException(
String.format(
"Renaming the %s table to %s failed",
getFullTableName(namespace, oldTableName), getFullTableName(namespace, newTableName)),
e);
}
}

@Override
public void addRawColumnToTable(
String namespace, String table, String columnName, DataType columnType)
Expand Down
Loading
Loading