Skip to content

Commit fb1a424

Browse files
feeblefakieKodaiD
andauthored
Backport to branch(3) : Add drop column (#3002)
Co-authored-by: Kodai Doki <[email protected]>
1 parent 8a12ccd commit fb1a424

File tree

35 files changed

+1005
-0
lines changed

35 files changed

+1005
-0
lines changed

core/src/integration-test/java/com/scalar/db/storage/cosmos/ConsensusCommitAdminIntegrationTestWithCosmos.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import com.scalar.db.transaction.consensuscommit.Coordinator;
77
import java.util.Map;
88
import java.util.Properties;
9+
import org.junit.jupiter.api.Disabled;
910

1011
public class ConsensusCommitAdminIntegrationTestWithCosmos
1112
extends ConsensusCommitAdminIntegrationTestBase {
@@ -39,4 +40,28 @@ protected boolean isGroupCommitEnabled(String testName) {
3940
return new ConsensusCommitConfig(new DatabaseConfig(getProperties(testName)))
4041
.isCoordinatorGroupCommitEnabled();
4142
}
43+
44+
@Override
45+
@Disabled("Cosmos DB does not support dropping columns")
46+
public void dropColumnFromTable_DropColumnForEachExistingDataType_ShouldDropColumnsCorrectly() {}
47+
48+
@Override
49+
@Disabled("Cosmos DB does not support dropping columns")
50+
public void dropColumnFromTable_ForNonExistingTable_ShouldThrowIllegalArgumentException() {}
51+
52+
@Override
53+
@Disabled("Cosmos DB does not support dropping columns")
54+
public void dropColumnFromTable_ForNonExistingColumn_ShouldThrowIllegalArgumentException() {}
55+
56+
@Override
57+
@Disabled("Cosmos DB does not support dropping columns")
58+
public void dropColumnFromTable_ForPrimaryKeyColumn_ShouldThrowIllegalArgumentException() {}
59+
60+
@Disabled("Cosmos DB does not support dropping columns")
61+
@Override
62+
public void dropColumnFromTable_ForIndexedColumn_ShouldDropColumnAndIndexCorrectly() {}
63+
64+
@Override
65+
@Disabled("Cosmos DB does not support dropping columns")
66+
public void dropColumnFromTable_IfNotExists_ForNonExistingColumn_ShouldNotThrowAnyException() {}
4267
}

core/src/integration-test/java/com/scalar/db/storage/cosmos/CosmosAdminCaseSensitivityIntegrationTest.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.scalar.db.config.DatabaseConfig;
55
import java.util.Map;
66
import java.util.Properties;
7+
import org.junit.jupiter.api.Disabled;
78

89
public class CosmosAdminCaseSensitivityIntegrationTest
910
extends DistributedStorageAdminCaseSensitivityIntegrationTestBase {
@@ -24,4 +25,28 @@ protected String getSystemNamespaceName(Properties properties) {
2425
.getTableMetadataDatabase()
2526
.orElse(DatabaseConfig.DEFAULT_SYSTEM_NAMESPACE_NAME);
2627
}
28+
29+
@Disabled("Cosmos DB does not support dropping columns")
30+
@Override
31+
public void dropColumnFromTable_DropColumnForEachExistingDataType_ShouldDropColumnsCorrectly() {}
32+
33+
@Disabled("Cosmos DB does not support dropping columns")
34+
@Override
35+
public void dropColumnFromTable_ForNonExistingTable_ShouldThrowIllegalArgumentException() {}
36+
37+
@Disabled("Cosmos DB does not support dropping columns")
38+
@Override
39+
public void dropColumnFromTable_ForNonExistingColumn_ShouldThrowIllegalArgumentException() {}
40+
41+
@Disabled("Cosmos DB does not support dropping columns")
42+
@Override
43+
public void dropColumnFromTable_ForPrimaryKeyColumn_ShouldThrowIllegalArgumentException() {}
44+
45+
@Disabled("Cosmos DB does not support dropping columns")
46+
@Override
47+
public void dropColumnFromTable_ForIndexedColumn_ShouldDropColumnAndIndexCorrectly() {}
48+
49+
@Disabled("Cosmos DB does not support dropping columns")
50+
@Override
51+
public void dropColumnFromTable_IfExists_ForNonExistingColumn_ShouldNotThrowAnyException() {}
2752
}

core/src/integration-test/java/com/scalar/db/storage/cosmos/CosmosAdminIntegrationTest.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.scalar.db.config.DatabaseConfig;
55
import java.util.Map;
66
import java.util.Properties;
7+
import org.junit.jupiter.api.Disabled;
78

89
public class CosmosAdminIntegrationTest extends DistributedStorageAdminIntegrationTestBase {
910

@@ -23,4 +24,28 @@ protected String getSystemNamespaceName(Properties properties) {
2324
.getTableMetadataDatabase()
2425
.orElse(DatabaseConfig.DEFAULT_SYSTEM_NAMESPACE_NAME);
2526
}
27+
28+
@Disabled("Cosmos DB does not support dropping columns")
29+
@Override
30+
public void dropColumnFromTable_DropColumnForEachExistingDataType_ShouldDropColumnsCorrectly() {}
31+
32+
@Disabled("Cosmos DB does not support dropping columns")
33+
@Override
34+
public void dropColumnFromTable_ForNonExistingTable_ShouldThrowIllegalArgumentException() {}
35+
36+
@Disabled("Cosmos DB does not support dropping columns")
37+
@Override
38+
public void dropColumnFromTable_ForNonExistingColumn_ShouldThrowIllegalArgumentException() {}
39+
40+
@Disabled("Cosmos DB does not support dropping columns")
41+
@Override
42+
public void dropColumnFromTable_ForPrimaryKeyColumn_ShouldThrowIllegalArgumentException() {}
43+
44+
@Disabled("Cosmos DB does not support dropping columns")
45+
@Override
46+
public void dropColumnFromTable_ForIndexedColumn_ShouldDropColumnAndIndexCorrectly() {}
47+
48+
@Disabled("Cosmos DB does not support dropping columns")
49+
@Override
50+
public void dropColumnFromTable_IfExists_ForNonExistingColumn_ShouldNotThrowAnyException() {}
2651
}

core/src/integration-test/java/com/scalar/db/storage/cosmos/SingleCrudOperationTransactionAdminIntegrationTestWithCosmos.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.scalar.db.transaction.singlecrudoperation.SingleCrudOperationTransactionAdminIntegrationTestBase;
55
import java.util.Map;
66
import java.util.Properties;
7+
import org.junit.jupiter.api.Disabled;
78

89
public class SingleCrudOperationTransactionAdminIntegrationTestWithCosmos
910
extends SingleCrudOperationTransactionAdminIntegrationTestBase {
@@ -24,4 +25,28 @@ protected String getSystemNamespaceName(Properties properties) {
2425
.getTableMetadataDatabase()
2526
.orElse(DatabaseConfig.DEFAULT_SYSTEM_NAMESPACE_NAME);
2627
}
28+
29+
@Override
30+
@Disabled("Cosmos DB does not support dropping columns")
31+
public void dropColumnFromTable_DropColumnForEachExistingDataType_ShouldDropColumnsCorrectly() {}
32+
33+
@Override
34+
@Disabled("Cosmos DB does not support dropping columns")
35+
public void dropColumnFromTable_ForNonExistingTable_ShouldThrowIllegalArgumentException() {}
36+
37+
@Override
38+
@Disabled("Cosmos DB does not support dropping columns")
39+
public void dropColumnFromTable_ForNonExistingColumn_ShouldThrowIllegalArgumentException() {}
40+
41+
@Override
42+
@Disabled("Cosmos DB does not support dropping columns")
43+
public void dropColumnFromTable_ForPrimaryKeyColumn_ShouldThrowIllegalArgumentException() {}
44+
45+
@Disabled("Cosmos DB does not support dropping columns")
46+
@Override
47+
public void dropColumnFromTable_ForIndexedColumn_ShouldDropColumnAndIndexCorrectly() {}
48+
49+
@Override
50+
@Disabled("Cosmos DB does not support dropping columns")
51+
public void dropColumnFromTable_IfNotExists_ForNonExistingColumn_ShouldNotThrowAnyException() {}
2752
}

core/src/integration-test/java/com/scalar/db/storage/dynamo/ConsensusCommitAdminIntegrationTestWithDynamo.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,28 @@ public void namespaceExists_ShouldReturnCorrectResults() {}
9494
@Test
9595
@Override
9696
public void createTable_ForNonExistingNamespace_ShouldThrowIllegalArgumentException() {}
97+
98+
@Override
99+
@Disabled("DynamoDB does not support dropping columns")
100+
public void dropColumnFromTable_DropColumnForEachExistingDataType_ShouldDropColumnsCorrectly() {}
101+
102+
@Override
103+
@Disabled("DynamoDB does not support dropping columns")
104+
public void dropColumnFromTable_ForNonExistingTable_ShouldThrowIllegalArgumentException() {}
105+
106+
@Override
107+
@Disabled("DynamoDB does not support dropping columns")
108+
public void dropColumnFromTable_ForNonExistingColumn_ShouldThrowIllegalArgumentException() {}
109+
110+
@Override
111+
@Disabled("DynamoDB does not support dropping columns")
112+
public void dropColumnFromTable_ForPrimaryKeyColumn_ShouldThrowIllegalArgumentException() {}
113+
114+
@Disabled("DynamoDB does not support dropping columns")
115+
@Override
116+
public void dropColumnFromTable_ForIndexedColumn_ShouldDropColumnAndIndexCorrectly() {}
117+
118+
@Override
119+
@Disabled("DynamoDB does not support dropping columns")
120+
public void dropColumnFromTable_IfNotExists_ForNonExistingColumn_ShouldNotThrowAnyException() {}
97121
}

