Skip to content

Commit 7802a3b

Browse files
committed
Fix
1 parent b64e4bc commit 7802a3b

File tree

2 files changed

+37
-31
lines changed

2 files changed

+37
-31
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -885,7 +885,8 @@ public void alterColumnType(
885885
for (String alterColumnTypeStatement : alterColumnTypeStatements) {
886886
execute(connection, alterColumnTypeStatement);
887887
}
888-
addTableMetadata(connection, namespace, table, updatedTableMetadata, false, true);
888+
execute(connection, getDeleteTableMetadataStatement(namespace, table));
889+
addTableMetadata(connection, namespace, table, updatedTableMetadata, false);
889890
}
890891
} catch (SQLException e) {
891892
throw new ExecutionException(

core/src/test/java/com/scalar/db/storage/jdbc/JdbcAdminTestBase.java

Lines changed: 35 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3118,15 +3118,17 @@ public void alterColumnType_ForMysql_ShouldWorkProperly()
31183118
alterColumnType_ForX_ShouldWorkProperly(
31193119
RdbEngine.MYSQL,
31203120
"SELECT `column_name`,`data_type`,`key_type`,`clustering_order`,`indexed` FROM `"
3121-
+ METADATA_SCHEMA
3121+
+ tableMetadataSchemaName
31223122
+ "`.`metadata` WHERE `full_table_name`=? ORDER BY `ordinal_position` ASC",
31233123
"ALTER TABLE `ns`.`table` MODIFY `c2` BIGINT",
3124-
"DELETE FROM `" + METADATA_SCHEMA + "`.`metadata` WHERE `full_table_name` = 'ns.table'",
3124+
"DELETE FROM `"
3125+
+ tableMetadataSchemaName
3126+
+ "`.`metadata` WHERE `full_table_name` = 'ns.table'",
31253127
"INSERT INTO `"
3126-
+ METADATA_SCHEMA
3128+
+ tableMetadataSchemaName
31273129
+ "`.`metadata` VALUES ('ns.table','c1','TEXT','PARTITION',NULL,false,1)",
31283130
"INSERT INTO `"
3129-
+ METADATA_SCHEMA
3131+
+ tableMetadataSchemaName
31303132
+ "`.`metadata` VALUES ('ns.table','c2','BIGINT',NULL,NULL,false,2)");
31313133
}
31323134

@@ -3136,17 +3138,17 @@ public void alterColumnType_ForOracle_ShouldWorkProperly()
31363138
alterColumnType_ForX_ShouldWorkProperly(
31373139
RdbEngine.ORACLE,
31383140
"SELECT \"column_name\",\"data_type\",\"key_type\",\"clustering_order\",\"indexed\" FROM \""
3139-
+ METADATA_SCHEMA
3141+
+ tableMetadataSchemaName
31403142
+ "\".\"metadata\" WHERE \"full_table_name\"=? ORDER BY \"ordinal_position\" ASC",
31413143
"ALTER TABLE \"ns\".\"table\" MODIFY ( \"c2\" NUMBER(16) )",
31423144
"DELETE FROM \""
3143-
+ METADATA_SCHEMA
3145+
+ tableMetadataSchemaName
31443146
+ "\".\"metadata\" WHERE \"full_table_name\" = 'ns.table'",
31453147
"INSERT INTO \""
3146-
+ METADATA_SCHEMA
3148+
+ tableMetadataSchemaName
31473149
+ "\".\"metadata\" VALUES ('ns.table','c1','TEXT','PARTITION',NULL,0,1)",
31483150
"INSERT INTO \""
3149-
+ METADATA_SCHEMA
3151+
+ tableMetadataSchemaName
31503152
+ "\".\"metadata\" VALUES ('ns.table','c2','BIGINT',NULL,NULL,0,2)");
31513153
}
31523154

@@ -3156,17 +3158,17 @@ public void alterColumnType_ForPostgresql_ShouldWorkProperly()
31563158
alterColumnType_ForX_ShouldWorkProperly(
31573159
RdbEngine.POSTGRESQL,
31583160
"SELECT \"column_name\",\"data_type\",\"key_type\",\"clustering_order\",\"indexed\" FROM \""
3159-
+ METADATA_SCHEMA
3161+
+ tableMetadataSchemaName
31603162
+ "\".\"metadata\" WHERE \"full_table_name\"=? ORDER BY \"ordinal_position\" ASC",
31613163
"ALTER TABLE \"ns\".\"table\" ALTER COLUMN \"c2\" TYPE BIGINT",
31623164
"DELETE FROM \""
3163-
+ METADATA_SCHEMA
3165+
+ tableMetadataSchemaName
31643166
+ "\".\"metadata\" WHERE \"full_table_name\" = 'ns.table'",
31653167
"INSERT INTO \""
3166-
+ METADATA_SCHEMA
3168+
+ tableMetadataSchemaName
31673169
+ "\".\"metadata\" VALUES ('ns.table','c1','TEXT','PARTITION',NULL,false,1)",
31683170
"INSERT INTO \""
3169-
+ METADATA_SCHEMA
3171+
+ tableMetadataSchemaName
31703172
+ "\".\"metadata\" VALUES ('ns.table','c2','BIGINT',NULL,NULL,false,2)");
31713173
}
31723174

