Skip to content

Commit b705bc3

Browse files
committed
Fix to reorg when using Db2
1 parent 0232c33 commit b705bc3

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

core/src/main/java/com/scalar/db/storage/jdbc/JdbcAdmin.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -868,13 +868,11 @@ public void dropColumnFromTable(String namespace, String table, String columnNam
868868
TableMetadata currentTableMetadata = getTableMetadata(namespace, table);
869869
TableMetadata updatedTableMetadata =
870870
TableMetadata.newBuilder(currentTableMetadata).removeColumn(columnName).build();
871-
String dropColumnStatement =
872-
"ALTER TABLE "
873-
+ encloseFullTableName(namespace, table)
874-
+ " DROP COLUMN "
875-
+ enclose(columnName);
871+
String[] dropColumnStatements = rdbEngine.dropColumnSql(namespace, table, columnName);
876872
try (Connection connection = dataSource.getConnection()) {
877-
execute(connection, dropColumnStatement);
873+
for (String dropColumnStatement : dropColumnStatements) {
874+
execute(connection, dropColumnStatement);
875+
}
878876
addTableMetadata(connection, namespace, table, updatedTableMetadata, false, true);
879877
}
880878
} catch (SQLException e) {

core/src/main/java/com/scalar/db/storage/jdbc/RdbEngineDb2.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,17 @@ public void dropNamespaceTranslateSQLException(SQLException e, String namespace)
246246
throw new ExecutionException("Dropping the schema failed: " + namespace, e);
247247
}
248248

249+
@Override
250+
public String[] dropColumnSql(String namespace, String table, String columnName) {
251+
return new String[] {
252+
"ALTER TABLE "
253+
+ encloseFullTableName(namespace, table)
254+
+ " DROP COLUMN "
255+
+ enclose(columnName),
256+
"CALL SYSPROC.ADMIN_CMD('REORG TABLE " + encloseFullTableName(namespace, table) + "')"
257+
};
258+
}
259+
249260
@Override
250261
public String alterColumnTypeSql(
251262
String namespace, String table, String columnName, String columnType) {

core/src/main/java/com/scalar/db/storage/jdbc/RdbEngineStrategy.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,15 @@ default String truncateTableSql(String namespace, String table) {
9898
void dropNamespaceTranslateSQLException(SQLException e, String namespace)
9999
throws ExecutionException;
100100

101+
default String[] dropColumnSql(String namespace, String table, String columnName) {
102+
return new String[] {
103+
"ALTER TABLE "
104+
+ encloseFullTableName(namespace, table)
105+
+ " DROP COLUMN "
106+
+ enclose(columnName)
107+
};
108+
}
109+
101110
String alterColumnTypeSql(String namespace, String table, String columnName, String columnType);
102111

103112
String tableExistsInternalTableCheckSql(String fullTableName);

0 commit comments

Comments
 (0)