Skip to content

Commit 0724fc4

Browse files
committed
Apply suggestions
1 parent b41de5e commit 0724fc4

File tree

7 files changed

+31
-35
lines changed

7 files changed

+31
-35
lines changed

core/src/main/java/com/scalar/db/common/CoreError.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -799,7 +799,7 @@ public enum CoreError implements ScalarDbError {
799799
JDBC_UNSUPPORTED_COLUMN_TYPE_CONVERSION(
800800
Category.USER_ERROR,
801801
"0239",
802-
"The storage does not support column type conversion from %s to %s. Column: %s",
802+
"The storage does not support column type conversion from %s to %s",
803803
"",
804804
""),
805805

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -977,15 +977,10 @@ public void alterColumnType(
977977
String namespace, String table, String columnName, DataType newColumnType)
978978
throws ExecutionException {
979979
try {
980-
rdbEngine.throwIfAlterColumnTypeNotSupported();
981980
TableMetadata currentTableMetadata = getTableMetadata(namespace, table);
982981
assert currentTableMetadata != null;
983982
DataType currentColumnType = currentTableMetadata.getColumnDataType(columnName);
984-
if (!rdbEngine.isTypeConversionSupported(currentColumnType, newColumnType)) {
985-
throw new UnsupportedOperationException(
986-
CoreError.JDBC_UNSUPPORTED_COLUMN_TYPE_CONVERSION.buildMessage(
987-
currentColumnType, newColumnType, columnName));
988-
}
983+
rdbEngine.throwIfAlterColumnTypeNotSupported(currentColumnType, newColumnType);
989984

990985
TableMetadata updatedTableMetadata =
991986
TableMetadata.newBuilder(currentTableMetadata)

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,15 @@ public void throwIfRenameColumnNotSupported(String columnName, TableMetadata tab
549549
}
550550
}
551551

552+
@Override
553+
public void throwIfAlterColumnTypeNotSupported(DataType from, DataType to) {
554+
if (from == DataType.BLOB && to == DataType.TEXT) {
555+
throw new UnsupportedOperationException(
556+
CoreError.JDBC_UNSUPPORTED_COLUMN_TYPE_CONVERSION.buildMessage(
557+
from.toString(), to.toString()));
558+
}
559+
}
560+
552561
private String getProjection(String columnName, DataType dataType) {
553562
if (dataType == DataType.DATE) {
554563
// Selecting a DATE column requires special handling. We need to cast the DATE column values
@@ -574,9 +583,4 @@ public void throwIfCrossPartitionScanOrderingOnBlobColumnNotSupported(
574583
.buildMessage(orderingOnBlobColumn.get()));
575584
}
576585
}
577-
578-
@Override
579-
public boolean isTypeConversionSupported(DataType from, DataType to) {
580-
return from != DataType.BLOB || to != DataType.TEXT;
581-
}
582586
}

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,11 @@ public String tryAddIfNotExistsToCreateIndexSql(String createIndexSql) {
444444
}
445445

446446
@Override
447-
public boolean isTypeConversionSupported(DataType from, DataType to) {
448-
return from == DataType.INT && to == DataType.BIGINT;
447+
public void throwIfAlterColumnTypeNotSupported(DataType from, DataType to) {
448+
if (!(from == DataType.INT && to == DataType.BIGINT)) {
449+
throw new UnsupportedOperationException(
450+
CoreError.JDBC_UNSUPPORTED_COLUMN_TYPE_CONVERSION.buildMessage(
451+
from.toString(), to.toString()));
452+
}
449453
}
450454
}

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -358,13 +358,14 @@ public RdbEngineTimeTypeStrategy<Integer, Long, Long, Long> getTimeTypeStrategy(
358358
}
359359

360360
@Override
361-
public void setConnectionToReadOnly(Connection connection, boolean readOnly) {
362-
// Do nothing. SQLite does not support read-only mode.
361+
public void throwIfAlterColumnTypeNotSupported(DataType from, DataType to) {
362+
throw new UnsupportedOperationException(
363+
CoreError.JDBC_SQLITE_ALTER_COLUMN_TYPE_NOT_SUPPORTED.buildMessage(
364+
from.toString(), to.toString()));
363365
}
364366

365367
@Override
366-
public void throwIfAlterColumnTypeNotSupported() {
367-
throw new UnsupportedOperationException(
368-
CoreError.JDBC_SQLITE_ALTER_COLUMN_TYPE_NOT_SUPPORTED.buildMessage());
368+
public void setConnectionToReadOnly(Connection connection, boolean readOnly) {
369+
// Do nothing. SQLite does not support read-only mode.
369370
}
370371
}

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

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -283,9 +283,11 @@ default void throwIfRenameColumnNotSupported(String columnName, TableMetadata ta
283283
/**
284284
* Throws an exception if altering the column type is not supported in the underlying database.
285285
*
286+
* @param from the source data type
287+
* @param to the target data type
286288
* @throws UnsupportedOperationException if altering the column type is not supported
287289
*/
288-
default void throwIfAlterColumnTypeNotSupported() {}
290+
default void throwIfAlterColumnTypeNotSupported(DataType from, DataType to) {}
289291

290292
default void setConnectionToReadOnly(Connection connection, boolean readOnly)
291293
throws SQLException {
@@ -303,16 +305,4 @@ default void setConnectionToReadOnly(Connection connection, boolean readOnly)
303305
*/
304306
default void throwIfCrossPartitionScanOrderingOnBlobColumnNotSupported(
305307
ScanAll scanAll, TableMetadata metadata) {}
306-
307-
/**
308-
* Returns whether type conversion is supported between the two data types in the underlying
309-
* storage.
310-
*
311-
* @param from the source data type
312-
* @param to the target data type
313-
* @return true if type conversion is supported, false otherwise
314-
*/
315-
default boolean isTypeConversionSupported(DataType from, DataType to) {
316-
return true;
317-
}
318308
}

integration-test/src/main/java/com/scalar/db/api/DistributedTransactionAdminIntegrationTestBase.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@
3636

3737
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
3838
public abstract class DistributedTransactionAdminIntegrationTestBase {
39+
private static final Logger logger =
40+
LoggerFactory.getLogger(DistributedTransactionAdminIntegrationTestBase.class);
41+
3942
protected static final String NAMESPACE_BASE_NAME = "int_test_";
4043
protected static final String TABLE1 = "test_table1";
4144
protected static final String TABLE2 = "test_table2";
@@ -52,11 +55,11 @@ public abstract class DistributedTransactionAdminIntegrationTestBase {
5255
protected static final String COL_NAME9 = "c9";
5356
protected static final String COL_NAME10 = "c10";
5457
protected static final String COL_NAME11 = "c11";
55-
private static final Logger logger =
56-
LoggerFactory.getLogger(DistributedTransactionAdminIntegrationTestBase.class);
5758
private static final String COL_NAME12 = "c12";
5859
private static final String COL_NAME13 = "c13";
5960
private static final String COL_NAME14 = "c14";
61+
private static final String COL_NAME15 = "c15";
62+
6063
protected static final TableMetadata TABLE_METADATA =
6164
TableMetadata.newBuilder()
6265
.addColumn(COL_NAME1, DataType.INT)
@@ -80,7 +83,6 @@ public abstract class DistributedTransactionAdminIntegrationTestBase {
8083
.addSecondaryIndex(COL_NAME5)
8184
.addSecondaryIndex(COL_NAME6)
8285
.build();
83-
private static final String COL_NAME15 = "c15";
8486
protected TransactionFactory transactionFactory;
8587
protected DistributedTransactionAdmin admin;
8688
protected String namespace1;

0 commit comments

Comments
 (0)