This is an automated email from the ASF dual-hosted git repository. zykkk pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push: new 6f1c03c766 [fix](jdbc_catalog) fix int and bigint in mysql view when use doris catalog (#22251) 6f1c03c766 is described below commit 6f1c03c76640b3de1b0572dbcc809c9d95a61621 Author: lsy3993 <110876560+lsy3...@users.noreply.github.com> AuthorDate: Thu Jul 27 16:50:42 2023 +0800 [fix](jdbc_catalog) fix int and bigint in mysql view when use doris catalog (#22251) --- be/src/vec/exec/vjdbc_connector.cpp | 2 +- .../docker-compose/mysql/init/03-create-table.sql | 6 +++++- .../java/org/apache/doris/jdbc/JdbcExecutor.java | 20 ++++++++++++++++++++ .../data/jdbc_catalog_p0/test_mysql_jdbc_catalog.out | 3 +++ .../jdbc_catalog_p0/test_mysql_jdbc_catalog.groovy | 13 +++++++++++++ 5 files changed, 42 insertions(+), 2 deletions(-) diff --git a/be/src/vec/exec/vjdbc_connector.cpp b/be/src/vec/exec/vjdbc_connector.cpp index cfdbcbc185..f9181c559a 100644 --- a/be/src/vec/exec/vjdbc_connector.cpp +++ b/be/src/vec/exec/vjdbc_connector.cpp @@ -273,7 +273,7 @@ Status JdbcConnector::_check_type(SlotDescriptor* slot_desc, const std::string& if (type_str != "java.lang.Short" && type_str != "java.lang.Integer" && type_str != "java.math.BigDecimal" && type_str != "java.lang.Byte" && type_str != "com.clickhouse.data.value.UnsignedByte" && - type_str != "com.clickhouse.data.value.UnsignedShort") { + type_str != "com.clickhouse.data.value.UnsignedShort" && type_str != "java.lang.Long") { return Status::InternalError(error_msg); } break; 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 0b013c827a..0b5b6bb636 100644 --- a/docker/thirdparties/docker-compose/mysql/init/03-create-table.sql +++ b/docker/thirdparties/docker-compose/mysql/init/03-create-table.sql @@ -303,4 +303,8 @@ CREATE TABLE doris_test.dt ( CREATE TABLE doris_test.dt_null ( `dt` datetime NOT NULL -) ENGINE=INNODB CHARSET=utf8; \ No newline at end of file +) ENGINE=INNODB CHARSET=utf8; + +CREATE VIEW doris_test.mysql_view as +select 10086 as col_1, 4294967295 as col_2, tinyint_u as col_3 from doris_test.all_types where tinyint_u=201; + diff --git a/fe/be-java-extensions/jdbc-scanner/src/main/java/org/apache/doris/jdbc/JdbcExecutor.java b/fe/be-java-extensions/jdbc-scanner/src/main/java/org/apache/doris/jdbc/JdbcExecutor.java index 3b7c9a79aa..54506679a3 100644 --- a/fe/be-java-extensions/jdbc-scanner/src/main/java/org/apache/doris/jdbc/JdbcExecutor.java +++ b/fe/be-java-extensions/jdbc-scanner/src/main/java/org/apache/doris/jdbc/JdbcExecutor.java @@ -742,6 +742,23 @@ public class JdbcExecutor { } } + private void longPutToInt(Object[] column, boolean isNullable, int numRows, long nullMapAddr, + long columnAddr, int startRowForNullable) { + if (isNullable) { + for (int i = startRowForNullable; i < numRows; i++) { + if (column[i] == null) { + UdfUtils.UNSAFE.putByte(nullMapAddr + i, (byte) 1); + } else { + UdfUtils.UNSAFE.putInt(columnAddr + (i * 4L), ((Long) column[i]).intValue()); + } + } + } else { + for (int i = 0; i < numRows; i++) { + UdfUtils.UNSAFE.putInt(columnAddr + (i * 4L), ((Long) column[i]).intValue()); + } + } + } + public void clickHouseUInt16ToInt(Object[] column, boolean isNullable, int numRows, long nullMapAddr, long columnAddr, int startRowForNullable) { if (isNullable) { @@ -775,6 +792,9 @@ public class JdbcExecutor { integerPutToInt(column, isNullable, numRows, nullMapAddr, columnAddr, firstNotNullIndex); } else if (column[firstNotNullIndex] instanceof com.clickhouse.data.value.UnsignedShort) { clickHouseUInt16ToInt(column, isNullable, numRows, nullMapAddr, columnAddr, firstNotNullIndex); + } else if (column[firstNotNullIndex] instanceof java.lang.Long) { + // For mysql view. But don't worry about overflow + longPutToInt(column, isNullable, numRows, nullMapAddr, columnAddr, firstNotNullIndex); } } 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 e0ec83151a..81ce6f369b 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 @@ -301,3 +301,6 @@ sys 202 302 402 502 602 4.14159 5.1415926 6.14159 0 -124 -302 2013 -402 -502 -602 2012-11-01 2012-10-26T02:08:39.345700 2013-10-26T08:09:18 -5.14145 -6.1400000001 -7.1400 row2 line2 09:11:09.567 text2 0xE86F6C6C6F20576F726C67 {"age":18,"city":"ChongQing","name":"Gaoxin"} Option1,Option2 0x2F 0x58676C6C6F00000000000000 0x88656C6C9F Value3 203 303 403 503 603 7.14159 8.1415926 9.14159 0 \N -402 2017 -602 -902 -1102 2012-11-02 \N 2013-10-27T08:11:18 -5.14145 -6.1400000000001 -7.1400 row3 line3 09:11:09.567 text3 0xE86F6C6C6F20576F726C67 {"age":24,"city":"ChongQing","name":"ChenQi"} Option2 0x2F 0x58676C6C6F00000000000000 \N Value1 +-- !mysql_view -- +10086 4294967295 201 + 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 2e2da519c6..b37c83bba6 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 @@ -220,5 +220,18 @@ suite("test_mysql_jdbc_catalog", "p0") { qt_mysql_all_types """select * from all_types order by tinyint_u;""" sql """ drop catalog if exists ${catalog_name} """ + + // test mysql view + sql """ CREATE CATALOG view_catalog PROPERTIES ( + "type"="jdbc", + "jdbc.user"="root", + "jdbc.password"="123456", + "jdbc.jdbc_url" = "jdbc:mysql://127.0.0.1:${mysql_port}/doris_test?useSSL=false", + "jdbc.driver_url" = "https://doris-community-test-1308700295.cos.ap-hongkong.myqcloud.com/jdbc_driver/mysql-connector-java-8.0.25.jar", + "jdbc.driver_class" = "com.mysql.cj.jdbc.Driver"); + """ + qt_mysql_view """ select * from view_catalog.doris_test.mysql_view order by col_1;""" + sql """ drop catalog if exists view_catalog; """ } } + --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org