Merge pull request #11653 from ClickHouse/parse-date-time-best-effort-incompletely-parsed-value

Return NULL or zero when value is not parsed completely in parseDateTimeBestEffortOr* functions
This commit is contained in:
alexey-milovidov 2020-06-14 10:59:10 +03:00 committed by GitHub
commit 88cf3f7083
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 25 additions and 7 deletions

View File

@ -722,10 +722,10 @@ struct ConvertThroughParsing
parsed = ToDataType::tryReadText(vec_to[i], read_buffer, ToDataType::maxPrecision(), vec_to.getScale());
else
parsed = tryParseImpl<ToDataType>(vec_to[i], read_buffer, local_time_zone);
parsed = parsed && isAllRead(read_buffer);
}
parsed = parsed && isAllRead(read_buffer);
if (!parsed)
vec_to[i] = 0;

View File

@ -13,7 +13,7 @@
11 Feb 2018 06:40:50 +0300 2018-02-11 03:40:50 2018-02-11 03:40:50
17 Apr 2 1:2:3 2000-04-17 01:02:03 2000-04-17 01:02:03
19700102 01:00:00 1970-01-02 01:00:00 1970-01-02 01:00:00
1970010201:00:00 2032-06-06 02:03:21 2032-06-06 02:03:21
1970010201:00:00 ᴺᵁᴸᴸ 0000-00-00 00:00:00
19700102010203 1970-01-02 01:02:03 1970-01-02 01:02:03
19700102010203Z 1970-01-02 01:02:03 1970-01-02 01:02:03
1970/01/02 010203Z 1970-01-02 01:02:03 1970-01-02 01:02:03
@ -61,7 +61,7 @@
2017/01/32 0000-00-00 00:00:00 0000-00-00 00:00:00
2017-01 MSD Jun 2017-05-31 20:00:00 2017-05-31 20:00:00
201701 MSD Jun 2017-05-31 20:00:00 2017-05-31 20:00:00
2017 25 1:2:3 0000-00-00 00:00:00 0000-00-00 00:00:00
2017 25 1:2:3 ᴺᵁᴸᴸ 0000-00-00 00:00:00
2017 25 Apr 1:2:3 2017-04-01 01:02:03 2017-04-01 01:02:03
2017 Apr 01 11:22:33 2017-04-01 11:22:33 2017-04-01 11:22:33
2017 Apr 02 01/02/03 UTC+0300 ᴺᵁᴸᴸ 0000-00-00 00:00:00
@ -74,8 +74,8 @@
2017 Apr 02 1:2:3 2017-04-02 01:02:03 2017-04-02 01:02:03
2017 Apr 02 1:2:33 2017-04-02 01:02:33 2017-04-02 01:02:33
2017 Apr 02 1:2:3 MSK 2017-04-01 22:02:03 2017-04-01 22:02:03
2017 Apr 02 1:2:3 MSK 2017 2017-04-01 22:02:03 2017-04-01 22:02:03
2017 Apr 02 1:2:3 MSK 2018 2017-04-01 22:02:03 2017-04-01 22:02:03
2017 Apr 02 1:2:3 MSK 2017 ᴺᵁᴸᴸ 0000-00-00 00:00:00
2017 Apr 02 1:2:3 MSK 2018 ᴺᵁᴸᴸ 0000-00-00 00:00:00
2017 Apr 02 1:2:3 UTC+0000 2017-04-02 01:02:03 2017-04-02 01:02:03
2017 Apr 02 1:2:3 UTC+0300 2017-04-01 22:02:03 2017-04-01 22:02:03
2017 Apr 02 1:2:3 UTC+0400 2017-04-01 21:02:03 2017-04-01 21:02:03
@ -101,6 +101,6 @@
25 Jan 2017 1:2:3 Z PM 2017-01-25 13:02:03 2017-01-25 13:02:03
25 Jan 2017 1:2:3Z PM 2017-01-25 13:02:03 2017-01-25 13:02:03
25 Jan 2017 1:2:3 Z PM +03:00 2017-01-25 10:02:03 2017-01-25 10:02:03
Jun, 11 Feb 2018 06:40:50 +0300 2000-06-01 00:00:00 2000-06-01 00:00:00
Jun, 11 Feb 2018 06:40:50 +0300 ᴺᵁᴸᴸ 0000-00-00 00:00:00
Sun 11 Feb 2018 06:40:50 +0300 2018-02-11 03:40:50 2018-02-11 03:40:50
Sun, 11 Feb 2018 06:40:50 +0300 2018-02-11 03:40:50 2018-02-11 03:40:50

View File

@ -0,0 +1,6 @@
\N
0000-00-00 00:00:00
\N
0000-00-00 00:00:00.000
\N
0000-00-00 00:00:00

View File

@ -0,0 +1,12 @@
SELECT parseDateTimeBestEffort('<Empty>'); -- { serverError 6 }
SELECT parseDateTimeBestEffortOrNull('<Empty>');
SELECT parseDateTimeBestEffortOrZero('<Empty>');
SELECT parseDateTime64BestEffort('<Empty>'); -- { serverError 6 }
SELECT parseDateTime64BestEffortOrNull('<Empty>');
SELECT parseDateTime64BestEffortOrZero('<Empty>');
SET date_time_input_format = 'best_effort';
SELECT toDateTime('<Empty>'); -- { serverError 41 }
SELECT toDateTimeOrNull('<Empty>');
SELECT toDateTimeOrZero('<Empty>');