[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
This commit is contained in:
Ashin Gau
2023-05-09 13:53:17 +08:00
committed by GitHub
parent 729cd319f1
commit e3d4723849

View File

@ -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");