core/src/integration-test/java/com/scalar/db/storage/dynamo/DynamoAdminCaseSensitivityIntegrationTest.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,28 @@ public void namespaceExists_ShouldReturnCorrectResults() {}
7979
@Test
8080
@Override
8181
public void createTable_ForNonExistingNamespace_ShouldThrowIllegalArgumentException() {}
82+
83+
@Disabled("DynamoDB does not support dropping columns")
84+
@Override
85+
public void dropColumnFromTable_DropColumnForEachExistingDataType_ShouldDropColumnsCorrectly() {}
86+
87+
@Disabled("DynamoDB does not support dropping columns")
88+
@Override
89+
public void dropColumnFromTable_ForNonExistingTable_ShouldThrowIllegalArgumentException() {}
90+
91+
@Disabled("DynamoDB does not support dropping columns")
92+
@Override
93+
public void dropColumnFromTable_ForNonExistingColumn_ShouldThrowIllegalArgumentException() {}
94+
95+
@Disabled("DynamoDB does not support dropping columns")
96+
@Override
97+
public void dropColumnFromTable_ForPrimaryKeyColumn_ShouldThrowIllegalArgumentException() {}
98+
99+
@Disabled("DynamoDB does not support dropping columns")
100+
@Override
101+
public void dropColumnFromTable_ForIndexedColumn_ShouldDropColumnAndIndexCorrectly() {}
102+
103+
@Disabled("DynamoDB does not support dropping columns")
104+
@Override
105+
public void dropColumnFromTable_IfExists_ForNonExistingColumn_ShouldNotThrowAnyException() {}
82106
}

