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 a5248479ec9edec6b1a3331418975a8e6f720c45 Author: yongkang.zhong <[email protected]> AuthorDate: Wed May 10 21:53:30 2023 +0800 [fix](jdbc catalog) fix error to clickhouse uint64 type Conversion (#19463) * [fix](jdbc catalog) fix error to clickhouse uint64 type Conversion * add test case --- .../clickhouse/init/03-create-table.sql | 20 ++++++++++++++++ .../docker-compose/clickhouse/init/04-insert.sql | 6 +++++ .../java/org/apache/doris/udf/JdbcExecutor.java | 26 +++++++++++++++++---- .../test_clickhouse_jdbc_catalog.out | Bin 880 -> 1466 bytes .../test_clickhouse_jdbc_catalog.groovy | 1 + 5 files changed, 48 insertions(+), 5 deletions(-) diff --git a/docker/thirdparties/docker-compose/clickhouse/init/03-create-table.sql b/docker/thirdparties/docker-compose/clickhouse/init/03-create-table.sql index 4a8fceee3d..b6a7fb89f2 100644 --- a/docker/thirdparties/docker-compose/clickhouse/init/03-create-table.sql +++ b/docker/thirdparties/docker-compose/clickhouse/init/03-create-table.sql @@ -50,6 +50,26 @@ CREATE TABLE doris_test.type ENGINE = MergeTree ORDER BY k1; +CREATE TABLE doris_test.number +( + `k6` Float32, + `k7` Float64, + `k8` Int8, + `k9` Int16, + `k10` Int32, + `k11` Int64, + `k12` Int128, + `k13` Int256, + `k14` UInt8, + `k15` UInt16, + `k16` UInt32, + `k17` UInt64, + `k18` UInt128, + `k19` UInt256 +) + ENGINE = MergeTree +ORDER BY k6; + CREATE TABLE doris_test.student diff --git a/docker/thirdparties/docker-compose/clickhouse/init/04-insert.sql b/docker/thirdparties/docker-compose/clickhouse/init/04-insert.sql index d5df9baba1..a598e0f1d5 100644 --- a/docker/thirdparties/docker-compose/clickhouse/init/04-insert.sql +++ b/docker/thirdparties/docker-compose/clickhouse/init/04-insert.sql @@ -20,6 +20,12 @@ INSERT INTO doris_test.type VALUES INSERT INTO doris_test.type VALUES (false, '2022-01-02','2022-01-02','2022-01-02 00:00:00','2022-01-02 00:00:00.000000000',2.2,2.2,2,2,2,2,2,2,2,2,2,2,2,2,2.2,2.2,2.2,2.2,2,'116.253.40.133','2a02:aa08:e000:3100::2','61f0c404-5cb3-11e7-907b-a6006ad3dba0','String','T'); +INSERT INTO doris_test.number +(`k6`, `k7`, `k8`, `k9`, `k10`, `k11`, `k12`, `k13`, `k14`, `k15`, `k16`, `k17`, `k18`, `k19`) +VALUES + (-3.4028235e38, -1.7976931348623157e308, -128, -32768, -2147483648, -9223372036854775808, -170141183460469231731687303715884105728, -57896044618658097711785492504343953926634992332820282019728792003956564819968, 0, 0, 0, 0, 0, 0), + (3.4028235e38, 1.7976931348623157e308, 127, 32767, 2147483647, 9223372036854775807, 170141183460469231731687303715884105727, 57896044618658097711785492504343953926634992332820282019728792003956564819967, 255, 65535, 4294967295, 18446744073709551615, 340282366920938463463374607431768211455, 115792089237316195423570985008687907853269984665640564039457584007913129639935); + INSERT INTO doris_test.student values (1, 'doris', 18), (2, 'alice', 19), (3, 'bob', 20); INSERT INTO doris_test.arr values diff --git a/fe/java-udf/src/main/java/org/apache/doris/udf/JdbcExecutor.java b/fe/java-udf/src/main/java/org/apache/doris/udf/JdbcExecutor.java index 8e20d8cc4c..2dfb81020d 100644 --- a/fe/java-udf/src/main/java/org/apache/doris/udf/JdbcExecutor.java +++ b/fe/java-udf/src/main/java/org/apache/doris/udf/JdbcExecutor.java @@ -677,7 +677,7 @@ public class JdbcExecutor { private void bigIntegerPutToByte(Object[] column, boolean isNullable, int numRows, long nullMapAddr, long columnAddr, int startRowForNullable) { - if (isNullable == true) { + if (isNullable) { for (int i = startRowForNullable; i < numRows; i++) { if (column[i] == null) { UdfUtils.UNSAFE.putByte(nullMapAddr + i, (byte) 1); @@ -724,19 +724,35 @@ public class JdbcExecutor { copyBatchDecimalResult(data, isNullable, numRows, columnAddr, 16, startRowForNullable); } - private void clickHouseUInt64ToLong(Object[] column, boolean isNullable, int numRows, long nullMapAddr, + private void clickHouseUInt64ToByte(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.putLong(columnAddr + (i * 16L), ((UnsignedLong) column[i]).longValue()); + UnsignedLong columnValue = (UnsignedLong) column[i]; + BigInteger bigIntValue = columnValue.bigIntegerValue(); + byte[] bytes = UdfUtils.convertByteOrder(bigIntValue.toByteArray()); + byte[] value = new byte[16]; + if (bigIntValue.signum() == -1) { + Arrays.fill(value, (byte) -1); + } + System.arraycopy(bytes, 0, value, 0, Math.min(bytes.length, value.length)); + UdfUtils.copyMemory(value, UdfUtils.BYTE_ARRAY_OFFSET, null, columnAddr + (i * 16L), 16); } } } else { for (int i = 0; i < numRows; i++) { - UdfUtils.UNSAFE.putLong(columnAddr + (i * 16L), ((UnsignedLong) column[i]).longValue()); + UnsignedLong columnValue = (UnsignedLong) column[i]; + BigInteger bigIntValue = columnValue.bigIntegerValue(); + byte[] bytes = UdfUtils.convertByteOrder(bigIntValue.toByteArray()); + byte[] value = new byte[16]; + if (bigIntValue.signum() == -1) { + Arrays.fill(value, (byte) -1); + } + System.arraycopy(bytes, 0, value, 0, Math.min(bytes.length, value.length)); + UdfUtils.copyMemory(value, UdfUtils.BYTE_ARRAY_OFFSET, null, columnAddr + (i * 16L), 16); } } } @@ -758,7 +774,7 @@ public class JdbcExecutor { } else if (column[firstNotNullIndex] instanceof String) { stringPutToBigInteger(column, isNullable, numRows, nullMapAddr, columnAddr, firstNotNullIndex); } else if (column[firstNotNullIndex] instanceof com.clickhouse.data.value.UnsignedLong) { - clickHouseUInt64ToLong(column, isNullable, numRows, nullMapAddr, columnAddr, firstNotNullIndex); + clickHouseUInt64ToByte(column, isNullable, numRows, nullMapAddr, columnAddr, firstNotNullIndex); } } diff --git a/regression-test/data/jdbc_catalog_p0/test_clickhouse_jdbc_catalog.out b/regression-test/data/jdbc_catalog_p0/test_clickhouse_jdbc_catalog.out index 8efde34a30..2864fb4235 100644 Binary files a/regression-test/data/jdbc_catalog_p0/test_clickhouse_jdbc_catalog.out and b/regression-test/data/jdbc_catalog_p0/test_clickhouse_jdbc_catalog.out differ diff --git a/regression-test/suites/jdbc_catalog_p0/test_clickhouse_jdbc_catalog.groovy b/regression-test/suites/jdbc_catalog_p0/test_clickhouse_jdbc_catalog.groovy index 57d47c9469..fc13620288 100644 --- a/regression-test/suites/jdbc_catalog_p0/test_clickhouse_jdbc_catalog.groovy +++ b/regression-test/suites/jdbc_catalog_p0/test_clickhouse_jdbc_catalog.groovy @@ -54,6 +54,7 @@ suite("test_clickhouse_jdbc_catalog", "p0") { sql """ use ${ex_db_name} """ order_qt_type """ select * from type order by k1; """ + order_qt_number """ select * from number order by k6; """ order_qt_arr """ select * from arr order by id; """ sql """ insert into internal.${internal_db_name}.${inDorisTable} select * from student; """ order_qt_in_tb """ select id, name, age from internal.${internal_db_name}.${inDorisTable} order by id; """ --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