@@ -3176,15 +3178,17 @@ public void alterColumnType_ForSqlServer_ShouldWorkProperly()
31763178
alterColumnType_ForX_ShouldWorkProperly(
31773179
RdbEngine.SQL_SERVER,
31783180
"SELECT [column_name],[data_type],[key_type],[clustering_order],[indexed] FROM ["
3179-
+ METADATA_SCHEMA
3181+
+ tableMetadataSchemaName
31803182
+ "].[metadata] WHERE [full_table_name]=? ORDER BY [ordinal_position] ASC",
31813183
"ALTER TABLE [ns].[table] ALTER COLUMN [c2] BIGINT",
3182-
"DELETE FROM [" + METADATA_SCHEMA + "].[metadata] WHERE [full_table_name] = 'ns.table'",
3184+
"DELETE FROM ["
3185+
+ tableMetadataSchemaName
3186+
+ "].[metadata] WHERE [full_table_name] = 'ns.table'",
31833187
"INSERT INTO ["
3184-
+ METADATA_SCHEMA
3188+
+ tableMetadataSchemaName
31853189
+ "].[metadata] VALUES ('ns.table','c1','TEXT','PARTITION',NULL,0,1)",
31863190
"INSERT INTO ["
3187-
+ METADATA_SCHEMA
3191+
+ tableMetadataSchemaName
31883192
+ "].[metadata] VALUES ('ns.table','c2','BIGINT',NULL,NULL,0,2)");
31893193
}
31903194

@@ -3197,15 +3201,16 @@ public void alterColumnType_ForSqlite_ShouldThrowUnsupportedOperationException()
31973201
String columnName1 = "c1";
31983202
String columnName2 = "c2";
31993203

3204+
PreparedStatement checkStatement = prepareStatementForNamespaceCheck();
32003205
PreparedStatement selectStatement = mock(PreparedStatement.class);
32013206
ResultSet resultSet =
32023207
mockResultSet(
3203-
new SelectAllFromMetadataTableResultSetMocker.Row(
3204-
columnName1, DataType.TEXT.toString(), "PARTITION", null, false),
3205-
new SelectAllFromMetadataTableResultSetMocker.Row(
3206-
columnName2, DataType.INT.toString(), null, null, false));
3208+
Arrays.asList(
3209+
new Row(columnName1, DataType.TEXT.toString(), "PARTITION", null, false),
3210+
new Row(columnName2, DataType.INT.toString(), null, null, false)));
32073211
when(selectStatement.executeQuery()).thenReturn(resultSet);
3208-
when(connection.prepareStatement(any())).thenReturn(selectStatement);
3212+
3213+
when(connection.prepareStatement(any())).thenReturn(checkStatement).thenReturn(selectStatement);
32093214
when(dataSource.getConnection()).thenReturn(connection);
32103215
JdbcAdmin admin = createJdbcAdminFor(RdbEngine.SQLITE);
32113216

@@ -3220,18 +3225,18 @@ public void alterColumnType_ForDb2_ShouldWorkProperly() throws SQLException, Exe
32203225
alterColumnType_ForX_ShouldWorkProperly(
32213226
RdbEngine.DB2,
32223227
"SELECT \"column_name\",\"data_type\",\"key_type\",\"clustering_order\",\"indexed\" FROM \""
3223-
+ METADATA_SCHEMA
3228+
+ tableMetadataSchemaName
32243229
+ "\".\"metadata\" WHERE \"full_table_name\"=? ORDER BY \"ordinal_position\" ASC",
32253230
"ALTER TABLE \"ns\".\"table\" ALTER COLUMN \"c2\" SET DATA TYPE BIGINT",
32263231
"CALL SYSPROC.ADMIN_CMD('REORG TABLE \"ns\".\"table\"')",
32273232
"DELETE FROM \""
3228-
+ METADATA_SCHEMA
3233+
+ tableMetadataSchemaName
32293234
+ "\".\"metadata\" WHERE \"full_table_name\" = 'ns.table'",
32303235
"INSERT INTO \""
3231-
+ METADATA_SCHEMA
3236+
+ tableMetadataSchemaName
32323237
+ "\".\"metadata\" VALUES ('ns.table','c1','TEXT','PARTITION',NULL,false,1)",
32333238
"INSERT INTO \""
3234-
+ METADATA_SCHEMA
3239+
+ tableMetadataSchemaName
32353240
+ "\".\"metadata\" VALUES ('ns.table','c2','BIGINT',NULL,NULL,false,2)");
32363241
}
32373242

@@ -3244,16 +3249,16 @@ private void alterColumnType_ForX_ShouldWorkProperly(
32443249
String columnName1 = "c1";
32453250
String columnName2 = "c2";
32463251

3252+
PreparedStatement checkStatement = prepareStatementForNamespaceCheck();
32473253
PreparedStatement selectStatement = mock(PreparedStatement.class);
32483254
ResultSet resultSet =
32493255
mockResultSet(
3250-
new SelectAllFromMetadataTableResultSetMocker.Row(
3251-
columnName1, DataType.TEXT.toString(), "PARTITION", null, false),
3252-
new SelectAllFromMetadataTableResultSetMocker.Row(
3253-
columnName2, DataType.INT.toString(), null, null, false));
3256+
Arrays.asList(
3257+
new Row(columnName1, DataType.TEXT.toString(), "PARTITION", null, false),
3258+
new Row(columnName2, DataType.INT.toString(), null, null, false)));
32543259
when(selectStatement.executeQuery()).thenReturn(resultSet);
32553260

3256-
when(connection.prepareStatement(any())).thenReturn(selectStatement);
3261+
when(connection.prepareStatement(any())).thenReturn(checkStatement).thenReturn(selectStatement);
32573262
List<Statement> expectedStatements = new ArrayList<>();
32583263
for (int i = 0; i < expectedSqlStatements.length; i++) {
32593264
Statement expectedStatement = mock(Statement.class);

0 commit comments

Comments
 (0)