core/src/integration-test/java/com/scalar/db/storage/dynamo/DynamoAdminIntegrationTest.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,28 @@ public void namespaceExists_ShouldReturnCorrectResults() {}
7878
@Test
7979
@Override
8080
public void createTable_ForNonExistingNamespace_ShouldThrowIllegalArgumentException() {}
81+
82+
@Disabled("DynamoDB does not support dropping columns")
83+
@Override
84+
public void dropColumnFromTable_DropColumnForEachExistingDataType_ShouldDropColumnsCorrectly() {}
85+
86+
@Disabled("DynamoDB does not support dropping columns")
87+
@Override
88+
public void dropColumnFromTable_ForNonExistingTable_ShouldThrowIllegalArgumentException() {}
89+
90+
@Disabled("DynamoDB does not support dropping columns")
91+
@Override
92+
public void dropColumnFromTable_ForNonExistingColumn_ShouldThrowIllegalArgumentException() {}
93+
94+
@Disabled("DynamoDB does not support dropping columns")
95+
@Override
96+
public void dropColumnFromTable_ForPrimaryKeyColumn_ShouldThrowIllegalArgumentException() {}
97+
98+
@Disabled("DynamoDB does not support dropping columns")
99+
@Override
100+
public void dropColumnFromTable_ForIndexedColumn_ShouldDropColumnAndIndexCorrectly() {}
101+
102+
@Disabled("DynamoDB does not support dropping columns")
103+
@Override
104+
public void dropColumnFromTable_IfExists_ForNonExistingColumn_ShouldNotThrowAnyException() {}
81105
}

