This is an automated email from the ASF dual-hosted git repository.

morningman pushed a commit to branch branch-1.2-lts
in repository https://gitbox.apache.org/repos/asf/doris.git

commit ca4ba80ac926d767ae47ead92052ec61428e3e0a
Author: Tiewei Fang <43782773+bepppo...@users.noreply.github.com>
AuthorDate: Fri Feb 10 20:24:40 2023 +0800

    [Fix](Jdbc Catalog) jdbc catalog support to connect to doris database 
(#16527)
    
    Doris can use mysql-jdbc-jar to connect doris database, but doris has some 
data type that mysql without.
    Such as DecimalV3 and Date/DatetimeV2
    I add some case judgments in `Mysql Catalog` , so that Jdbc catalog can 
identify the data type of DORIS
---
 .../docker-compose/mysql/init/03-create-table.sql     | 19 +++++++++++++++++++
 .../org/apache/doris/external/jdbc/JdbcClient.java    | 10 ++++++++--
 .../data/jdbc_catalog_p0/test_mysql_jdbc_catalog.out  | 11 +++--------
 .../jdbc_catalog_p0/test_mysql_jdbc_catalog.groovy    |  8 ++++++--
 4 files changed, 36 insertions(+), 12 deletions(-)

diff --git a/docker/thirdparties/docker-compose/mysql/init/03-create-table.sql 
b/docker/thirdparties/docker-compose/mysql/init/03-create-table.sql
index 1847551d0e..b47ea6d169 100644
--- a/docker/thirdparties/docker-compose/mysql/init/03-create-table.sql
+++ b/docker/thirdparties/docker-compose/mysql/init/03-create-table.sql
@@ -229,3 +229,22 @@ create table doris_test.test_insert (
     `age` int NULL
 ) engine=innodb charset=utf8;
 
+
+create table doris_test.test_insert2 (
+    id varchar(128) NULL,
+    k1 boolean,
+    k2 char(100),
+    k3 varchar(128),
+    k4 date,
+    k5 float,
+    k6 tinyint,
+    k7 smallint,
+    k8 int,
+    k9 bigint,
+    k10 double,
+    k11 decimal(10, 3),
+    k12 time,
+    k13 year,
+    k14 datetime,
+    k15 timestamp
+) engine=innodb charset=utf8;
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/external/jdbc/JdbcClient.java 
b/fe/fe-core/src/main/java/org/apache/doris/external/jdbc/JdbcClient.java
index 159359e462..e5a925557f 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/external/jdbc/JdbcClient.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/external/jdbc/JdbcClient.java
@@ -360,7 +360,7 @@ public class JdbcClient {
                 case "INT":
                     return Type.BIGINT;
                 case "BIGINT":
-                    return ScalarType.createStringType();
+                    return Type.LARGEINT;
                 case "DECIMAL":
                     int precision = fieldSchema.getColumnSize() + 1;
                     int scale = fieldSchema.getDecimalDigits();
@@ -389,16 +389,21 @@ public class JdbcClient {
                 return Type.INT;
             case "BIGINT":
                 return Type.BIGINT;
+            case "LARGEINT": // for jdbc catalog connecting Doris database
+                return Type.LARGEINT;
             case "DATE":
+            case "DATEV2":
                 return ScalarType.getDefaultDateType(Type.DATE);
             case "TIMESTAMP":
             case "DATETIME":
+            case "DATETIMEV2": // for jdbc catalog connecting Doris database
                 return ScalarType.getDefaultDateType(Type.DATETIME);
             case "FLOAT":
                 return Type.FLOAT;
             case "DOUBLE":
                 return Type.DOUBLE;
             case "DECIMAL":
+            case "DECIMALV3": // for jdbc catalog connecting Doris database
                 int precision = fieldSchema.getColumnSize();
                 int scale = fieldSchema.getDecimalDigits();
                 if (precision <= ScalarType.MAX_DECIMAL128_PRECISION) {
@@ -413,8 +418,9 @@ public class JdbcClient {
                 ScalarType charType = 
ScalarType.createType(PrimitiveType.CHAR);
                 charType.setLength(fieldSchema.columnSize);
                 return charType;
-            case "TIME":
             case "VARCHAR":
+                return ScalarType.createVarcharType(fieldSchema.columnSize);
+            case "TIME":
             case "TINYTEXT":
             case "TEXT":
             case "MEDIUMTEXT":
diff --git a/regression-test/data/jdbc_catalog_p0/test_mysql_jdbc_catalog.out 
b/regression-test/data/jdbc_catalog_p0/test_mysql_jdbc_catalog.out
index 008815857f..0ef5ea238d 100644
--- a/regression-test/data/jdbc_catalog_p0/test_mysql_jdbc_catalog.out
+++ b/regression-test/data/jdbc_catalog_p0/test_mysql_jdbc_catalog.out
@@ -1,12 +1,4 @@
 -- This file is automatically generated. You should know what you did if you 
want to edit this
--- !db_amount --
-doris_test
-information_schema
-init_db
-mysql
-performance_schema
-sys
-
 -- !ex_tb0 --
 111    abc
 112    abd
@@ -169,6 +161,9 @@ doris2      19
 doris3 20
 doris3 20
 
+-- !test_insert4 --
+1      abcHa1.12345    1.123450xkalowadawd     2022-10-01      3.14159 1       
2       0       100000  1.2345678       24.000  07:09:51        2022    
2022-11-27T07:09:51     2022-11-27T07:09:51
+
 -- !ex_tb1 --
 {"k1":"v1", "k2":"v2"}
 
diff --git 
a/regression-test/suites/jdbc_catalog_p0/test_mysql_jdbc_catalog.groovy 
b/regression-test/suites/jdbc_catalog_p0/test_mysql_jdbc_catalog.groovy
index b97d4f20de..3dbfd3291d 100644
--- a/regression-test/suites/jdbc_catalog_p0/test_mysql_jdbc_catalog.groovy
+++ b/regression-test/suites/jdbc_catalog_p0/test_mysql_jdbc_catalog.groovy
@@ -46,6 +46,7 @@ suite("test_mysql_jdbc_catalog", "p0") {
         String ex_tb19 = "ex_tb19";
         String ex_tb20 = "ex_tb20";
         String test_insert = "test_insert";
+        String test_insert2 = "test_insert2";
 
         sql """ADMIN SET FRONTEND CONFIG ("enable_decimal_conversion" = 
"true");"""
         sql """drop catalog if exists ${catalog_name} """
@@ -72,8 +73,6 @@ suite("test_mysql_jdbc_catalog", "p0") {
         """
 
         sql """switch ${catalog_name}"""
-        qt_db_amount """ show databases; """
-
         sql """ use ${ex_db_name}"""
 
         order_qt_ex_tb0  """ select id, name from ${ex_tb0} order by id; """
@@ -113,6 +112,11 @@ suite("test_mysql_jdbc_catalog", "p0") {
         sql """ insert into ${test_insert} select * from ${test_insert} where 
id = '${uuid2}' """
         order_qt_test_insert3 """ select name, age from ${test_insert} where 
id = '${uuid2}' order by age """
 
+        String uuid3 = UUID.randomUUID().toString();
+        sql """ INSERT INTO ${test_insert2} VALUES
+                ('${uuid3}', true, 'abcHa1.12345', '1.123450xkalowadawd', 
'2022-10-01', 3.14159, 1, 2, 0, 100000, 1.2345678, 24.000, '07:09:51', '2022', 
'2022-11-27 07:09:51', '2022-11-27 07:09:51'); """
+        order_qt_test_insert4 """ select 
k1,k2,k3,k4,k5,k6,k7,k8,k9,k10,k11,k12,k13,k14,k15 from ${test_insert2} where 
id = '${uuid3}' """
+
         sql """ drop catalog if exists ${catalog_name} """
         sql """ drop resource if exists ${resource_name} """
 


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to