From e3d47238499b2d6a6bb18302a5083af375b150fb Mon Sep 17 00:00:00 2001 From: Ashin Gau Date: Tue, 9 May 2023 13:53:17 +0800 Subject: [PATCH] [fix](JDBC) set jdbc parameters to compatible with both MySQL and Doris when reading boolean type (#19399) Fix errors when read boolean type from external doris cluster by jdbc catalog: ``` ERROR 1105 (HY000): errCode = 2, detailMessage = (172.16.10.11)[INTERNAL_ERROR]Fail to convert jdbc type of java.lang.Integer to doris type BOOL on column: deleted. You need to check this column type between external table and doris table. ``` MySQL Types and Return Values for GetColumnTypeName and GetColumnClassName are presented in https://dev.mysql.com/doc/connector-j/8.0/en/connector-j-reference-type-conversions.html. 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 --- .../java/org/apache/doris/catalog/JdbcResource.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/JdbcResource.java b/fe/fe-core/src/main/java/org/apache/doris/catalog/JdbcResource.java index 2a736b4ddb..8ca7440988 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/catalog/JdbcResource.java +++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/JdbcResource.java @@ -308,10 +308,13 @@ public class JdbcResource extends Resource { // `yearIsDateType` is a parameter of JDBC, and the default is true. // We force the use of `yearIsDateType=false` newJdbcUrl = checkAndSetJdbcBoolParam(newJdbcUrl, "yearIsDateType", "true", "false"); - // `tinyInt1isBit` is a parameter of JDBC, and the default is true. - // We force the use of `tinyInt1isBit=false`, so that for mysql type tinyint, - // it will convert to Doris tinyint, not bit. - newJdbcUrl = checkAndSetJdbcBoolParam(newJdbcUrl, "tinyInt1isBit", "true", "false"); + // MySQL Types and Return Values for GetColumnTypeName and GetColumnClassName + // are presented in https://dev.mysql.com/doc/connector-j/8.0/en/connector-j-reference-type-conversions.html + // 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", "true", "true"); + newJdbcUrl = checkAndSetJdbcBoolParam(newJdbcUrl, "transformedBitIsBoolean", "true", "true"); // set useUnicode and characterEncoding to false and utf-8 newJdbcUrl = checkAndSetJdbcBoolParam(newJdbcUrl, "useUnicode", "false", "true"); newJdbcUrl = checkAndSetJdbcParam(newJdbcUrl, "characterEncoding", "utf-8");