From 2a5c2b24420bea75a0ffbb1ece3b46caad64d708 Mon Sep 17 00:00:00 2001 From: zy-kkk Date: Wed, 8 Nov 2023 11:53:57 +0800 Subject: [PATCH] [fix](jdbc catalog) fix mysql zero date --- .../mysql/init/03-create-table.sql | 5 + .../docker-compose/mysql/init/04-insert.sql | 5 + docs/en/docs/lakehouse/multi-catalog/jdbc.md | 132 ++++++++---------- .../docs/lakehouse/multi-catalog/jdbc.md | 52 +++---- .../jdbc/client/JdbcMySQLClient.java | 3 + .../jdbc/test_mysql_jdbc_catalog.out | 4 + .../jdbc/test_mysql_jdbc_catalog.groovy | 2 + 7 files changed, 96 insertions(+), 107 deletions(-) diff --git a/docker/thirdparties/docker-compose/mysql/init/03-create-table.sql b/docker/thirdparties/docker-compose/mysql/init/03-create-table.sql index 4663ea2cf6ee45..ee44e1c87a2bf5 100644 --- a/docker/thirdparties/docker-compose/mysql/init/03-create-table.sql +++ b/docker/thirdparties/docker-compose/mysql/init/03-create-table.sql @@ -321,3 +321,8 @@ CREATE TABLE show_test_do_not_modify.ex_tb2 ( id int, count_value varchar(20) ); + +CREATE TABLE doris_test.test_zd ( +`id` int(10) unsigned NOT NULL, +`d_z` date NOT NULL +); diff --git a/docker/thirdparties/docker-compose/mysql/init/04-insert.sql b/docker/thirdparties/docker-compose/mysql/init/04-insert.sql index 93ae8c9b63e5ff..3ff51a9a123837 100644 --- a/docker/thirdparties/docker-compose/mysql/init/04-insert.sql +++ b/docker/thirdparties/docker-compose/mysql/init/04-insert.sql @@ -1152,3 +1152,8 @@ VALUES ('2023-06-17 10:00:00', '2023-06-17 10:00:01.1', '2023-06-17 10:00:02.22' SET SESSION sql_mode=(SELECT REPLACE(@@sql_mode,'STRICT_TRANS_TABLES','')); INSERT INTO doris_test.dt_null VALUES ('2023-06-17 10:00:00'),('0000-00-00 00:00:00'); + +SET SESSION sql_mode=(SELECT REPLACE(@@sql_mode,'NO_ZERO_DATE','')); +SET SESSION sql_mode=(SELECT REPLACE(@@sql_mode,'NO_ZERO_IN_DATE','')); + +insert into doris_test.test_zd (id,d_z) VALUES (1,'0000-00-00'),(2,'2022-01-01'); diff --git a/docs/en/docs/lakehouse/multi-catalog/jdbc.md b/docs/en/docs/lakehouse/multi-catalog/jdbc.md index d62948460622b0..db41b033a49aac 100644 --- a/docs/en/docs/lakehouse/multi-catalog/jdbc.md +++ b/docs/en/docs/lakehouse/multi-catalog/jdbc.md @@ -695,60 +695,59 @@ DROP CATALOG ; SET NAMES utf8mb4 ``` -3. Why does the error message "CAUSED BY: DataReadException: Zero date value prohibited" pop up when DateTime="0000:00:00 00:00:00" while reading MySQL external tables? +3. Exception occurs when reading MySQL date/datetime type - This error occurs because of an illegal DateTime. It can be fixed by modifying the `zeroDateTimeBehavior` parameter. - - The options for this parameter include: `EXCEPTION`,`CONVERT_TO_NULL`,`ROUND`. Respectively, they mean to report error, convert to null, and round the DateTime to "0001-01-01 00:00:00" when encountering an illegal DateTime. - - You can add `"jdbc_url"="jdbc:mysql://IP:PORT/doris_test?zeroDateTimeBehavior=convertToNull"` to the URL. - -4. Why do loading failures happen when reading MySQL or other external tables? + ``` + ERROR 1105 (HY000): errCode = 2, detailMessage = (10.16.10.6)[INTERNAL_ERROR]UdfRuntimeException: get next block failed: + CAUSED BY: SQLException: Zero date value prohibited + CAUSED BY: DataReadException: Zero date value prohibited + ``` - For example: + This is because the default handling of illegal Date/DateTime in JDBC is to throw an exception, and this behavior can be controlled through the parameter `zeroDateTimeBehavior`. - ``` - failed to load driver class com.mysql.jdbc.driver in either of hikariconfig class loader - ``` + The optional parameters are: `EXCEPTION`, `CONVERT_TO_NULL`, `ROUND`, respectively: exception error reporting, converted to NULL value, converted to "0001-01-01 00:00:00"; - Such errors occur because the `driver_class` has been wrongly put when creating the catalog. The problem with the above example is the letter case. It should be corrected as `"driver_class" = "com.mysql.jdbc.Driver"`. + You need to add `zeroDateTimeBehavior=convertToNull` to the end of the JDBC connection string when creating the Catalog `jdbc_url`, such as `"jdbc_url" = "jdbc:mysql://127.0.0.1:3306/test?zeroDateTimeBehavior=convertToNull"` + In this case, JDBC will convert 0000-00-00 or 0000-00-00 00:00:00 into null, and then Doris will process all Date/DateTime type columns in the current Catalog as nullable types, so that It can be read normally. -5. There is a communication link exception in reading MySQL +4. When reading the MySQL table or other tables, a class loading failure occurs. - If you run into the following errors: + Such as the following exception: - ``` - ERROR 1105 (HY000): errCode = 2, detailMessage = PoolInitializationException: Failed to initialize pool: Communications link failure - - The last packet successfully received from the server was 7 milliseconds ago. The last packet sent successfully to the server was 4 milliseconds ago. - CAUSED BY: CommunicationsException: Communications link failure - - The last packet successfully received from the server was 7 milliseconds ago. The last packet sent successfully to the server was 4 milliseconds ago. - CAUSED BY: SSLHandshakeExcepti - ``` + ``` + failed to load driver class com.mysql.jdbc.driver in either of hikariconfig class loader + ``` - Please check the be.out log of BE. + This is because when creating the catalog, the driver_class filled in is incorrect and needs to be filled in correctly. For example, the above example has a case problem and should be filled in as `"driver_class" = "com.mysql.jdbc.Driver"` - If it contains the following message: +5. Communication link abnormality occurs when reading MySQL - ``` - WARN: Establishing SSL connection without server's identity verification is not recommended. - According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. - For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. - You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification. - ``` + If the following error occurs: - You can add `?useSSL=false` to the end of the JDBC connection string when creating Catalog. For example, `"jdbc_url" = "jdbc:mysql://127.0.0.1:3306/test?useSSL=false"`. + ``` + ERROR 1105 (HY000): errCode = 2, detailMessage = PoolInitializationException: Failed to initialize pool: Communications link failure + + The last packet successfully received from the server was 7 milliseconds ago. The last packet sent successfully to the server was 4 milliseconds ago. + CAUSED BY: CommunicationsException: Communications link failure + + The last packet successfully received from the server was 7 milliseconds ago. The last packet sent successfully to the server was 4 milliseconds ago. + CAUSED BY: SSLHandshakeExcepti + ``` -6. What to do with the `OutOfMemoryError` when querying MySQL databases? + You can view be’s be.out log - To reduce memory usage, Doris obtains one batch of query results at a time, and has a size limit for each batch. However, MySQL conducts one-off loading of all query results by default, which means the "loading in batches" method won't work. To solve this, you need to specify "jdbc_url"="jdbc:mysql://IP:PORT/doris_test?useCursorFetch=true" in the URL. + If the following information is included: -7. What to do with errors such as "CAUSED BY: SQLException OutOfMemoryError" when performing JDBC queries? + ``` + WARN: Establishing SSL connection without server's identity verification is not recommended. + According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. + For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. + You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification. + ``` - If you have set `useCursorFetch` for MySQL, you can increase the JVM memory limit by modifying the value of `jvm_max_heap_size` in be.conf. The current default value is 1024M. + You can add `?useSSL=false` to the end of the JDBC connection string when creating the Catalog, such as `"jdbc_url" = "jdbc:mysql://127.0.0.1:3306/test?useSSL=false"` -8. When using JDBC to query MySQL large data volume, if the query can occasionally succeed, occasionally report the following errors, and all the MySQL connections are completely disconnected when the error occurs: +6. When using JDBC to query large amounts of MYSQL data, if the query is occasionally successful, the following error will occasionally be reported. When this error occurs, all MYSQL connections are disconnected and cannot be connected to MYSQL SERVER. After a while, mysql returns to normal. , but the previous connections are gone: ``` ERROR 1105 (HY000): errCode = 2, detailMessage = [INTERNAL_ERROR]UdfRuntimeException: JDBC executor sql has error: @@ -756,35 +755,28 @@ DROP CATALOG ; The last packet successfully received from the server was 4,446 milliseconds ago. The last packet sent successfully to the server was 4,446 milliseconds ago. ``` - When the above phenomenon appears, it may be that mysql server's own memory or CPU resources are exhausted and the MySQL service is unavailable. You can try to increase the memory or CPU resources of MySQL Server. + When the above phenomenon occurs, it may be that Mysql Server's own memory or CPU resources are exhausted, causing the Mysql service to be unavailable. You can try to increase the memory or CPU configuration of Mysql Server. -9. If the results are inconsistent with those in the MYSQL database when you query the MYSQL database using JDBC +7. During the process of using JDBC to query MYSQL, if it is found that the query results are inconsistent with the query results in the MYSQL library - First check whether the string in the query field is case-sensitive. For example, there is a field c_1 in the Table with two - - data "aaa" and "AAA". If the MYSQL database is not case-sensitive when initializing the MYSQL database, mysql is - - case-insensitive by default, but Doris is strictly case-sensitive, so the following situations will occur: + First, check whether the string in the query field is case-sensitive. For example, there is a field c_1 in Table that contains two pieces of data: "aaa" and "AAA". If no distinguishing string is specified when initializing the MYSQL database, + Case, then MYSQL is not case-sensitive in strings by default, but in Doris it is strictly case-sensitive, so the following situations will occur: ``` - Mysql behavior: - select count(c_1) from table where c_1 = "aaa"; The string size is not distinguished, so the result is : 2 + Mysql behavior: + select count(c_1) from table where c_1 = "aaa"; The string size is not distinguished, so the result is: 2 - Doris behavior: - select count(c_1) from table where c_1 = "aaa"; Strictly delimit the string size, so the result is : 1 + Doris behavior: + select count(c_1) from table where c_1 = "aaa"; strictly distinguishes the string size, so the result is: 1 ``` - If the above phenomenon occurs, it needs to be adjusted according to demand, as follows: + If the above phenomenon occurs, it needs to be adjusted according to needs, as follows: - Add the "BINARY" keyword when querying in MYSQL to force case sensitivity : select count(c_1) from table where BINARY c_1 = - - "aaa"; Or specify it when creating a table in MYSQL : CREATE TABLE table ( c_1 VARCHAR(255) CHARACTER SET binary ); - - Or specify collation rules to be case sensitive when initializing the MYSQL database : character-set-server=UTF-8 and - - collation-server=utf8_bin. + Add the "BINARY" keyword to force case sensitivity when querying in MYSQL: select count(c_1) from table where BINARY c_1 = "aaa"; or specify when creating a table in MYSQL: + CREATE TABLE table ( c_1 VARCHAR(255) CHARACTER SET binary ); Or specify collation rules to make case sensitive when initializing the MYSQL database: + character-set-server=UTF-8 and collation-server=utf8_bin. -10. There is a communication link exception in reading SQLServer +8. Communication link abnormality occurs when reading SQL Server ``` ERROR 1105 (HY000): errCode = 2, detailMessage = (10.16.10.6)[CANCELLED][INTERNAL_ERROR]UdfRuntimeException: Initialize datasource failed: @@ -793,26 +785,16 @@ DROP CATALOG ; unable to find valid certification path to requested target". ClientConnectionId:a92f3817-e8e6-4311-bc21-7c66 ``` - In the create Catalog `jdbc_url` the JDBC connection string finally increase `encrypt=false`, such as `"jdbc_url" = "jdbc:sqlserver://127.0.0.1:1433;DataBaseName=doris_test;encrypt=false"` - -11. Error encountered when reading MySQL datetime type - - ``` - ERROR 1105 (HY000): errCode = 2, detailMessage = (10.16.10.6)[INTERNAL_ERROR]UdfRuntimeException: get next block failed: - CAUSED BY: SQLException: Zero date value prohibited - CAUSED BY: DataReadException: Zero date value prohibited - ``` + You can add `encrypt=false` to the end of the JDBC connection string when creating the Catalog, such as `"jdbc_url" = "jdbc:sqlserver://127.0.0.1:1433;DataBaseName=doris_test;encrypt=false"` - This happens because JDBC can't handle the datetime format 0000-00-00 00:00:00. - To address this, append zeroDateTimeBehavior=convertToNull to the jdbc_url when creating the Catalog, e.g., "jdbc_url" = "jdbc:mysql://127.0.0.1:3306/test?zeroDateTimeBehavior=convertToNull". - In this case, JDBC will convert 0000-00-00 00:00:00 to null, and then Doris will handle the DateTime column as a nullable type, allowing for successful reading. +9. `Non supported character set (add orai18n.jar in your classpath): ZHS16GBK` exception occurs when reading Oracle -12. `Non supported character set (add orai18n.jar in your classpath): ZHS16GBK` exception occurs when reading Oracle + Download [orai18n.jar](https://www.oracle.com/database/technologies/appdev/jdbc-downloads.html) and put it in the lib directory of Doris FE and the lib/java_extensions directory of BE (versions before Doris 2.0 It needs to be placed in the lib directory of BE). - Download [orai18n.jar](https://www.oracle.com/database/technologies/appdev/jdbc-downloads.html) and put it in the lib directory of Doris FE and the `lib/java_extensions/` directory of BE (Doris versions before 2.0 need to be placed in the lib directory of BE). + Starting from version 2.0.2, this file can be placed in the `custom_lib/` directory of FE and BE (if it does not exist, just create it manually) to prevent the file from being lost when the lib directory is replaced when upgrading the cluster. - Starting from version 2.0.2, this file can be placed in BE's `custom_lib/` directory (if it does not exist, just create it manually) to prevent the file from being lost due to the replacement of the lib directory when upgrading the cluster. +10. `NoClassDefFoundError: net/jpountz/lz4/LZ4Factory` error message appears when reading Clickhouse data through jdbc catalog -13. `NoClassDefFoundError: net/jpountz/lz4/LZ4Factory` exception occurs when reading Clickhouse data via jdbc catalog. + You can download the [lz4-1.3.0.jar](https://repo1.maven.org/maven2/net/jpountz/lz4/lz4/1.3.0/lz4-1.3.0.jar) package first, and then put it in DorisFE lib directory and BE's `lib/lib/java_extensions` directory (versions before Doris 2.0 need to be placed in BE's lib directory). - You can download the [lz4-1.3.0.jar](https://repo1.maven.org/maven2/net/jpountz/lz4/lz4/1.3.0/lz4-1.3.0.jar) package and put it into the DorisFE `lib` directory and the `lib/java_extensions` directory of BE (the version before Doris 2.0 should be put into the `lib` directory of BE). + Starting from version 2.0.2, this file can be placed in the `custom_lib/` directory of FE and BE (if it does not exist, just create it manually) to prevent the file from being lost due to the replacement of the lib directory when upgrading the cluster. \ No newline at end of file diff --git a/docs/zh-CN/docs/lakehouse/multi-catalog/jdbc.md b/docs/zh-CN/docs/lakehouse/multi-catalog/jdbc.md index ec3a37ab4275a6..2896b5c410a180 100644 --- a/docs/zh-CN/docs/lakehouse/multi-catalog/jdbc.md +++ b/docs/zh-CN/docs/lakehouse/multi-catalog/jdbc.md @@ -696,13 +696,20 @@ DROP CATALOG ; SET NAMES utf8mb4 ``` -3. 读 MySQL 外表时,DateTime="0000:00:00 00:00:00"异常报错: "CAUSED BY: DataReadException: Zero date value prohibited" +3. 读取 MySQL date/datetime 类型出现异常 + + ``` + ERROR 1105 (HY000): errCode = 2, detailMessage = (10.16.10.6)[INTERNAL_ERROR]UdfRuntimeException: get next block failed: + CAUSED BY: SQLException: Zero date value prohibited + CAUSED BY: DataReadException: Zero date value prohibited + ``` + + 这是因为JDBC中对于该非法的 Date/DateTime 默认处理为抛出异常,可以通过参数 `zeroDateTimeBehavior`控制该行为。 - 这是因为JDBC中对于该非法的DateTime默认处理为抛出异常,可以通过参数 `zeroDateTimeBehavior`控制该行为。 - 可选参数为: `EXCEPTION`,`CONVERT_TO_NULL`,`ROUND`, 分别为:异常报错,转为NULL值,转为 "0001-01-01 00:00:00"; - - 可在url中添加: `"jdbc_url"="jdbc:mysql://IP:PORT/doris_test?zeroDateTimeBehavior=convertToNull"` + + 需要在创建 Catalog 的 `jdbc_url` 把JDBC连接串最后增加 `zeroDateTimeBehavior=convertToNull` ,如 `"jdbc_url" = "jdbc:mysql://127.0.0.1:3306/test?zeroDateTimeBehavior=convertToNull"` + 这种情况下,JDBC 会把 0000-00-00 或者 0000-00-00 00:00:00 转换成 null,然后 Doris 会把当前 Catalog 的所有 Date/DateTime 类型的列按照可空类型处理,这样就可以正常读取了。 4. 读取 MySQL 外表或其他外表时,出现加载类失败 @@ -741,16 +748,7 @@ DROP CATALOG ; 可在创建 Catalog 的 `jdbc_url` 把JDBC连接串最后增加 `?useSSL=false` ,如 `"jdbc_url" = "jdbc:mysql://127.0.0.1:3306/test?useSSL=false"` -6. 查询MYSQL的数据库报OutOfMemoryError的错误 - - 为减少内存的使用,在获取结果集时,每次仅获取batchSize的大小,这样一批一批的获取结果。而MYSQL默认是一次将结果全部加载到内存, - 设置的按批获取无法生效,需要主动显示的在URL中指定:"jdbc_url"="jdbc:mysql://IP:PORT/doris_test?useCursorFetch=true" - -7. 在使用JDBC查询过程中时,如果出现"CAUSED BY: SQLException OutOfMemoryError" 类似的错误 - - 如果MYSQL已经主动设置useCursorFetch,可以在be.conf中修改jvm_max_heap_size的值,尝试增大JVM的内存,目前默认值为1024M。 - -8. 使用JDBC查询MYSQL大数据量时,如果查询偶尔能够成功,偶尔会报如下错误,且出现该错误时MYSQL的连接被全部断开,无法连接到MYSQL SERVER,过段时间后mysql又恢复正常,但是之前的连接都没了: +6. 使用JDBC查询MYSQL大数据量时,如果查询偶尔能够成功,偶尔会报如下错误,且出现该错误时MYSQL的连接被全部断开,无法连接到MYSQL SERVER,过段时间后mysql又恢复正常,但是之前的连接都没了: ``` ERROR 1105 (HY000): errCode = 2, detailMessage = [INTERNAL_ERROR]UdfRuntimeException: JDBC executor sql has error: @@ -760,7 +758,7 @@ DROP CATALOG ; 出现上述现象时,可能是Mysql Server自身的内存或CPU资源被耗尽导致Mysql服务不可用,可以尝试增大Mysql Server的内存或CPU配置。 -9. 使用JDBC查询MYSQL的过程中,如果发现和在MYSQL库的查询结果不一致的情况 +7. 使用JDBC查询MYSQL的过程中,如果发现和在MYSQL库的查询结果不一致的情况 首先要先排查下查询字段中是字符串否存在有大小写情况。比如,Table中有一个字段c_1中有"aaa"和"AAA"两条数据,如果在初始化MYSQL数据库时未指定区分字符串 大小写,那么MYSQL默认是不区分字符串大小写的,但是在Doris中是严格区分大小写的,所以会出现以下情况: @@ -779,7 +777,7 @@ DROP CATALOG ; CREATE TABLE table ( c_1 VARCHAR(255) CHARACTER SET binary ); 或者在初始化MYSQL数据库时指定校对规则来区分大小写: character-set-server=UTF-8 和 collation-server=utf8_bin。 -10. 读取 SQLServer 出现通信链路异常 +8. 读取 SQLServer 出现通信链路异常 ``` ERROR 1105 (HY000): errCode = 2, detailMessage = (10.16.10.6)[CANCELLED][INTERNAL_ERROR]UdfRuntimeException: Initialize datasource failed: @@ -790,24 +788,14 @@ DROP CATALOG ; 可在创建 Catalog 的 `jdbc_url` 把JDBC连接串最后增加 `encrypt=false` ,如 `"jdbc_url" = "jdbc:sqlserver://127.0.0.1:1433;DataBaseName=doris_test;encrypt=false"` -11. 读取 MySQL datetime 类型出现异常 - - ``` - ERROR 1105 (HY000): errCode = 2, detailMessage = (10.16.10.6)[INTERNAL_ERROR]UdfRuntimeException: get next block failed: - CAUSED BY: SQLException: Zero date value prohibited - CAUSED BY: DataReadException: Zero date value prohibited - ``` - - 这是因为 JDBC 并不能处理 0000-00-00 00:00:00 这种时间格式, - 需要在创建 Catalog 的 `jdbc_url` 把JDBC连接串最后增加 `zeroDateTimeBehavior=convertToNull` ,如 `"jdbc_url" = "jdbc:mysql://127.0.0.1:3306/test?zeroDateTimeBehavior=convertToNull"` - 这种情况下,JDBC 会把 0000-00-00 00:00:00 转换成 null,然后 Doris 会把 DateTime 类型的列按照可空类型处理,这样就可以正常读取了。 - -12. 读取 Oracle 出现 `Non supported character set (add orai18n.jar in your classpath): ZHS16GBK` 异常 +9. 读取 Oracle 出现 `Non supported character set (add orai18n.jar in your classpath): ZHS16GBK` 异常 下载 [orai18n.jar](https://www.oracle.com/database/technologies/appdev/jdbc-downloads.html) 并放到 Doris FE 的 lib 目录以及 BE 的 lib/java_extensions 目录 (Doris 2.0 之前的版本需放到 BE 的 lib 目录下) 下即可。 - 从 2.0.2 版本起,可以将这个文件放置在BE的 `custom_lib/` 目录下(如不存在,手动创建即可),以防止升级集群时因为 lib 目录被替换而导致文件丢失。 + 从 2.0.2 版本起,可以将这个文件放置在 FE 和 BE 的 `custom_lib/` 目录下(如不存在,手动创建即可),以防止升级集群时因为 lib 目录被替换而导致文件丢失。 -13. 通过jdbc catalog 读取Clickhouse数据出现`NoClassDefFoundError: net/jpountz/lz4/LZ4Factory` 错误信息 +10. 通过jdbc catalog 读取Clickhouse数据出现`NoClassDefFoundError: net/jpountz/lz4/LZ4Factory` 错误信息 可以先下载[lz4-1.3.0.jar](https://repo1.maven.org/maven2/net/jpountz/lz4/lz4/1.3.0/lz4-1.3.0.jar)包,然后放到DorisFE lib 目录以及BE 的 `lib/lib/java_extensions`目录中(Doris 2.0 之前的版本需放到 BE 的 lib 目录下)。 + + 从 2.0.2 版本起,可以将这个文件放置在 FE 和 BE 的 `custom_lib/` 目录下(如不存在,手动创建即可),以防止升级集群时因为 lib 目录被替换而导致文件丢失。 \ No newline at end of file diff --git a/fe/fe-core/src/main/java/org/apache/doris/datasource/jdbc/client/JdbcMySQLClient.java b/fe/fe-core/src/main/java/org/apache/doris/datasource/jdbc/client/JdbcMySQLClient.java index cb06722a05dbd9..61ba2a0db47d07 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/datasource/jdbc/client/JdbcMySQLClient.java +++ b/fe/fe-core/src/main/java/org/apache/doris/datasource/jdbc/client/JdbcMySQLClient.java @@ -265,6 +265,9 @@ protected Type jdbcTypeToDoris(JdbcFieldSchema fieldSchema) { case "BIGINT": return Type.BIGINT; case "DATE": + if (convertDateToNull) { + fieldSchema.setAllowNull(true); + } return ScalarType.createDateV2Type(); case "TIMESTAMP": case "DATETIME": { diff --git a/regression-test/data/external_table_p0/jdbc/test_mysql_jdbc_catalog.out b/regression-test/data/external_table_p0/jdbc/test_mysql_jdbc_catalog.out index d5cc90fa80f0d0..8fef1684317884 100644 --- a/regression-test/data/external_table_p0/jdbc/test_mysql_jdbc_catalog.out +++ b/regression-test/data/external_table_p0/jdbc/test_mysql_jdbc_catalog.out @@ -238,6 +238,10 @@ VIEWS \N 2023-06-17T10:00 +-- !test_dz -- +1 \N +2 2022-01-01 + -- !test_insert1 -- doris1 18 diff --git a/regression-test/suites/external_table_p0/jdbc/test_mysql_jdbc_catalog.groovy b/regression-test/suites/external_table_p0/jdbc/test_mysql_jdbc_catalog.groovy index d004d392377df7..6c68260857d7c6 100644 --- a/regression-test/suites/external_table_p0/jdbc/test_mysql_jdbc_catalog.groovy +++ b/regression-test/suites/external_table_p0/jdbc/test_mysql_jdbc_catalog.groovy @@ -59,6 +59,7 @@ suite("test_mysql_jdbc_catalog", "p0,external,mysql,external_docker,external_doc String auto_default_t = "auto_default_t"; String dt = "dt"; String dt_null = "dt_null"; + String test_zd = "test_zd" try_sql("DROP USER ${user}") sql """CREATE USER '${user}' IDENTIFIED BY '${pwd}'""" @@ -119,6 +120,7 @@ suite("test_mysql_jdbc_catalog", "p0,external,mysql,external_docker,external_doc order_qt_auto_default_t """insert into ${auto_default_t}(name) values('a'); """ order_qt_dt """select * from ${dt}; """ order_qt_dt_null """select * from ${dt_null} order by 1; """ + order_qt_test_dz """select * from ${test_zd} order by 1; """ // test insert String uuid1 = UUID.randomUUID().toString();