Skip to content

Commit

Permalink
[fix](jdbc catalog) fix mysql zero date (apache#26569)
Browse files Browse the repository at this point in the history
  • Loading branch information
zy-kkk committed Nov 12, 2023
1 parent 15d4404 commit 8dde524
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -326,3 +326,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
);
5 changes: 5 additions & 0 deletions docker/thirdparties/docker-compose/mysql/init/04-insert.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1154,3 +1154,8 @@ INSERT INTO doris_test.dt_null
VALUES ('2023-06-17 10:00:00'),('0000-00-00 00:00:00');

insert into doris_test.test_key_word values (1, 1), (2, 2);

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');
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,10 @@ VIEWS
\N
2023-06-17T10:00

-- !test_dz --
1 \N
2 2022-01-01

-- !test_insert1 --
doris1 18

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,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}'"""
Expand Down Expand Up @@ -163,6 +164,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();
Expand Down

0 comments on commit 8dde524

Please sign in to comment.