diff --git a/src/IO/ReadHelpers.h b/src/IO/ReadHelpers.h index 48c291d8fcc..e68da3a1c7d 100644 --- a/src/IO/ReadHelpers.h +++ b/src/IO/ReadHelpers.h @@ -867,7 +867,8 @@ inline ReturnType readDateTimeTextImpl(time_t & datetime, ReadBuffer & buf, cons UInt8 minute = 0; UInt8 second = 0; ///simply determine whether it is YYYY-MM-DD hh:mm:ss or YYYY-MM-DD by the content of the tenth character in an optimistic scenario - if (s[10] == ' ') + bool dt_long = (s[10] == ' ' || s[10] == 'T'); + if (dt_long) { hour = (s[11] - '0') * 10 + (s[12] - '0'); minute = (s[14] - '0') * 10 + (s[15] - '0'); @@ -879,7 +880,7 @@ inline ReturnType readDateTimeTextImpl(time_t & datetime, ReadBuffer & buf, cons else datetime = date_lut.makeDateTime(year, month, day, hour, minute, second); - if (s[10] == ' ') + if (dt_long) buf.position() += DateTimeStringInputSize; else buf.position() += DateStringInputSize; diff --git a/tests/queries/0_stateless/02249_parse_date_time_basic.reference b/tests/queries/0_stateless/02249_parse_date_time_basic.reference index d67e0ae15e0..027c72d802f 100644 --- a/tests/queries/0_stateless/02249_parse_date_time_basic.reference +++ b/tests/queries/0_stateless/02249_parse_date_time_basic.reference @@ -1,3 +1,5 @@ -2022-03-31 00:00:00 1 -2022-04-01 17:10:24 2 -2022-03-31 10:18:56 3 +2022-03-31T04:00:00Z 1 +2022-04-01T09:10:24Z 2 +2022-03-31T14:18:56Z 3 +2022-03-31T14:18:56Z 4 +2022-04-01T09:10:24Z 5 diff --git a/tests/queries/0_stateless/02249_parse_date_time_basic.sql b/tests/queries/0_stateless/02249_parse_date_time_basic.sql index 2cea41874d5..cb443bbdd8e 100644 --- a/tests/queries/0_stateless/02249_parse_date_time_basic.sql +++ b/tests/queries/0_stateless/02249_parse_date_time_basic.sql @@ -1,6 +1,10 @@ +SET date_time_output_format='iso'; drop table if exists t; CREATE TABLE t (a DateTime, b String, c String, d String, e Int32) ENGINE = Memory; INSERT INTO t(a, b, c, d ,e) VALUES ('2022-03-31','','','',1); INSERT INTO t(a, b, c, d ,e) VALUES (1648804224,'','','',2); INSERT INTO t(a, b, c, d ,e) VALUES ('2022-03-31 10:18:56','','','',3); -select a, e from t; +INSERT INTO t(a, b, c, d ,e) VALUES ('2022-03-31T10:18:56','','','',4); +INSERT INTO t(a, b, c, d ,e) VALUES ('1648804224','','','',5); +select a, e from t order by e; +drop table if exists t;