From a61fd73c882ab7b2c852fde8e8eddf2bb5181ada Mon Sep 17 00:00:00 2001 From: zvonand Date: Thu, 25 Aug 2022 00:26:44 +0300 Subject: [PATCH] fix test fails --- src/Functions/CustomWeekTransforms.h | 21 ++------ src/Functions/FunctionsConversion.h | 24 ++++++---- .../0_stateless/00941_to_custom_week.sql | 1 - .../01440_to_date_monotonicity.reference | 2 +- .../01921_datatype_date32.reference | 48 +++++++++---------- .../02403_date_time_narrowing.reference | 2 +- .../0_stateless/02403_date_time_narrowing.sql | 12 ++--- 7 files changed, 50 insertions(+), 60 deletions(-) diff --git a/src/Functions/CustomWeekTransforms.h b/src/Functions/CustomWeekTransforms.h index 3f520d12420..3fd5cd07824 100644 --- a/src/Functions/CustomWeekTransforms.h +++ b/src/Functions/CustomWeekTransforms.h @@ -65,12 +65,7 @@ struct ToStartOfWeekImpl if (t < 0) return 0; - auto res = time_zone.toFirstDayNumOfWeek(DayNum(std::min(time_t(time_zone.toDayNum(t)), time_t(DATE_LUT_MAX_DAY_NUM))), week_mode); - - if (res > time_zone.toDayNum(t)) - return 0; - else - return res; + return time_zone.toFirstDayNumOfWeek(DayNum(std::min(time_t(time_zone.toDayNum(t)), time_t(DATE_LUT_MAX_DAY_NUM))), week_mode); } static inline UInt16 execute(UInt32 t, UInt8 week_mode, const DateLUTImpl & time_zone) { @@ -81,21 +76,11 @@ struct ToStartOfWeekImpl if (d < 0) return 0; - auto res = time_zone.toFirstDayNumOfWeek(DayNum(std::min(d, DATE_LUT_MAX_DAY_NUM)), week_mode); - - if (res > d) - return 0; - else - return res; + return time_zone.toFirstDayNumOfWeek(DayNum(std::min(d, DATE_LUT_MAX_DAY_NUM)), week_mode); } static inline UInt16 execute(UInt16 d, UInt8 week_mode, const DateLUTImpl & time_zone) { - auto res = time_zone.toFirstDayNumOfWeek(d, week_mode); - - if (res > d) - return 0; - else - return res; + return time_zone.toFirstDayNumOfWeek(DayNum(d), week_mode); } using FactorTransform = ZeroTransform; diff --git a/src/Functions/FunctionsConversion.h b/src/Functions/FunctionsConversion.h index b60f9f739f5..7a94e42d330 100644 --- a/src/Functions/FunctionsConversion.h +++ b/src/Functions/FunctionsConversion.h @@ -379,8 +379,9 @@ struct ToDateTransform32Or64 if (from < 0) return 0; - auto day_num = time_zone.toDayNum(from); - return day_num < DATE_LUT_MAX_DAY_NUM ? day_num : DATE_LUT_MAX_DAY_NUM; + return (from < DATE_LUT_MAX_DAY_NUM) + ? from + : std::min(UInt64(time_zone.toDayNum(from)), UInt64(DATE_LUT_MAX_DAY_NUM)); } }; @@ -398,6 +399,11 @@ struct ToDateTransform32Or64Signed auto day_num = time_zone.toDayNum(ExtendedDayNum(from)); return day_num < DATE_LUT_MAX_DAY_NUM ? day_num : DATE_LUT_MAX_DAY_NUM; + + return (from < DATE_LUT_MAX_DAY_NUM) + ? from + : std::min(UInt64(time_zone.toDayNum(from)), UInt64(0xFFFFFFFF)); + } }; @@ -426,7 +432,9 @@ struct ToDate32Transform32Or64 static inline NO_SANITIZE_UNDEFINED ToType execute(const FromType & from, const DateLUTImpl & time_zone) { - return std::min(time_t(time_zone.toDayNum(from)), time_t(DATE_LUT_MAX_EXTEND_DAY_NUM)); + return (from < DATE_LUT_MAX_EXTEND_DAY_NUM) + ? from + : std::min(UInt64(time_zone.toDayNum(from)), UInt64(DATE_LUT_MAX_EXTEND_DAY_NUM)); } }; @@ -442,7 +450,7 @@ struct ToDate32Transform32Or64Signed return daynum_min_offset; return (from < DATE_LUT_MAX_EXTEND_DAY_NUM) ? from - : time_zone.toDayNum(std::min(time_t(from), time_t(0xFFFFFFFF))); + : time_zone.toDayNum(std::min(Int64(from), Int64(0xFFFFFFFF))); } }; @@ -544,14 +552,12 @@ struct ToDateTimeTransform64Signed { static constexpr auto name = "toDateTime"; - static inline NO_SANITIZE_UNDEFINED ToType execute(const FromType & from, const DateLUTImpl & time_zone) + static inline NO_SANITIZE_UNDEFINED ToType execute(const FromType & from, const DateLUTImpl & /* time_zone */) { if (from < 0) return 0; - else if (time_zone.toDayNum(from) > DATE_LUT_MAX_DAY_NUM) - return DATE_LUT_MAX_DAY_NUM; - else - return time_t(from); + + return std::min(Int64(from), Int64(0xFFFFFFFF)); } }; diff --git a/tests/queries/0_stateless/00941_to_custom_week.sql b/tests/queries/0_stateless/00941_to_custom_week.sql index 4dd5d209306..04ff08d4117 100644 --- a/tests/queries/0_stateless/00941_to_custom_week.sql +++ b/tests/queries/0_stateless/00941_to_custom_week.sql @@ -49,4 +49,3 @@ SELECT toStartOfWeek(x, 3) AS w3, toStartOfWeek(x_t, 3) AS wt3 FROM numbers(10); - diff --git a/tests/queries/0_stateless/01440_to_date_monotonicity.reference b/tests/queries/0_stateless/01440_to_date_monotonicity.reference index 2dbec540fbb..dd8545b721d 100644 --- a/tests/queries/0_stateless/01440_to_date_monotonicity.reference +++ b/tests/queries/0_stateless/01440_to_date_monotonicity.reference @@ -1,4 +1,4 @@ 0 -1970-01-01 2106-02-07 1970-04-11 1970-01-01 2149-06-06 +1970-01-01 2120-07-26 1970-04-11 1970-01-01 2149-06-06 1970-01-01 02:00:00 2106-02-07 09:28:15 1970-01-01 02:16:40 2000-01-01 13:12:12 diff --git a/tests/queries/0_stateless/01921_datatype_date32.reference b/tests/queries/0_stateless/01921_datatype_date32.reference index acb0cc4ca59..a33a96ffffb 100644 --- a/tests/queries/0_stateless/01921_datatype_date32.reference +++ b/tests/queries/0_stateless/01921_datatype_date32.reference @@ -43,16 +43,16 @@ -------toMinute--------- -------toSecond--------- -------toStartOfDay--------- -2036-02-07 07:31:20 -2036-02-07 07:31:20 -2027-10-01 11:03:28 -2027-10-17 11:03:28 +1970-01-01 02:00:00 +1970-01-01 02:00:00 +2106-02-07 00:00:00 +2106-02-07 00:00:00 2021-06-22 00:00:00 -------toMonday--------- -2079-06-07 -2079-06-07 -2120-07-06 -2120-07-20 +1970-01-01 +1970-01-01 +2149-06-02 +2149-06-02 2021-06-21 -------toISOWeek--------- 1 @@ -79,28 +79,28 @@ 229953 202125 -------toStartOfWeek--------- -2079-06-06 -2079-06-06 -2120-07-05 -2120-07-26 +1970-01-01 +1970-01-01 +2149-06-01 +2149-06-01 2021-06-20 -------toStartOfMonth--------- -2079-06-07 -2079-06-07 -2120-06-26 -2120-06-26 +1970-01-01 +1970-01-01 +2149-06-01 +2149-06-01 2021-06-01 -------toStartOfQuarter--------- -2079-06-07 -2079-06-07 -2120-04-26 -2120-04-26 +1970-01-01 +1970-01-01 +2149-04-01 +2149-04-01 2021-04-01 -------toStartOfYear--------- -2079-06-07 -2079-06-07 -2119-07-28 -2119-07-28 +1970-01-01 +1970-01-01 +2149-01-01 +2149-01-01 2021-01-01 -------toStartOfSecond--------- -------toStartOfMinute--------- diff --git a/tests/queries/0_stateless/02403_date_time_narrowing.reference b/tests/queries/0_stateless/02403_date_time_narrowing.reference index 3d8e09ac5e1..1d97c361773 100644 --- a/tests/queries/0_stateless/02403_date_time_narrowing.reference +++ b/tests/queries/0_stateless/02403_date_time_narrowing.reference @@ -1,4 +1,4 @@ -1970-01-01 2149-06-06 1970-01-01 2149-06-06 1900-01-01 1970-01-02 1970-01-01 03:00:00 1970-01-01 21:12:15 +1970-01-01 2149-06-06 1970-01-01 2149-06-06 1900-01-01 1970-01-02 1970-01-01 00:00:00 2106-02-07 06:28:15 1970-01-01 2149-06-06 1970-01-01 2149-06-06 1970-01-01 00:00:00 2106-02-07 06:28:15 diff --git a/tests/queries/0_stateless/02403_date_time_narrowing.sql b/tests/queries/0_stateless/02403_date_time_narrowing.sql index ddadf507055..bcc35df5934 100644 --- a/tests/queries/0_stateless/02403_date_time_narrowing.sql +++ b/tests/queries/0_stateless/02403_date_time_narrowing.sql @@ -1,12 +1,12 @@ -- check conversion of numbers to date/time -- SELECT toDate(toInt32(toDate32('1930-01-01'))), toDate(toInt32(toDate32('2151-01-01'))), - toDate(toInt64(toDateTime64('1930-01-01 12:12:12.123', 3))), - toDate(toInt64(toDateTime64('2151-01-01 12:12:12.123', 3))), + toDate(toInt64(toDateTime64('1930-01-01 12:12:12.123', 3, 'UTC'))), + toDate(toInt64(toDateTime64('2151-01-01 12:12:12.123', 3, 'UTC'))), toDate32(toInt32(toDate32('1900-01-01')) - 1), toDate32(toInt32(toDate32('2299-12-31')) + 1), - toDateTime(toInt64(toDateTime64('1930-01-01 12:12:12.123', 3))), - toDateTime(toInt64(toDateTime64('2151-01-01 12:12:12.123', 3))); + toDateTime(toInt64(toDateTime64('1930-01-01 12:12:12.123', 3, 'UTC')), 'UTC'), + toDateTime(toInt64(toDateTime64('2151-01-01 12:12:12.123', 3, 'UTC')), 'UTC'); -- check conversion of extended range type to normal range type -- SELECT toDate(toDate32('1930-01-01')), @@ -34,8 +34,8 @@ SELECT toStartOfDay(toDate('2141-01-01', 'UTC'), 'UTC'), SELECT 'toStartOfWeek'; SELECT toStartOfWeek(toDate('1970-01-01')), toStartOfWeek(toDate32('1970-01-01')), - toStartOfWeek(toDateTime('1970-01-01 10:10:10')), - toStartOfWeek(toDateTime64('1970-01-01 10:10:10.123', 3)), + toStartOfWeek(toDateTime('1970-01-01 10:10:10', 'UTC')), + toStartOfWeek(toDateTime64('1970-01-01 10:10:10.123', 3, 'UTC')), toStartOfWeek(toDate32('1930-01-01')), toStartOfWeek(toDate32('2151-01-01')), toStartOfWeek(toDateTime64('1930-01-01 12:12:12.123', 3)),