diff --git a/src/Common/DateLUTImpl.h b/src/Common/DateLUTImpl.h index 98df35b2dfa..a5a2b491a61 100644 --- a/src/Common/DateLUTImpl.h +++ b/src/Common/DateLUTImpl.h @@ -71,7 +71,7 @@ private: static inline LUTIndex normalizeLUTIndex(UInt32 index) { if (index >= DATE_LUT_SIZE) - LUTIndex(DATE_LUT_SIZE - 1); + return LUTIndex(DATE_LUT_SIZE - 1); return LUTIndex{index}; } @@ -80,7 +80,7 @@ private: if unlikely(index < 0 ) return LUTIndex(0); if (index >= DATE_LUT_SIZE) - LUTIndex(DATE_LUT_SIZE - 1); + return LUTIndex(DATE_LUT_SIZE - 1); return LUTIndex{index}; } @@ -93,7 +93,7 @@ private: template friend inline LUTIndex operator+(const T v, const LUTIndex & index) { - return normalizeLUTIndex(v + index.toUnderType()); + return normalizeLUTIndex(static_cast(v + index.toUnderType())); } friend inline LUTIndex operator+(const LUTIndex & index, const LUTIndex & v) diff --git a/tests/queries/0_stateless/01821_to_date_time_ubsan.reference b/tests/queries/0_stateless/01821_to_date_time_ubsan.reference index 0a762ec3b77..28c4987125c 100644 --- a/tests/queries/0_stateless/01821_to_date_time_ubsan.reference +++ b/tests/queries/0_stateless/01821_to_date_time_ubsan.reference @@ -1,2 +1,2 @@ -2283-11-11 23:48:05.4775806 -2283-11-11 23:52:48.54775806 +2299-12-31 23:48:05.4775806 +2299-12-31 23:52:48.54775806 diff --git a/tests/queries/0_stateless/01921_datatype_date32.reference b/tests/queries/0_stateless/01921_datatype_date32.reference index 70eebc76c01..acb0cc4ca59 100644 --- a/tests/queries/0_stateless/01921_datatype_date32.reference +++ b/tests/queries/0_stateless/01921_datatype_date32.reference @@ -1,19 +1,19 @@ -1925-01-01 -1925-01-01 -2282-12-31 -2283-11-11 +1900-01-01 +1900-01-01 +2299-12-15 +2299-12-31 2021-06-22 -------toYear--------- -1925 -1925 -2282 -2283 +1900 +1900 +2299 +2299 2021 -------toMonth--------- 1 1 12 -11 +12 6 -------toQuarter--------- 1 @@ -24,83 +24,83 @@ -------toDayOfMonth--------- 1 1 +15 31 -11 22 -------toDayOfWeek--------- -4 -4 -7 +1 +1 +5 7 2 -------toDayOfYear--------- 1 1 -365 -315 +349 +364 173 -------toHour--------- -------toMinute--------- -------toSecond--------- -------toStartOfDay--------- -2061-02-06 07:28:16 -2061-02-06 07:28:16 -2010-10-17 11:03:28 -2011-08-28 11:03:28 +2036-02-07 07:31:20 +2036-02-07 07:31:20 +2027-10-01 11:03:28 +2027-10-17 11:03:28 2021-06-22 00:00:00 -------toMonday--------- -2104-06-04 -2104-06-04 -2103-07-21 -2104-05-31 +2079-06-07 +2079-06-07 +2120-07-06 +2120-07-20 2021-06-21 -------toISOWeek--------- 1 1 +50 52 -45 25 -------toISOYear--------- -1925 -1925 -2282 -2283 +1900 +1900 +2299 +2299 2021 -------toWeek--------- 0 0 +50 53 -45 25 -------toYearWeek--------- -192452 -192452 -228253 -228345 +189953 +189953 +229950 +229953 202125 -------toStartOfWeek--------- -2104-06-03 -2104-06-03 -2103-07-27 -2104-06-06 +2079-06-06 +2079-06-06 +2120-07-05 +2120-07-26 2021-06-20 -------toStartOfMonth--------- -2104-06-07 -2104-06-07 -2103-06-27 -2104-05-27 +2079-06-07 +2079-06-07 +2120-06-26 +2120-06-26 2021-06-01 -------toStartOfQuarter--------- -2104-06-07 -2104-06-07 -2103-04-27 -2104-04-26 +2079-06-07 +2079-06-07 +2120-04-26 +2120-04-26 2021-04-01 -------toStartOfYear--------- -2104-06-07 -2104-06-07 -2102-07-28 -2103-07-28 +2079-06-07 +2079-06-07 +2119-07-28 +2119-07-28 2021-01-01 -------toStartOfSecond--------- -------toStartOfMinute--------- @@ -109,183 +109,183 @@ -------toStartOfFifteenMinutes--------- -------toStartOfHour--------- -------toStartOfISOYear--------- -2104-06-04 -2104-06-04 -2102-07-29 -2103-07-28 +2079-06-07 +2079-06-07 +2119-07-29 +2119-07-29 2021-01-04 -------toRelativeYearNum--------- -1925 -1925 -2282 -2283 +1900 +1900 +2299 +2299 2021 -------toRelativeQuarterNum--------- -7700 -7700 -9131 -9135 +7600 +7600 +9199 +9199 8085 -------toRelativeMonthNum--------- -23101 -23101 -27396 -27407 +22801 +22801 +27600 +27600 24258 -------toRelativeWeekNum--------- -63189 -63189 -16331 -63188 +61885 +61885 +17216 +17217 2686 -------toRelativeDayNum--------- -49100 -49100 -48784 -49099 +39969 +39969 +54977 +54993 18800 -------toRelativeHourNum--------- -4294572852 -4294572852 -2743677 -2751237 +4294353708 +4294353708 +2892309 +2892693 451197 -------toRelativeMinuteNum--------- -4271299336 -4271299336 -164620620 -165074220 +4258150699 +4258150699 +173538540 +173561580 27071820 -------toRelativeSecondNum--------- -2874889696 -2874889696 -1287302608 -1314518608 +2085971480 +2085971480 +1822377808 +1823760208 1624309200 -------toTime--------- -------toYYYYMM--------- -192501 -192501 -228212 -228311 +190001 +190001 +229912 +229912 202106 -------toYYYYMMDD--------- -19250101 -19250101 -22821231 -22831111 +19000101 +19000101 +22991215 +22991231 20210622 -------toYYYYMMDDhhmmss--------- -19250101000000 -19250101000000 -22821231000000 -22831111000000 +19000101000000 +19000101000000 +22991215000000 +22991231000000 20210622000000 -------addSeconds--------- -1925-01-01 01:00:00.000 -1925-01-01 01:00:00.000 -2282-12-31 01:00:00.000 -2283-11-11 01:00:00.000 +1900-01-01 01:00:00.000 +1900-01-01 01:00:00.000 +2299-12-15 01:00:00.000 +2299-12-31 01:00:00.000 2021-06-22 01:00:00.000 -------addMinutes--------- -1925-01-01 01:00:00.000 -1925-01-01 01:00:00.000 -2282-12-31 01:00:00.000 -2283-11-11 01:00:00.000 +1900-01-01 01:00:00.000 +1900-01-01 01:00:00.000 +2299-12-15 01:00:00.000 +2299-12-31 01:00:00.000 2021-06-22 01:00:00.000 -------addHours--------- -1925-01-01 01:00:00.000 -1925-01-01 01:00:00.000 -2282-12-31 01:00:00.000 -2283-11-11 01:00:00.000 +1900-01-01 01:00:00.000 +1900-01-01 01:00:00.000 +2299-12-15 01:00:00.000 +2299-12-31 01:00:00.000 2021-06-22 01:00:00.000 -------addDays--------- -1925-01-08 -1925-01-08 -2283-01-07 -1925-01-07 +1900-01-08 +1900-01-08 +2299-12-22 +2299-12-31 2021-06-29 -------addWeeks--------- -1925-01-08 -1925-01-08 -2283-01-07 -1925-01-07 +1900-01-08 +1900-01-08 +2299-12-22 +2299-12-31 2021-06-29 -------addMonths--------- -1925-02-01 -1925-02-01 -2283-01-31 -2283-11-11 +1900-02-01 +1900-02-01 +2299-12-31 +2299-12-31 2021-07-22 -------addQuarters--------- -1925-04-01 -1925-04-01 -2283-03-31 -2283-11-11 +1900-04-01 +1900-04-01 +2299-12-31 +2299-12-31 2021-09-22 -------addYears--------- -1926-01-01 -1926-01-01 -2283-11-11 -2283-11-11 +1901-01-01 +1901-01-01 +2299-12-31 +2299-12-31 2022-06-22 -------subtractSeconds--------- -1925-01-01 00:00:00.000 -1925-01-01 00:00:00.000 -2282-12-30 23:00:00.000 -2283-11-10 23:00:00.000 +1900-01-01 00:00:00.000 +1900-01-01 00:00:00.000 +2299-12-14 23:00:00.000 +2299-12-30 23:00:00.000 2021-06-21 23:00:00.000 -------subtractMinutes--------- -1925-01-01 00:00:00.000 -1925-01-01 00:00:00.000 -2282-12-30 23:00:00.000 -2283-11-10 23:00:00.000 +1900-01-01 00:00:00.000 +1900-01-01 00:00:00.000 +2299-12-14 23:00:00.000 +2299-12-30 23:00:00.000 2021-06-21 23:00:00.000 -------subtractHours--------- -1925-01-01 00:00:00.000 -1925-01-01 00:00:00.000 -2282-12-30 23:00:00.000 -2283-11-10 23:00:00.000 +1900-01-01 00:00:00.000 +1900-01-01 00:00:00.000 +2299-12-14 23:00:00.000 +2299-12-30 23:00:00.000 2021-06-21 23:00:00.000 -------subtractDays--------- -2283-11-05 -2283-11-05 -2282-12-24 -2283-11-04 +2299-12-31 +2299-12-31 +2299-12-08 +2299-12-24 2021-06-15 -------subtractWeeks--------- -2283-11-05 -2283-11-05 -2282-12-24 -2283-11-04 +2299-12-31 +2299-12-31 +2299-12-08 +2299-12-24 2021-06-15 -------subtractMonths--------- -1925-01-01 -1925-01-01 -2282-11-30 -2283-10-11 +1900-01-01 +1900-01-01 +2299-11-15 +2299-11-30 2021-05-22 -------subtractQuarters--------- -1925-01-01 -1925-01-01 -2282-09-30 -2283-08-11 +1900-01-01 +1900-01-01 +2299-09-15 +2299-09-30 2021-03-22 -------subtractYears--------- -1925-01-01 -1925-01-01 -2281-12-31 -2282-11-11 +1900-01-01 +1900-01-01 +2298-12-15 +2298-12-31 2020-06-22 -------toDate32--------- -1925-01-01 2000-01-01 -1925-01-01 1925-01-01 -1925-01-01 \N -1925-01-01 +1900-01-01 2000-01-01 +1900-01-01 1900-01-01 +1900-01-01 \N +1900-01-01 \N -1925-01-01 +1900-01-01 1969-12-31 1970-01-01 2149-06-06 2149-06-07 -2283-11-11 +2299-12-31 diff --git a/tests/queries/0_stateless/01921_datatype_date32.sql b/tests/queries/0_stateless/01921_datatype_date32.sql index ef6e3e5ee89..8b65f82825f 100644 --- a/tests/queries/0_stateless/01921_datatype_date32.sql +++ b/tests/queries/0_stateless/01921_datatype_date32.sql @@ -1,7 +1,7 @@ drop table if exists t1; create table t1(x1 Date32) engine Memory; -insert into t1 values ('1925-01-01'),('1924-01-01'),('2282-12-31'),('2283-12-31'),('2021-06-22'); +insert into t1 values ('1900-01-01'),('1899-01-01'),('2299-12-15'),('2300-12-31'),('2021-06-22'); select x1 from t1; select '-------toYear---------'; @@ -113,20 +113,19 @@ select subtractQuarters(x1, 1) from t1; select '-------subtractYears---------'; select subtractYears(x1, 1) from t1; select '-------toDate32---------'; -select toDate32('1925-01-01'), toDate32(toDate('2000-01-01')); -select toDate32OrZero('1924-01-01'), toDate32OrNull('1924-01-01'); +select toDate32('1900-01-01'), toDate32(toDate('2000-01-01')); +select toDate32OrZero('1899-01-01'), toDate32OrNull('1899-01-01'); select toDate32OrZero(''), toDate32OrNull(''); select (select toDate32OrZero('')); select (select toDate32OrNull('')); SELECT toString(T.d) dateStr FROM ( - SELECT '1925-01-01'::Date32 d + SELECT '1900-01-01'::Date32 d UNION ALL SELECT '1969-12-31'::Date32 UNION ALL SELECT '1970-01-01'::Date32 UNION ALL SELECT '2149-06-06'::Date32 UNION ALL SELECT '2149-06-07'::Date32 - UNION ALL SELECT '2283-11-11'::Date32 + UNION ALL SELECT '2299-12-31'::Date32 ) AS T ORDER BY T.d -