From 241017bc1fa07a3faf7c6543ecc41905630bf03f Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Fri, 7 Aug 2020 02:52:18 +0300 Subject: [PATCH] Fix error in parseDateTimeBestEffort --- src/Common/BitHelpers.h | 2 ++ src/IO/parseDateTimeBestEffort.cpp | 1 + .../01432_parse_date_time_best_effort_timestamp.reference | 3 +++ .../01432_parse_date_time_best_effort_timestamp.sql | 3 +++ 4 files changed, 9 insertions(+) create mode 100644 tests/queries/0_stateless/01432_parse_date_time_best_effort_timestamp.reference create mode 100644 tests/queries/0_stateless/01432_parse_date_time_best_effort_timestamp.sql diff --git a/src/Common/BitHelpers.h b/src/Common/BitHelpers.h index 639a0c026ff..699e379b8d3 100644 --- a/src/Common/BitHelpers.h +++ b/src/Common/BitHelpers.h @@ -1,6 +1,7 @@ #pragma once #include +#include #include #include @@ -11,6 +12,7 @@ */ inline unsigned int bitScanReverse(unsigned int x) { + assert(x != 0); return sizeof(unsigned int) * 8 - 1 - __builtin_clz(x); } diff --git a/src/IO/parseDateTimeBestEffort.cpp b/src/IO/parseDateTimeBestEffort.cpp index c350bd1ddc1..d84ac76b164 100644 --- a/src/IO/parseDateTimeBestEffort.cpp +++ b/src/IO/parseDateTimeBestEffort.cpp @@ -104,6 +104,7 @@ ReturnType parseDateTimeBestEffortImpl( return false; }; + res = 0; UInt16 year = 0; UInt8 month = 0; UInt8 day_of_month = 0; diff --git a/tests/queries/0_stateless/01432_parse_date_time_best_effort_timestamp.reference b/tests/queries/0_stateless/01432_parse_date_time_best_effort_timestamp.reference new file mode 100644 index 00000000000..36cee487d54 --- /dev/null +++ b/tests/queries/0_stateless/01432_parse_date_time_best_effort_timestamp.reference @@ -0,0 +1,3 @@ +2020-08-07 01:29:00 +1973-03-03 12:46:40 +2020-08-07 00:00:00 diff --git a/tests/queries/0_stateless/01432_parse_date_time_best_effort_timestamp.sql b/tests/queries/0_stateless/01432_parse_date_time_best_effort_timestamp.sql new file mode 100644 index 00000000000..071fefe0403 --- /dev/null +++ b/tests/queries/0_stateless/01432_parse_date_time_best_effort_timestamp.sql @@ -0,0 +1,3 @@ +SELECT parseDateTimeBestEffort('1596752940', 'Europe/Moscow'); +SELECT parseDateTimeBestEffort('100000000', 'Europe/Moscow'); +SELECT parseDateTimeBestEffort('20200807', 'Europe/Moscow');