Skip to content

Commit 72cbaa9

Browse files
Backport to branch(3.15) : For Oracle, allow importing a table with NUMBER(1) data type to a ScalarDB BOOLEAN (#3252)
Co-authored-by: Vincent Guilpain <[email protected]>
1 parent 5ad9f8c commit 72cbaa9

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
@@ -326,12 +326,20 @@ private LinkedHashMap<String, String> prepareColumnsForOracle() {
326326
columns.put("col19", "TIMESTAMP"); // override to TIME
327327
columns.put("col20", "TIMESTAMP WITH TIME ZONE");
328328
columns.put("col21", "TIMESTAMP WITH LOCAL TIME ZONE");
329+
columns.put("col22", "NUMBER(1)"); // override to BOOLEAN
329330
return columns;
330331
}
331332

332333
private Map<String, DataType> prepareOverrideColumnsTypeForOracle() {
333334
return ImmutableMap.of(
334-
"col16", DataType.TIME, "col17", DataType.TIMESTAMP, "col19", DataType.TIME);
335+
"col16",
336+
DataType.TIME,
337+
"col17",
338+
DataType.TIMESTAMP,
339+
"col19",
340+
DataType.TIME,
341+
"col22",
342+
DataType.BOOLEAN);
335343
}
336344

337345
private TableMetadata prepareTableMetadataForOracle() {
@@ -359,6 +367,7 @@ private TableMetadata prepareTableMetadataForOracle() {
359367
.addColumn("col19", DataType.TIME)
360368
.addColumn("col20", DataType.TIMESTAMPTZ)
361369
.addColumn("col21", DataType.TIMESTAMPTZ)
370+
.addColumn("col22", DataType.BOOLEAN)
362371
.addPartitionKey("pk1")
363372
.addPartitionKey("pk2")
364373
.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
@@ -269,6 +269,9 @@ DataType getDataTypeForScalarDbInternal(
269269
numericTypeDescription, columnDescription));
270270
}
271271
if (digits == 0) {
272+
if (columnSize == 1 && overrideDataType == DataType.BOOLEAN) {
273+
return DataType.BOOLEAN;
274+
}
272275
logger.info(
273276
"Data type larger than that of underlying database is assigned: {} to BIGINT",
274277
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
@@ -97,6 +97,9 @@ private static void prepareDataTypeMap() {
9797
DATA_TYPE_MAP.get(MYSQL).put(new Column(JDBCType.BIT, "BIT", 1, 0), DataType.BOOLEAN);
9898
DATA_TYPE_MAP.get(POSTGRESQL).put(new Column(JDBCType.BIT, "bool", 1, 0), DataType.BOOLEAN);
9999
DATA_TYPE_MAP.get(SQL_SERVER).put(new Column(JDBCType.BIT, "bit", 1, 0), DataType.BOOLEAN);
100+
DATA_TYPE_MAP
101+
.get(ORACLE)
102+
.put(new Column(JDBCType.NUMERIC, "NUMBER", 1, 0, DataType.BOOLEAN), DataType.BOOLEAN);
100103

101104
// INT
102105
DATA_TYPE_MAP.get(MYSQL).put(new Column(JDBCType.TINYINT, "TINYINT"), DataType.INT);
@@ -180,6 +183,7 @@ private static void prepareDataTypeMap() {
180183
DATA_TYPE_MAP.get(ORACLE).put(new Column(JDBCType.NUMERIC, "NUMBER", 15, 0), DataType.BIGINT);
181184
DATA_TYPE_MAP.get(ORACLE).put(new Column(JDBCType.NUMERIC, "NUMBER", 15, 2), DataType.DOUBLE);
182185
DATA_TYPE_MAP.get(ORACLE).put(new Column(JDBCType.NUMERIC, "NUMBER", 16, 0), null);
186+
DATA_TYPE_MAP.get(ORACLE).put(new Column(JDBCType.NUMERIC, "NUMBER", 1, 0), DataType.BIGINT);
183187
DATA_TYPE_MAP.get(SQL_SERVER).put(new Column(JDBCType.NUMERIC, "numeric"), null);
184188
DATA_TYPE_MAP.get(SQL_SERVER).put(new Column(JDBCType.DECIMAL, "decimal"), null);
185189

0 commit comments

Comments
 (0)