Skip to content

Commit 1935d4e

Browse files
authored
For Oracle, allow importing a table with NUMBER(1) data type to a ScalarDB BOOLEAN (#3239)
1 parent f017785 commit 1935d4e

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

core/src/integration-test/java/com/scalar/db/storage/jdbc/JdbcAdminImportTestUtils.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,12 +358,20 @@ private LinkedHashMap<String, String> prepareColumnsForOracle() {
358358
columns.put("col19", "TIMESTAMP"); // override to TIME
359359
columns.put("col20", "TIMESTAMP WITH TIME ZONE");
360360
columns.put("col21", "TIMESTAMP WITH LOCAL TIME ZONE");
361+
columns.put("col22", "NUMBER(1)"); // override to BOOLEAN
361362
return columns;
362363
}
363364

364365
private Map<String, DataType> prepareOverrideColumnsTypeForOracle() {
365366
return ImmutableMap.of(
366-
"col16", DataType.TIME, "col17", DataType.TIMESTAMP, "col19", DataType.TIME);
367+
"col16",
368+
DataType.TIME,
369+
"col17",
370+
DataType.TIMESTAMP,
371+
"col19",
372+
DataType.TIME,
373+
"col22",
374+
DataType.BOOLEAN);
367375
}
368376

369377
private TableMetadata prepareTableMetadataForOracle() {
@@ -391,6 +399,7 @@ private TableMetadata prepareTableMetadataForOracle() {
391399
.addColumn("col19", DataType.TIME)
392400
.addColumn("col20", DataType.TIMESTAMPTZ)
393401
.addColumn("col21", DataType.TIMESTAMPTZ)
402+
.addColumn("col22", DataType.BOOLEAN)
394403
.addPartitionKey("pk1")
395404
.addPartitionKey("pk2")
396405
.build();

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,9 @@ DataType getDataTypeForScalarDbInternal(
308308
numericTypeDescription, columnDescription));
309309
}
310310
if (digits == 0) {
311+
if (columnSize == 1 && overrideDataType == DataType.BOOLEAN) {
312+
return DataType.BOOLEAN;
313+
}
311314
logger.info(
312315
"Data type larger than that of underlying database is assigned: {} to BIGINT",
313316
numericTypeDescription);

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ private static void prepareDataTypeMap() {
9999
DATA_TYPE_MAP.get(POSTGRESQL).put(new Column(JDBCType.BIT, "bool", 1, 0), DataType.BOOLEAN);
100100
DATA_TYPE_MAP.get(SQL_SERVER).put(new Column(JDBCType.BIT, "bit", 1, 0), DataType.BOOLEAN);
101101
DATA_TYPE_MAP.get(DB2).put(new Column(JDBCType.BOOLEAN, "BOOLEAN"), DataType.BOOLEAN);
102+
DATA_TYPE_MAP
103+
.get(ORACLE)
104+
.put(new Column(JDBCType.NUMERIC, "NUMBER", 1, 0, DataType.BOOLEAN), DataType.BOOLEAN);
102105

103106
// INT
104107
DATA_TYPE_MAP.get(MYSQL).put(new Column(JDBCType.TINYINT, "TINYINT"), DataType.INT);
@@ -203,6 +206,7 @@ private static void prepareDataTypeMap() {
203206
DATA_TYPE_MAP.get(ORACLE).put(new Column(JDBCType.NUMERIC, "NUMBER", 15, 0), DataType.BIGINT);
204207
DATA_TYPE_MAP.get(ORACLE).put(new Column(JDBCType.NUMERIC, "NUMBER", 15, 2), DataType.DOUBLE);
205208
DATA_TYPE_MAP.get(ORACLE).put(new Column(JDBCType.NUMERIC, "NUMBER", 16, 0), null);
209+
DATA_TYPE_MAP.get(ORACLE).put(new Column(JDBCType.NUMERIC, "NUMBER", 1, 0), DataType.BIGINT);
206210
DATA_TYPE_MAP.get(SQL_SERVER).put(new Column(JDBCType.NUMERIC, "numeric"), null);
207211
DATA_TYPE_MAP.get(SQL_SERVER).put(new Column(JDBCType.DECIMAL, "decimal"), null);
208212
DATA_TYPE_MAP.get(DB2).put(new Column(JDBCType.DECIMAL, "DECIMAL"), null);

0 commit comments

Comments
 (0)