From a631204312887ee25d90b2771a694d88d522a7c3 Mon Sep 17 00:00:00 2001 From: Vincent Guilpain Date: Wed, 3 Dec 2025 11:17:38 +0900 Subject: [PATCH] For Oracle, allow importing a NUMBER(1) data type with BOOLEAN type override --- .../db/storage/jdbc/JdbcAdminImportTestUtils.java | 11 ++++++++++- .../com/scalar/db/storage/jdbc/RdbEngineOracle.java | 3 +++ .../com/scalar/db/storage/jdbc/RdbEngineTest.java | 4 ++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/core/src/integration-test/java/com/scalar/db/storage/jdbc/JdbcAdminImportTestUtils.java b/core/src/integration-test/java/com/scalar/db/storage/jdbc/JdbcAdminImportTestUtils.java index 2fbb0aac35..1d86c7b6a1 100644 --- a/core/src/integration-test/java/com/scalar/db/storage/jdbc/JdbcAdminImportTestUtils.java +++ b/core/src/integration-test/java/com/scalar/db/storage/jdbc/JdbcAdminImportTestUtils.java @@ -358,12 +358,20 @@ private LinkedHashMap prepareColumnsForOracle() { columns.put("col19", "TIMESTAMP"); // override to TIME columns.put("col20", "TIMESTAMP WITH TIME ZONE"); columns.put("col21", "TIMESTAMP WITH LOCAL TIME ZONE"); + columns.put("col22", "NUMBER(1)"); // override to BOOLEAN return columns; } private Map prepareOverrideColumnsTypeForOracle() { return ImmutableMap.of( - "col16", DataType.TIME, "col17", DataType.TIMESTAMP, "col19", DataType.TIME); + "col16", + DataType.TIME, + "col17", + DataType.TIMESTAMP, + "col19", + DataType.TIME, + "col22", + DataType.BOOLEAN); } private TableMetadata prepareTableMetadataForOracle() { @@ -391,6 +399,7 @@ private TableMetadata prepareTableMetadataForOracle() { .addColumn("col19", DataType.TIME) .addColumn("col20", DataType.TIMESTAMPTZ) .addColumn("col21", DataType.TIMESTAMPTZ) + .addColumn("col22", DataType.BOOLEAN) .addPartitionKey("pk1") .addPartitionKey("pk2") .build(); diff --git a/core/src/main/java/com/scalar/db/storage/jdbc/RdbEngineOracle.java b/core/src/main/java/com/scalar/db/storage/jdbc/RdbEngineOracle.java index 95f45887e5..7ace8b9d8c 100644 --- a/core/src/main/java/com/scalar/db/storage/jdbc/RdbEngineOracle.java +++ b/core/src/main/java/com/scalar/db/storage/jdbc/RdbEngineOracle.java @@ -308,6 +308,9 @@ DataType getDataTypeForScalarDbInternal( numericTypeDescription, columnDescription)); } if (digits == 0) { + if (columnSize == 1 && overrideDataType == DataType.BOOLEAN) { + return DataType.BOOLEAN; + } logger.info( "Data type larger than that of underlying database is assigned: {} to BIGINT", numericTypeDescription); diff --git a/core/src/test/java/com/scalar/db/storage/jdbc/RdbEngineTest.java b/core/src/test/java/com/scalar/db/storage/jdbc/RdbEngineTest.java index ff839f29ac..1d7d14edfb 100644 --- a/core/src/test/java/com/scalar/db/storage/jdbc/RdbEngineTest.java +++ b/core/src/test/java/com/scalar/db/storage/jdbc/RdbEngineTest.java @@ -99,6 +99,9 @@ private static void prepareDataTypeMap() { DATA_TYPE_MAP.get(POSTGRESQL).put(new Column(JDBCType.BIT, "bool", 1, 0), DataType.BOOLEAN); DATA_TYPE_MAP.get(SQL_SERVER).put(new Column(JDBCType.BIT, "bit", 1, 0), DataType.BOOLEAN); DATA_TYPE_MAP.get(DB2).put(new Column(JDBCType.BOOLEAN, "BOOLEAN"), DataType.BOOLEAN); + DATA_TYPE_MAP + .get(ORACLE) + .put(new Column(JDBCType.NUMERIC, "NUMBER", 1, 0, DataType.BOOLEAN), DataType.BOOLEAN); // INT DATA_TYPE_MAP.get(MYSQL).put(new Column(JDBCType.TINYINT, "TINYINT"), DataType.INT); @@ -203,6 +206,7 @@ private static void prepareDataTypeMap() { DATA_TYPE_MAP.get(ORACLE).put(new Column(JDBCType.NUMERIC, "NUMBER", 15, 0), DataType.BIGINT); DATA_TYPE_MAP.get(ORACLE).put(new Column(JDBCType.NUMERIC, "NUMBER", 15, 2), DataType.DOUBLE); DATA_TYPE_MAP.get(ORACLE).put(new Column(JDBCType.NUMERIC, "NUMBER", 16, 0), null); + DATA_TYPE_MAP.get(ORACLE).put(new Column(JDBCType.NUMERIC, "NUMBER", 1, 0), DataType.BIGINT); DATA_TYPE_MAP.get(SQL_SERVER).put(new Column(JDBCType.NUMERIC, "numeric"), null); DATA_TYPE_MAP.get(SQL_SERVER).put(new Column(JDBCType.DECIMAL, "decimal"), null); DATA_TYPE_MAP.get(DB2).put(new Column(JDBCType.DECIMAL, "DECIMAL"), null);