core/src/integration-test/java/com/scalar/db/storage/dynamo/DynamoAdminPermissionIntegrationTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,9 @@ public void addRawColumnToTable_WithSufficientPermission_ShouldSucceed() {}
5959
@Override
6060
@Disabled("Import-related functionality is not supported in DynamoDB")
6161
public void importTable_WithSufficientPermission_ShouldSucceed() {}
62+
63+
@Test
64+
@Override
65+
@Disabled("DynamoDB does not support dropping columns")
66+
public void dropColumnFromTable_WithSufficientPermission_ShouldSucceed() {}
6267
}

core/src/integration-test/java/com/scalar/db/storage/dynamo/SingleCrudOperationTransactionAdminIntegrationTestWithDynamo.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,28 @@ public void namespaceExists_ShouldReturnCorrectResults() {}
7979
@Test
8080
@Override
8181
public void createTable_ForNonExistingNamespace_ShouldThrowIllegalArgumentException() {}
82+
83+
@Override
84+
@Disabled("DynamoDB does not support dropping columns")
85+
public void dropColumnFromTable_DropColumnForEachExistingDataType_ShouldDropColumnsCorrectly() {}
86+
87+
@Override
88+
@Disabled("DynamoDB does not support dropping columns")
89+
public void dropColumnFromTable_ForNonExistingTable_ShouldThrowIllegalArgumentException() {}
90+
91+
@Override
92+
@Disabled("DynamoDB does not support dropping columns")
93+
public void dropColumnFromTable_ForNonExistingColumn_ShouldThrowIllegalArgumentException() {}
94+
95+
@Override
96+
@Disabled("DynamoDB does not support dropping columns")
97+
public void dropColumnFromTable_ForPrimaryKeyColumn_ShouldThrowIllegalArgumentException() {}
98+
99+
@Disabled("DynamoDB does not support dropping columns")
100+
@Override
101+
public void dropColumnFromTable_ForIndexedColumn_ShouldDropColumnAndIndexCorrectly() {}
102+
103+
@Override
104+
@Disabled("DynamoDB does not support dropping columns")
105+
public void dropColumnFromTable_IfNotExists_ForNonExistingColumn_ShouldNotThrowAnyException() {}
82106
}

core/src/main/java/com/scalar/db/api/Admin.java

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,47 @@ default void addNewColumnToTable(
465465
addNewColumnToTable(namespace, table, columnName, columnType);
466466
}
467467

468+
/**
469+
* Drops a column from an existing table. The column cannot be a partition key or a clustering
470+
* key.
471+
*
472+
* @param namespace the table namespace
473+
* @param table the table name
474+
* @param columnName the name of the column to drop
475+
* @throws IllegalArgumentException if the table or column does not exist, or the column is a
476+
* partition key column or clustering key column
477+
* @throws ExecutionException if the operation fails
478+
*/
479+
void dropColumnFromTable(String namespace, String table, String columnName)
480+
throws ExecutionException;
481+
482+
/**
483+
* Drops a column from an existing table. The column cannot be a partition key or a clustering
484+
* key.
485+
*
486+
* @param namespace the table namespace
487+
* @param table the table name
488+
* @param columnName the name of the column to drop
489+
* @param IfExists if set to true, the column will be dropped only if it exists. If set to false,
490+
* it will throw an exception if it does not exist
491+
* @throws IllegalArgumentException if the table does not exist, or the column is a partition key
492+
* column or clustering key column
493+
* @throws ExecutionException if the operation fails
494+
*/
495+
default void dropColumnFromTable(
496+
String namespace, String table, String columnName, boolean IfExists)
497+
throws ExecutionException {
498+
TableMetadata tableMetadata = getTableMetadata(namespace, table);
499+
if (tableMetadata == null) {
500+
throw new IllegalArgumentException(
501+
CoreError.TABLE_NOT_FOUND.buildMessage(ScalarDbUtils.getFullTableName(namespace, table)));
502+
}
503+
if (IfExists && !tableMetadata.getColumnNames().contains(columnName)) {
504+
return;
505+
}
506+
dropColumnFromTable(namespace, table, columnName);
507+
}
508+
468509
/**
469510
* Imports an existing table that is not managed by ScalarDB.
470511
*

0 commit comments

Comments
 (0)