[fix](catalog) fix doris jdbc catalog largeint select error (#19407)

when I use mysql-jdbc 5.1.47 create a doris jdbc catalog, the largeint cannot select
When mysql-jdbc reads largeint, it will convert the format to string because it is too long

mysql> select `largeint` from type3;
ERROR 1105 (HY000): errCode = 2, detailMessage = (127.0.0.1)[INTERNAL_ERROR]Fail to convert jdbc type of java.lang.String to doris type LARGEINT on column: largeint. You need to check this column type between external table and doris table.
This commit is contained in:
yongkang.zhong
2023-05-09 17:34:48 +08:00
committed by GitHub
parent b07053f47d
commit 1bc405c06f
2 changed files with 17 additions and 1 deletions

View File

@ -279,7 +279,7 @@ Status JdbcConnector::_check_type(SlotDescriptor* slot_desc, const std::string&
case TYPE_BIGINT:
case TYPE_LARGEINT: {
if (type_str != "java.lang.Long" && type_str != "java.math.BigDecimal" &&
type_str != "java.math.BigInteger" &&
type_str != "java.math.BigInteger" && type_str != "java.lang.String" &&
type_str != "com.clickhouse.data.value.UnsignedInteger" &&
type_str != "com.clickhouse.data.value.UnsignedLong") {
return Status::InternalError(error_msg);

View File

@ -723,6 +723,20 @@ public class JdbcExecutor {
}
}
private void stringPutToBigInteger(Object[] column, boolean isNullable, int numRows, long nullMapAddr,
long columnAddr, int startRowForNullable) {
BigInteger[] data = new BigInteger[numRows];
for (int i = 0; i < numRows; i++) {
if (column[i] == null) {
data[i] = null;
UdfUtils.UNSAFE.putByte(nullMapAddr + i, (byte) 1);
} else {
data[i] = new BigInteger((String) column[i]);
}
}
copyBatchDecimalResult(data, isNullable, numRows, columnAddr, 16, startRowForNullable);
}
private void clickHouseUInt64ToLong(Object[] column, boolean isNullable, int numRows, long nullMapAddr,
long columnAddr, int startRowForNullable) {
if (isNullable) {
@ -754,6 +768,8 @@ public class JdbcExecutor {
bigDecimalPutToBigInteger(column, isNullable, numRows, nullMapAddr, columnAddr, firstNotNullIndex);
} else if (column[firstNotNullIndex] instanceof BigInteger) {
bigIntegerPutToByte(column, isNullable, numRows, nullMapAddr, columnAddr, firstNotNullIndex);
} 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);
}