[fix](jdbc catalog) Fixed mappings with type errors for bool and tinyint(1) (#22089)

First of all, mysql does not have a boolean type, its boolean type is actually tinyint(1), in the previous logic, We force tinyint(1) to be a boolean by passing tinyInt1isBit=true, which causes an error if tinyint(1) is not a 0 or 1, Therefore, we need to match tinyint(1) according to tinyint instead of boolean, and this change will not affect the correctness of where k = 1 or where k = true queries
This commit is contained in:
zy-kkk
2023-07-25 22:45:22 +08:00
committed by GitHub
parent b2be42c31c
commit cf677b327b
8 changed files with 48 additions and 29 deletions

View File

@ -261,7 +261,8 @@ Status JdbcConnector::_check_type(SlotDescriptor* slot_desc, const std::string&
type_str, slot_desc->type().debug_string(), slot_desc->col_name());
switch (slot_desc->type().type) {
case TYPE_BOOLEAN: {
if (type_str != "java.lang.Boolean" && type_str != "java.lang.Byte") {
if (type_str != "java.lang.Boolean" && type_str != "java.lang.Byte" &&
type_str != "java.lang.Integer") {
return Status::InternalError(error_msg);
}
break;

View File

@ -266,7 +266,7 @@ create table doris_test.all_types (
`int` int,
`bigint` bigint,
`date` date,
`timestamp` timestamp(4),
`timestamp` timestamp(4) null,
`datetime` datetime,
`float` float,
`double` double,

View File

@ -167,7 +167,7 @@ CREATE CATALOG jdbc_mysql PROPERTIES (
| MYSQL Type | Doris Type | Comment |
|-------------------------------------------|----------------|-------------------------------------------------------------------------------|
| BOOLEAN | BOOLEAN | |
| BOOLEAN | TINYINT | |
| TINYINT | TINYINT | |
| SMALLINT | SMALLINT | |
| MEDIUMINT | INT | |

View File

@ -167,7 +167,7 @@ CREATE CATALOG jdbc_mysql PROPERTIES (
| MYSQL Type | Doris Type | Comment |
|-------------------------------------------|----------------|-------------------------------------------------|
| BOOLEAN | BOOLEAN | |
| BOOLEAN | TINYINT | |
| TINYINT | TINYINT | |
| SMALLINT | SMALLINT | |
| MEDIUMINT | INT | |

View File

@ -469,9 +469,8 @@ public class JdbcExecutor {
}
}
public void copyBatchBooleanResult(Object columnObj, boolean isNullable, int numRows, long nullMapAddr,
long columnAddr) {
Object[] column = (Object[]) columnObj;
public void booleanPutToByte(Object[] column, boolean isNullable, int numRows, long nullMapAddr, long columnAddr,
int startRow) {
if (isNullable) {
for (int i = 0; i < numRows; i++) {
if (column[i] == null) {
@ -487,6 +486,25 @@ public class JdbcExecutor {
}
}
public void copyBatchBooleanResult(Object columnObj, boolean isNullable, int numRows, long nullMapAddr,
long columnAddr) {
Object[] column = (Object[]) columnObj;
int firstNotNullIndex = 0;
if (isNullable) {
firstNotNullIndex = getFirstNotNullObject(column, numRows, nullMapAddr);
}
if (firstNotNullIndex == numRows) {
return;
}
if (column[firstNotNullIndex] instanceof Boolean) {
booleanPutToByte(column, isNullable, numRows, nullMapAddr, columnAddr, firstNotNullIndex);
} else if (column[firstNotNullIndex] instanceof Integer) {
integerPutToByte(column, isNullable, numRows, nullMapAddr, columnAddr, firstNotNullIndex);
} else if (column[firstNotNullIndex] instanceof Byte) {
bytePutToByte(column, isNullable, numRows, nullMapAddr, columnAddr, firstNotNullIndex);
}
}
private void bigDecimalPutToByte(Object[] column, boolean isNullable, int numRows, long nullMapAddr,
long columnAddr, int startRowForNullable) {
if (isNullable) {

View File

@ -303,7 +303,7 @@ public class JdbcResource extends Resource {
// However when tinyInt1isBit=false, GetColumnClassName of MySQL returns java.lang.Boolean,
// while that of Doris returns java.lang.Integer. In order to be compatible with both MySQL and Doris,
// Jdbc params should set tinyInt1isBit=true&transformedBitIsBoolean=true
newJdbcUrl = checkAndSetJdbcBoolParam(newJdbcUrl, "tinyInt1isBit", "false", "true");
newJdbcUrl = checkAndSetJdbcBoolParam(newJdbcUrl, "tinyInt1isBit", "true", "false");
newJdbcUrl = checkAndSetJdbcBoolParam(newJdbcUrl, "transformedBitIsBoolean", "false", "true");
// set useUnicode and characterEncoding to false and utf-8
newJdbcUrl = checkAndSetJdbcBoolParam(newJdbcUrl, "useUnicode", "false", "true");

View File

@ -81,14 +81,14 @@ b 1
c 1
-- !ex_tb13 --
张三0 11 1234567 123 321312 1999-02-13T00:00 中国 男 false
张三1 11 12345678 123 321312 1999-02-13T00:00 中国 男 false
张三2 11 12345671 123 321312 1999-02-13T00:00 中国 男 false
张三3 11 12345673 123 321312 1999-02-13T00:00 中国 男 false
张三4 11 123456711 123 321312 1999-02-13T00:00 中国 男 false
张三5 11 1232134567 123 321312 1999-02-13T00:00 中国 男 false
张三6 11 124314567 123 321312 1999-02-13T00:00 中国 男 false
张三7 11 123445167 123 321312 1998-02-13T00:00 中国 男 false
张三0 11 1234567 123 321312 1999-02-13T00:00 中国 男 0
张三1 11 12345678 123 321312 1999-02-13T00:00 中国 男 0
张三2 11 12345671 123 321312 1999-02-13T00:00 中国 男 0
张三3 11 12345673 123 321312 1999-02-13T00:00 中国 男 0
张三4 11 123456711 123 321312 1999-02-13T00:00 中国 男 0
张三5 11 1232134567 123 321312 1999-02-13T00:00 中国 男 0
张三6 11 124314567 123 321312 1999-02-13T00:00 中国 男 0
张三7 11 123445167 123 321312 1998-02-13T00:00 中国 男 0
-- !ex_tb14 --
123 2022-11-02 2022-11-02 8011 oppo
@ -275,7 +275,7 @@ doris3 20
doris3 20
-- !test_insert4 --
true 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
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
-- !specified_database_1 --
doris_test
@ -297,7 +297,7 @@ sys
-- !mysql_all_types --
\N 302 \N 502 602 4.14159 \N 6.14159 \N -124 -302 2013 -402 -502 -602 \N 2012-10-26T02:08:39.345700 2013-10-26T08:09:18 -5.14145 \N -7.1400 row2 \N 09:11:09.567 text2 0xe86f6c6c6f20576f726c67 \N \N 0x2f \N 0x88656c6c9f Value3
201 301 401 501 601 3.14159 4.1415926 5.14159 true -123 -301 2012 -401 -501 -601 2012-10-30 2012-10-25T12:05:36.345700 2012-10-25T08:08:08 -4.14145 -5.1400000001 -6.1400 row1 line1 09:09:09.567 text1 0x48656c6c6f20576f726c64 {"age":30,"city":"London","name":"Alice"} Option1,Option3 0x2a 0x48656c6c6f00000000000000 0x48656c6c6f Value2
202 302 402 502 602 4.14159 5.1415926 6.14159 false -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 false \N -402 2017 -602 -902 -1102 2012-11-02 2023-07-10T09:34:21.204900 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
201 301 401 501 601 3.14159 4.1415926 5.14159 1 -123 -301 2012 -401 -501 -601 2012-10-30 2012-10-25T12:05:36.345700 2012-10-25T08:08:08 -4.14145 -5.1400000001 -6.1400 row1 line1 09:09:09.567 text1 0x48656c6c6f20576f726c64 {"age":30,"city":"London","name":"Alice"} Option1,Option3 0x2a 0x48656c6c6f00000000000000 0x48656c6c6f Value2
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

View File

@ -98,14 +98,14 @@ b 1
c 1
-- !ex_tb13 --
张三0 11 1234567 123 321312 1999-02-13T00:00 中国 男 false
张三1 11 12345678 123 321312 1999-02-13T00:00 中国 男 false
张三2 11 12345671 123 321312 1999-02-13T00:00 中国 男 false
张三3 11 12345673 123 321312 1999-02-13T00:00 中国 男 false
张三4 11 123456711 123 321312 1999-02-13T00:00 中国 男 false
张三5 11 1232134567 123 321312 1999-02-13T00:00 中国 男 false
张三6 11 124314567 123 321312 1999-02-13T00:00 中国 男 false
张三7 11 123445167 123 321312 1998-02-13T00:00 中国 男 false
张三0 11 1234567 123 321312 1999-02-13T00:00 中国 男 0
张三1 11 12345678 123 321312 1999-02-13T00:00 中国 男 0
张三2 11 12345671 123 321312 1999-02-13T00:00 中国 男 0
张三3 11 12345673 123 321312 1999-02-13T00:00 中国 男 0
张三4 11 123456711 123 321312 1999-02-13T00:00 中国 男 0
张三5 11 1232134567 123 321312 1999-02-13T00:00 中国 男 0
张三6 11 124314567 123 321312 1999-02-13T00:00 中国 男 0
张三7 11 123445167 123 321312 1998-02-13T00:00 中国 男 0
-- !ex_tb14 --
123 2022-11-02 2022-11-02 8011 oppo
@ -259,7 +259,7 @@ doris3 20
doris3 20
-- !test_insert4 --
true 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
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"}