This is an automated email from the ASF dual-hosted git repository.
yiguolei 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 3a22af836e [fix](jdbc catalog) fix error to clickhouse uint64 type
Conversion (#19463)
3a22af836e is described below
commit 3a22af836e30ed4aebf62bb4fe8c535e98b36440
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 ea1a352da5..8ccb8c5a67 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
@@ -690,7 +690,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);
@@ -737,19 +737,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);
}
}
}
@@ -771,7 +787,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]