Skip to content

Commit 14cb0a7

Browse files
authored
Add drop column (#2983)
1 parent 2f021d4 commit 14cb0a7

File tree

35 files changed

+1002
-0
lines changed

35 files changed

+1002
-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
@@ -4,6 +4,7 @@
44
import com.scalar.db.util.AdminTestUtils;
55
import java.util.Map;
66
import java.util.Properties;
7+
import org.junit.jupiter.api.Disabled;
78

89
public class ConsensusCommitAdminIntegrationTestWithCosmos
910
extends ConsensusCommitAdminIntegrationTestBase {
@@ -22,4 +23,28 @@ protected Map<String, String> getCreationOptions() {
2223
protected AdminTestUtils getAdminTestUtils(String testName) {
2324
return new CosmosAdminTestUtils(getProperties(testName));
2425
}
26+
27+
@Override
28+
@Disabled("Cosmos DB does not support dropping columns")
29+
public void dropColumnFromTable_DropColumnForEachExistingDataType_ShouldDropColumnsCorrectly() {}
30+
31+
@Override
32+
@Disabled("Cosmos DB does not support dropping columns")
33+
public void dropColumnFromTable_ForNonExistingTable_ShouldThrowIllegalArgumentException() {}
34+
35+
@Override
36+
@Disabled("Cosmos DB does not support dropping columns")
37+
public void dropColumnFromTable_ForNonExistingColumn_ShouldThrowIllegalArgumentException() {}
38+
39+
@Override
40+
@Disabled("Cosmos DB does not support dropping columns")
41+
public void dropColumnFromTable_ForPrimaryKeyColumn_ShouldThrowIllegalArgumentException() {}
42+
43+
@Disabled("Cosmos DB does not support dropping columns")
44+
@Override
45+
public void dropColumnFromTable_ForIndexedColumn_ShouldDropColumnAndIndexCorrectly() {}
46+
47+
@Override
48+
@Disabled("Cosmos DB does not support dropping columns")
49+
public void dropColumnFromTable_IfNotExists_ForNonExistingColumn_ShouldNotThrowAnyException() {}
2550
}

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.util.AdminTestUtils;
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 {
@@ -22,4 +23,28 @@ protected Map<String, String> getCreationOptions() {
2223
protected AdminTestUtils getAdminTestUtils(String testName) {
2324
return new CosmosAdminTestUtils(getProperties(testName));
2425
}
26+
27+
@Disabled("Cosmos DB does not support dropping columns")
28+
@Override
29+
public void dropColumnFromTable_DropColumnForEachExistingDataType_ShouldDropColumnsCorrectly() {}
30+
31+
@Disabled("Cosmos DB does not support dropping columns")
32+
@Override
33+
public void dropColumnFromTable_ForNonExistingTable_ShouldThrowIllegalArgumentException() {}
34+
35+
@Disabled("Cosmos DB does not support dropping columns")
36+
@Override
37+
public void dropColumnFromTable_ForNonExistingColumn_ShouldThrowIllegalArgumentException() {}
38+
39+
@Disabled("Cosmos DB does not support dropping columns")
40+
@Override
41+
public void dropColumnFromTable_ForPrimaryKeyColumn_ShouldThrowIllegalArgumentException() {}
42+
43+
@Disabled("Cosmos DB does not support dropping columns")
44+
@Override
45+
public void dropColumnFromTable_ForIndexedColumn_ShouldDropColumnAndIndexCorrectly() {}
46+
47+
@Disabled("Cosmos DB does not support dropping columns")
48+
@Override
49+
public void dropColumnFromTable_IfExists_ForNonExistingColumn_ShouldNotThrowAnyException() {}
2550
}

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.util.AdminTestUtils;
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

@@ -21,4 +22,28 @@ protected Map<String, String> getCreationOptions() {
2122
protected AdminTestUtils getAdminTestUtils(String testName) {
2223
return new CosmosAdminTestUtils(getProperties(testName));
2324
}
25+
26+
@Disabled("Cosmos DB does not support dropping columns")
27+
@Override
28+
public void dropColumnFromTable_DropColumnForEachExistingDataType_ShouldDropColumnsCorrectly() {}
29+
30+
@Disabled("Cosmos DB does not support dropping columns")
31+
@Override
32+
public void dropColumnFromTable_ForNonExistingTable_ShouldThrowIllegalArgumentException() {}
33+
34+
@Disabled("Cosmos DB does not support dropping columns")
35+
@Override
36+
public void dropColumnFromTable_ForNonExistingColumn_ShouldThrowIllegalArgumentException() {}
37+
38+
@Disabled("Cosmos DB does not support dropping columns")
39+
@Override
40+
public void dropColumnFromTable_ForPrimaryKeyColumn_ShouldThrowIllegalArgumentException() {}
41+
42+
@Disabled("Cosmos DB does not support dropping columns")
43+
@Override
44+
public void dropColumnFromTable_ForIndexedColumn_ShouldDropColumnAndIndexCorrectly() {}
45+
46+
@Disabled("Cosmos DB does not support dropping columns")
47+
@Override
48+
public void dropColumnFromTable_IfExists_ForNonExistingColumn_ShouldNotThrowAnyException() {}
2449
}

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
@@ -3,6 +3,7 @@
33
import com.scalar.db.transaction.singlecrudoperation.SingleCrudOperationTransactionAdminIntegrationTestBase;
44
import java.util.Map;
55
import java.util.Properties;
6+
import org.junit.jupiter.api.Disabled;
67

78
public class SingleCrudOperationTransactionAdminIntegrationTestWithCosmos
89
extends SingleCrudOperationTransactionAdminIntegrationTestBase {
@@ -16,4 +17,28 @@ protected Properties getProps(String testName) {
1617
protected Map<String, String> getCreationOptions() {
1718
return CosmosEnv.getCreationOptions();
1819
}
20+
21+
@Override
22+
@Disabled("Cosmos DB does not support dropping columns")
23+
public void dropColumnFromTable_DropColumnForEachExistingDataType_ShouldDropColumnsCorrectly() {}
24+
25+
@Override
26+
@Disabled("Cosmos DB does not support dropping columns")
27+
public void dropColumnFromTable_ForNonExistingTable_ShouldThrowIllegalArgumentException() {}
28+
29+
@Override
30+
@Disabled("Cosmos DB does not support dropping columns")
31+
public void dropColumnFromTable_ForNonExistingColumn_ShouldThrowIllegalArgumentException() {}
32+
33+
@Override
34+
@Disabled("Cosmos DB does not support dropping columns")
35+
public void dropColumnFromTable_ForPrimaryKeyColumn_ShouldThrowIllegalArgumentException() {}
36+
37+
@Disabled("Cosmos DB does not support dropping columns")
38+
@Override
39+
public void dropColumnFromTable_ForIndexedColumn_ShouldDropColumnAndIndexCorrectly() {}
40+
41+
@Override
42+
@Disabled("Cosmos DB does not support dropping columns")
43+
public void dropColumnFromTable_IfNotExists_ForNonExistingColumn_ShouldNotThrowAnyException() {}
1944
}

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

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

89
public class ConsensusCommitAdminIntegrationTestWithDynamo
910
extends ConsensusCommitAdminIntegrationTestBase {
@@ -27,4 +28,28 @@ protected boolean isIndexOnBooleanColumnSupported() {
2728
protected AdminTestUtils getAdminTestUtils(String testName) {
2829
return new DynamoAdminTestUtils(getProperties(testName));
2930
}
31+
32+
@Override
33+
@Disabled("DynamoDB does not support dropping columns")
34+
public void dropColumnFromTable_DropColumnForEachExistingDataType_ShouldDropColumnsCorrectly() {}
35+
36+
@Override
37+
@Disabled("DynamoDB does not support dropping columns")
38+
public void dropColumnFromTable_ForNonExistingTable_ShouldThrowIllegalArgumentException() {}
39+
40+
@Override
41+
@Disabled("DynamoDB does not support dropping columns")
42+
public void dropColumnFromTable_ForNonExistingColumn_ShouldThrowIllegalArgumentException() {}
43+
44+
@Override
45+
@Disabled("DynamoDB does not support dropping columns")
46+
public void dropColumnFromTable_ForPrimaryKeyColumn_ShouldThrowIllegalArgumentException() {}
47+
48+
@Disabled("DynamoDB does not support dropping columns")
49+
@Override
50+
public void dropColumnFromTable_ForIndexedColumn_ShouldDropColumnAndIndexCorrectly() {}
51+
52+
@Override
53+
@Disabled("DynamoDB does not support dropping columns")
54+
public void dropColumnFromTable_IfNotExists_ForNonExistingColumn_ShouldNotThrowAnyException() {}
3055
}

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

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

89
public class DynamoAdminCaseSensitivityIntegrationTest
910
extends DistributedStorageAdminCaseSensitivityIntegrationTestBase {
@@ -27,4 +28,28 @@ protected boolean isIndexOnBooleanColumnSupported() {
2728
protected AdminTestUtils getAdminTestUtils(String testName) {
2829
return new DynamoAdminTestUtils(getProperties(testName));
2930
}
31+
32+
@Disabled("DynamoDB does not support dropping columns")
33+
@Override
34+
public void dropColumnFromTable_DropColumnForEachExistingDataType_ShouldDropColumnsCorrectly() {}
35+
36+
@Disabled("DynamoDB does not support dropping columns")
37+
@Override
38+
public void dropColumnFromTable_ForNonExistingTable_ShouldThrowIllegalArgumentException() {}
39+
40+
@Disabled("DynamoDB does not support dropping columns")
41+
@Override
42+
public void dropColumnFromTable_ForNonExistingColumn_ShouldThrowIllegalArgumentException() {}
43+
44+
@Disabled("DynamoDB does not support dropping columns")
45+
@Override
46+
public void dropColumnFromTable_ForPrimaryKeyColumn_ShouldThrowIllegalArgumentException() {}
47+
48+
@Disabled("DynamoDB does not support dropping columns")
49+
@Override
50+
public void dropColumnFromTable_ForIndexedColumn_ShouldDropColumnAndIndexCorrectly() {}
51+
52+
@Disabled("DynamoDB does not support dropping columns")
53+
@Override
54+
public void dropColumnFromTable_IfExists_ForNonExistingColumn_ShouldNotThrowAnyException() {}
3055
}

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

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

89
public class DynamoAdminIntegrationTest extends DistributedStorageAdminIntegrationTestBase {
910

@@ -26,4 +27,28 @@ protected boolean isIndexOnBooleanColumnSupported() {
2627
protected AdminTestUtils getAdminTestUtils(String testName) {
2728
return new DynamoAdminTestUtils(getProperties(testName));
2829
}
30+
31+
@Disabled("DynamoDB does not support dropping columns")
32+
@Override
33+
public void dropColumnFromTable_DropColumnForEachExistingDataType_ShouldDropColumnsCorrectly() {}
34+
35+
@Disabled("DynamoDB does not support dropping columns")
36+
@Override
37+
public void dropColumnFromTable_ForNonExistingTable_ShouldThrowIllegalArgumentException() {}
38+
39+
@Disabled("DynamoDB does not support dropping columns")
40+
@Override
41+
public void dropColumnFromTable_ForNonExistingColumn_ShouldThrowIllegalArgumentException() {}
42+
43+
@Disabled("DynamoDB does not support dropping columns")
44+
@Override
45+
public void dropColumnFromTable_ForPrimaryKeyColumn_ShouldThrowIllegalArgumentException() {}
46+
47+
@Disabled("DynamoDB does not support dropping columns")
48+
@Override
49+
public void dropColumnFromTable_ForIndexedColumn_ShouldDropColumnAndIndexCorrectly() {}
50+
51+
@Disabled("DynamoDB does not support dropping columns")
52+
@Override
53+
public void dropColumnFromTable_IfExists_ForNonExistingColumn_ShouldNotThrowAnyException() {}
2954
}

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: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.scalar.db.transaction.singlecrudoperation.SingleCrudOperationTransactionAdminIntegrationTestBase;
44
import java.util.Map;
55
import java.util.Properties;
6+
import org.junit.jupiter.api.Disabled;
67

78
public class SingleCrudOperationTransactionAdminIntegrationTestWithDynamo
89
extends SingleCrudOperationTransactionAdminIntegrationTestBase {
@@ -21,4 +22,28 @@ protected Map<String, String> getCreationOptions() {
2122
protected boolean isIndexOnBooleanColumnSupported() {
2223
return false;
2324
}
25+
26+
@Override
27+
@Disabled("DynamoDB does not support dropping columns")
28+
public void dropColumnFromTable_DropColumnForEachExistingDataType_ShouldDropColumnsCorrectly() {}
29+
30+
@Override
31+
@Disabled("DynamoDB does not support dropping columns")
32+
public void dropColumnFromTable_ForNonExistingTable_ShouldThrowIllegalArgumentException() {}
33+
34+
@Override
35+
@Disabled("DynamoDB does not support dropping columns")
36+
public void dropColumnFromTable_ForNonExistingColumn_ShouldThrowIllegalArgumentException() {}
37+
38+
@Override
39+
@Disabled("DynamoDB does not support dropping columns")
40+
public void dropColumnFromTable_ForPrimaryKeyColumn_ShouldThrowIllegalArgumentException() {}
41+
42+
@Disabled("DynamoDB does not support dropping columns")
43+
@Override
44+
public void dropColumnFromTable_ForIndexedColumn_ShouldDropColumnAndIndexCorrectly() {}
45+
46+
@Override
47+
@Disabled("DynamoDB does not support dropping columns")
48+
public void dropColumnFromTable_IfNotExists_ForNonExistingColumn_ShouldNotThrowAnyException() {}
2449
}

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

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,47 @@ default void addNewColumnToTable(
479479
addNewColumnToTable(namespace, table, columnName, columnType);
480480
}
481481

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+
* @throws IllegalArgumentException if the table or column does not exist, or the column is a
490+
* partition key column or clustering key column
491+
* @throws ExecutionException if the operation fails
492+
*/
493+
void dropColumnFromTable(String namespace, String table, String columnName)
494+
throws ExecutionException;
495+
496+
/**
497+
* Drops a column from an existing table. The column cannot be a partition key or a clustering
498+
* key.
499+
*
500+
* @param namespace the table namespace
501+
* @param table the table name
502+
* @param columnName the name of the column to drop
503+
* @param IfExists if set to true, the column will be dropped only if it exists. If set to false,
504+
* it will throw an exception if it does not exist
505+
* @throws IllegalArgumentException if the table does not exist, or the column is a partition key
506+
* column or clustering key column
507+
* @throws ExecutionException if the operation fails
508+
*/
509+
default void dropColumnFromTable(
510+
String namespace, String table, String columnName, boolean IfExists)
511+
throws ExecutionException {
512+
TableMetadata tableMetadata = getTableMetadata(namespace, table);
513+
if (tableMetadata == null) {
514+
throw new IllegalArgumentException(
515+
CoreError.TABLE_NOT_FOUND.buildMessage(ScalarDbUtils.getFullTableName(namespace, table)));
516+
}
517+
if (IfExists && !tableMetadata.getColumnNames().contains(columnName)) {
518+
return;
519+
}
520+
dropColumnFromTable(namespace, table, columnName);
521+
}
522+
482523
/**
483524
* Imports an existing table that is not managed by ScalarDB.
484525
*

0 commit comments

Comments
 (0)