Skip to content

Commit

Permalink
Change some JDBC data types to proper ones (#2000)
Browse files Browse the repository at this point in the history
  • Loading branch information
komamitsu authored Jul 3, 2024
1 parent 53a8013 commit e6ea7b1
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,9 @@ public String getDataTypeForEngine(DataType scalarDbDataType) {
case BOOLEAN:
return "BOOLEAN";
case DOUBLE:
case FLOAT:
return "DOUBLE";
case FLOAT:
return "REAL";
case INT:
return "INT";
case TEXT:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ public String getDataTypeForEngine(DataType scalarDbDataType) {
case FLOAT:
return "BINARY_FLOAT";
case INT:
return "INT";
return "NUMBER(10)";
case TEXT:
return "VARCHAR2(4000)";
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ public String getDataTypeForEngine(DataType scalarDbDataType) {
case DOUBLE:
return "DOUBLE PRECISION";
case FLOAT:
return "FLOAT";
return "REAL";
case INT:
return "INT";
case TEXT:
Expand Down
23 changes: 15 additions & 8 deletions core/src/test/java/com/scalar/db/storage/jdbc/JdbcAdminTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ public void createTableInternal_ForMysql_ShouldCreateTableAndIndexes()
throws ExecutionException, SQLException {
createTableInternal_ForX_CreateTableAndIndexes(
RdbEngine.MYSQL,
"CREATE TABLE `my_ns`.`foo_table`(`c3` BOOLEAN,`c1` VARCHAR(64),`c4` VARBINARY(64),`c2` BIGINT,`c5` INT,`c6` DOUBLE,`c7` DOUBLE, PRIMARY KEY (`c3` ASC,`c1` DESC,`c4` ASC))",
"CREATE TABLE `my_ns`.`foo_table`(`c3` BOOLEAN,`c1` VARCHAR(64),`c4` VARBINARY(64),`c2` BIGINT,`c5` INT,`c6` DOUBLE,`c7` REAL, PRIMARY KEY (`c3` ASC,`c1` DESC,`c4` ASC))",
"CREATE INDEX `index_my_ns_foo_table_c4` ON `my_ns`.`foo_table` (`c4`)",
"CREATE INDEX `index_my_ns_foo_table_c1` ON `my_ns`.`foo_table` (`c1`)");
}
Expand All @@ -461,7 +461,7 @@ public void createTableInternal_ForPostgresql_ShouldCreateTableAndIndexes()
throws ExecutionException, SQLException {
createTableInternal_ForX_CreateTableAndIndexes(
RdbEngine.POSTGRESQL,
"CREATE TABLE \"my_ns\".\"foo_table\"(\"c3\" BOOLEAN,\"c1\" VARCHAR(10485760),\"c4\" BYTEA,\"c2\" BIGINT,\"c5\" INT,\"c6\" DOUBLE PRECISION,\"c7\" FLOAT, PRIMARY KEY (\"c3\",\"c1\",\"c4\"))",
"CREATE TABLE \"my_ns\".\"foo_table\"(\"c3\" BOOLEAN,\"c1\" VARCHAR(10485760),\"c4\" BYTEA,\"c2\" BIGINT,\"c5\" INT,\"c6\" DOUBLE PRECISION,\"c7\" REAL, PRIMARY KEY (\"c3\",\"c1\",\"c4\"))",
"CREATE UNIQUE INDEX \"my_ns.foo_table_clustering_order_idx\" ON \"my_ns\".\"foo_table\" (\"c3\" ASC,\"c1\" DESC,\"c4\" ASC)",
"CREATE INDEX \"index_my_ns_foo_table_c4\" ON \"my_ns\".\"foo_table\" (\"c4\")",
"CREATE INDEX \"index_my_ns_foo_table_c1\" ON \"my_ns\".\"foo_table\" (\"c1\")");
Expand All @@ -483,7 +483,7 @@ public void createTableInternal_ForOracle_ShouldCreateTableAndIndexes()
throws ExecutionException, SQLException {
createTableInternal_ForX_CreateTableAndIndexes(
RdbEngine.ORACLE,
"CREATE TABLE \"my_ns\".\"foo_table\"(\"c3\" NUMBER(1),\"c1\" VARCHAR2(64),\"c4\" RAW(64),\"c2\" NUMBER(19),\"c5\" INT,\"c6\" BINARY_DOUBLE,\"c7\" BINARY_FLOAT, PRIMARY KEY (\"c3\",\"c1\",\"c4\")) ROWDEPENDENCIES",
"CREATE TABLE \"my_ns\".\"foo_table\"(\"c3\" NUMBER(1),\"c1\" VARCHAR2(64),\"c4\" RAW(64),\"c2\" NUMBER(19),\"c5\" NUMBER(10),\"c6\" BINARY_DOUBLE,\"c7\" BINARY_FLOAT, PRIMARY KEY (\"c3\",\"c1\",\"c4\")) ROWDEPENDENCIES",
"ALTER TABLE \"my_ns\".\"foo_table\" INITRANS 3 MAXTRANS 255",
"CREATE UNIQUE INDEX \"my_ns.foo_table_clustering_order_idx\" ON \"my_ns\".\"foo_table\" (\"c3\" ASC,\"c1\" DESC,\"c4\" ASC)",
"CREATE INDEX \"index_my_ns_foo_table_c4\" ON \"my_ns\".\"foo_table\" (\"c4\")",
Expand Down Expand Up @@ -548,7 +548,7 @@ public void createTableInternal_IfNotExistsForMysql_ShouldCreateTableAndIndexesI
throws ExecutionException, SQLException {
createTableInternal_IfNotExistsForX_createTableAndIndexesIfNotExists(
RdbEngine.MYSQL,
"CREATE TABLE IF NOT EXISTS `my_ns`.`foo_table`(`c3` BOOLEAN,`c1` VARCHAR(64),`c4` VARBINARY(64),`c2` BIGINT,`c5` INT,`c6` DOUBLE,`c7` DOUBLE, PRIMARY KEY (`c3` ASC,`c1` DESC,`c4` ASC))",
"CREATE TABLE IF NOT EXISTS `my_ns`.`foo_table`(`c3` BOOLEAN,`c1` VARCHAR(64),`c4` VARBINARY(64),`c2` BIGINT,`c5` INT,`c6` DOUBLE,`c7` REAL, PRIMARY KEY (`c3` ASC,`c1` DESC,`c4` ASC))",
"CREATE INDEX `index_my_ns_foo_table_c4` ON `my_ns`.`foo_table` (`c4`)",
"CREATE INDEX `index_my_ns_foo_table_c1` ON `my_ns`.`foo_table` (`c1`)");
}
Expand All @@ -558,7 +558,7 @@ public void createTableInternal_IfNotExistsForPostgresql_ShouldCreateTableAndInd
throws ExecutionException, SQLException {
createTableInternal_IfNotExistsForX_createTableAndIndexesIfNotExists(
RdbEngine.POSTGRESQL,
"CREATE TABLE IF NOT EXISTS \"my_ns\".\"foo_table\"(\"c3\" BOOLEAN,\"c1\" VARCHAR(10485760),\"c4\" BYTEA,\"c2\" BIGINT,\"c5\" INT,\"c6\" DOUBLE PRECISION,\"c7\" FLOAT, PRIMARY KEY (\"c3\",\"c1\",\"c4\"))",
"CREATE TABLE IF NOT EXISTS \"my_ns\".\"foo_table\"(\"c3\" BOOLEAN,\"c1\" VARCHAR(10485760),\"c4\" BYTEA,\"c2\" BIGINT,\"c5\" INT,\"c6\" DOUBLE PRECISION,\"c7\" REAL, PRIMARY KEY (\"c3\",\"c1\",\"c4\"))",
"CREATE UNIQUE INDEX IF NOT EXISTS \"my_ns.foo_table_clustering_order_idx\" ON \"my_ns\".\"foo_table\" (\"c3\" ASC,\"c1\" DESC,\"c4\" ASC)",
"CREATE INDEX IF NOT EXISTS \"index_my_ns_foo_table_c4\" ON \"my_ns\".\"foo_table\" (\"c4\")",
"CREATE INDEX IF NOT EXISTS \"index_my_ns_foo_table_c1\" ON \"my_ns\".\"foo_table\" (\"c1\")");
Expand All @@ -580,7 +580,7 @@ public void createTableInternal_IfNotExistsForOracle_ShouldCreateTableAndIndexes
throws ExecutionException, SQLException {
createTableInternal_IfNotExistsForX_createTableAndIndexesIfNotExists(
RdbEngine.ORACLE,
"CREATE TABLE \"my_ns\".\"foo_table\"(\"c3\" NUMBER(1),\"c1\" VARCHAR2(64),\"c4\" RAW(64),\"c2\" NUMBER(19),\"c5\" INT,\"c6\" BINARY_DOUBLE,\"c7\" BINARY_FLOAT, PRIMARY KEY (\"c3\",\"c1\",\"c4\")) ROWDEPENDENCIES",
"CREATE TABLE \"my_ns\".\"foo_table\"(\"c3\" NUMBER(1),\"c1\" VARCHAR2(64),\"c4\" RAW(64),\"c2\" NUMBER(19),\"c5\" NUMBER(10),\"c6\" BINARY_DOUBLE,\"c7\" BINARY_FLOAT, PRIMARY KEY (\"c3\",\"c1\",\"c4\")) ROWDEPENDENCIES",
"ALTER TABLE \"my_ns\".\"foo_table\" INITRANS 3 MAXTRANS 255",
"CREATE UNIQUE INDEX \"my_ns.foo_table_clustering_order_idx\" ON \"my_ns\".\"foo_table\" (\"c3\" ASC,\"c1\" DESC,\"c4\" ASC)",
"CREATE INDEX \"index_my_ns_foo_table_c4\" ON \"my_ns\".\"foo_table\" (\"c4\")",
Expand Down Expand Up @@ -2374,7 +2374,7 @@ public void addNewColumnToTable_ForOracle_ShouldWorkProperly()
"SELECT \"column_name\",\"data_type\",\"key_type\",\"clustering_order\",\"indexed\" FROM \""
+ METADATA_SCHEMA
+ "\".\"metadata\" WHERE \"full_table_name\"=? ORDER BY \"ordinal_position\" ASC",
"ALTER TABLE \"ns\".\"table\" ADD \"c2\" INT",
"ALTER TABLE \"ns\".\"table\" ADD \"c2\" NUMBER(10)",
"DELETE FROM \""
+ METADATA_SCHEMA
+ "\".\"metadata\" WHERE \"full_table_name\" = 'ns.table'",
Expand Down Expand Up @@ -2887,11 +2887,18 @@ private String prepareSqlForTableCheck(RdbEngine rdbEngine, String namespace, St

private String prepareSqlForAlterTableAddColumn(RdbEngine rdbEngine, String column) {
RdbEngineStrategy rdbEngineStrategy = getRdbEngineStrategy(rdbEngine);
String intType;
if (rdbEngineStrategy instanceof RdbEngineOracle) {
intType = "NUMBER(10)";
} else {
intType = "INT";
}
return "ALTER TABLE "
+ rdbEngineStrategy.encloseFullTableName(NAMESPACE, TABLE)
+ " ADD "
+ rdbEngineStrategy.enclose(column)
+ " INT";
+ " "
+ intType;
}

private RdbEngineStrategy getRdbEngineStrategy(RdbEngine rdbEngine) {
Expand Down
4 changes: 2 additions & 2 deletions docs/schema-loader.md
Original file line number Diff line number Diff line change
Expand Up @@ -625,9 +625,9 @@ The following table shows the supported data types in ScalarDB and their mapping
| ScalarDB | Cassandra | Cosmos DB for NoSQL | DynamoDB | MySQL | PostgreSQL/YugabyteDB | Oracle | SQL Server | SQLite |
|-----------|-----------|---------------------|----------|----------|-----------------------|----------------|-----------------|---------|
| BOOLEAN | boolean | boolean (JSON) | BOOL | boolean | boolean | number(1) | bit | boolean |
| INT | int | number (JSON) | N | int | int | int | int | int |
| INT | int | number (JSON) | N | int | int | number(10) | int | int |
| BIGINT | bigint | number (JSON) | N | bigint | bigint | number(19) | bigint | bigint |
| FLOAT | float | number (JSON) | N | double | float | binary_float | float(24) | float |
| FLOAT | float | number (JSON) | N | real | real | binary_float | float(24) | float |
| DOUBLE | double | number (JSON) | N | double | double precision | binary_double | float | double |
| TEXT | text | string (JSON) | S | longtext | text | varchar2(4000) | varchar(8000) | text |
| BLOB | blob | string (JSON) | B | longblob | bytea | RAW(2000) | varbinary(8000) | blob |
Expand Down

0 comments on commit e6ea7b1

Please sign in to comment.