Correct 01821_to_date_time_ubsan and 01921_datatype_date32 tests

This commit is contained in:
Roman Vasin 2022-07-18 16:44:14 +00:00
parent 7fcac45915
commit 28fd774df8
4 changed files with 177 additions and 178 deletions

View File

@ -71,7 +71,7 @@ private:
static inline LUTIndex normalizeLUTIndex(UInt32 index) static inline LUTIndex normalizeLUTIndex(UInt32 index)
{ {
if (index >= DATE_LUT_SIZE) if (index >= DATE_LUT_SIZE)
LUTIndex(DATE_LUT_SIZE - 1); return LUTIndex(DATE_LUT_SIZE - 1);
return LUTIndex{index}; return LUTIndex{index};
} }
@ -80,7 +80,7 @@ private:
if unlikely(index < 0 ) if unlikely(index < 0 )
return LUTIndex(0); return LUTIndex(0);
if (index >= DATE_LUT_SIZE) if (index >= DATE_LUT_SIZE)
LUTIndex(DATE_LUT_SIZE - 1); return LUTIndex(DATE_LUT_SIZE - 1);
return LUTIndex{index}; return LUTIndex{index};
} }
@ -93,7 +93,7 @@ private:
template <typename T> template <typename T>
friend inline LUTIndex operator+(const T v, const LUTIndex & index) friend inline LUTIndex operator+(const T v, const LUTIndex & index)
{ {
return normalizeLUTIndex(v + index.toUnderType()); return normalizeLUTIndex(static_cast<Int64>(v + index.toUnderType()));
} }
friend inline LUTIndex operator+(const LUTIndex & index, const LUTIndex & v) friend inline LUTIndex operator+(const LUTIndex & index, const LUTIndex & v)

View File

@ -1,2 +1,2 @@
2283-11-11 23:48:05.4775806 2299-12-31 23:48:05.4775806
2283-11-11 23:52:48.54775806 2299-12-31 23:52:48.54775806

View File

@ -1,19 +1,19 @@
1925-01-01 1900-01-01
1925-01-01 1900-01-01
2282-12-31 2299-12-15
2283-11-11 2299-12-31
2021-06-22 2021-06-22
-------toYear--------- -------toYear---------
1925 1900
1925 1900
2282 2299
2283 2299
2021 2021
-------toMonth--------- -------toMonth---------
1 1
1 1
12 12
11 12
6 6
-------toQuarter--------- -------toQuarter---------
1 1
@ -24,83 +24,83 @@
-------toDayOfMonth--------- -------toDayOfMonth---------
1 1
1 1
15
31 31
11
22 22
-------toDayOfWeek--------- -------toDayOfWeek---------
4 1
4 1
7 5
7 7
2 2
-------toDayOfYear--------- -------toDayOfYear---------
1 1
1 1
365 349
315 364
173 173
-------toHour--------- -------toHour---------
-------toMinute--------- -------toMinute---------
-------toSecond--------- -------toSecond---------
-------toStartOfDay--------- -------toStartOfDay---------
2061-02-06 07:28:16 2036-02-07 07:31:20
2061-02-06 07:28:16 2036-02-07 07:31:20
2010-10-17 11:03:28 2027-10-01 11:03:28
2011-08-28 11:03:28 2027-10-17 11:03:28
2021-06-22 00:00:00 2021-06-22 00:00:00
-------toMonday--------- -------toMonday---------
2104-06-04 2079-06-07
2104-06-04 2079-06-07
2103-07-21 2120-07-06
2104-05-31 2120-07-20
2021-06-21 2021-06-21
-------toISOWeek--------- -------toISOWeek---------
1 1
1 1
50
52 52
45
25 25
-------toISOYear--------- -------toISOYear---------
1925 1900
1925 1900
2282 2299
2283 2299
2021 2021
-------toWeek--------- -------toWeek---------
0 0
0 0
50
53 53
45
25 25
-------toYearWeek--------- -------toYearWeek---------
192452 189953
192452 189953
228253 229950
228345 229953
202125 202125
-------toStartOfWeek--------- -------toStartOfWeek---------
2104-06-03 2079-06-06
2104-06-03 2079-06-06
2103-07-27 2120-07-05
2104-06-06 2120-07-26
2021-06-20 2021-06-20
-------toStartOfMonth--------- -------toStartOfMonth---------
2104-06-07 2079-06-07
2104-06-07 2079-06-07
2103-06-27 2120-06-26
2104-05-27 2120-06-26
2021-06-01 2021-06-01
-------toStartOfQuarter--------- -------toStartOfQuarter---------
2104-06-07 2079-06-07
2104-06-07 2079-06-07
2103-04-27 2120-04-26
2104-04-26 2120-04-26
2021-04-01 2021-04-01
-------toStartOfYear--------- -------toStartOfYear---------
2104-06-07 2079-06-07
2104-06-07 2079-06-07
2102-07-28 2119-07-28
2103-07-28 2119-07-28
2021-01-01 2021-01-01
-------toStartOfSecond--------- -------toStartOfSecond---------
-------toStartOfMinute--------- -------toStartOfMinute---------
@ -109,183 +109,183 @@
-------toStartOfFifteenMinutes--------- -------toStartOfFifteenMinutes---------
-------toStartOfHour--------- -------toStartOfHour---------
-------toStartOfISOYear--------- -------toStartOfISOYear---------
2104-06-04 2079-06-07
2104-06-04 2079-06-07
2102-07-29 2119-07-29
2103-07-28 2119-07-29
2021-01-04 2021-01-04
-------toRelativeYearNum--------- -------toRelativeYearNum---------
1925 1900
1925 1900
2282 2299
2283 2299
2021 2021
-------toRelativeQuarterNum--------- -------toRelativeQuarterNum---------
7700 7600
7700 7600
9131 9199
9135 9199
8085 8085
-------toRelativeMonthNum--------- -------toRelativeMonthNum---------
23101 22801
23101 22801
27396 27600
27407 27600
24258 24258
-------toRelativeWeekNum--------- -------toRelativeWeekNum---------
63189 61885
63189 61885
16331 17216
63188 17217
2686 2686
-------toRelativeDayNum--------- -------toRelativeDayNum---------
49100 39969
49100 39969
48784 54977
49099 54993
18800 18800
-------toRelativeHourNum--------- -------toRelativeHourNum---------
4294572852 4294353708
4294572852 4294353708
2743677 2892309
2751237 2892693
451197 451197
-------toRelativeMinuteNum--------- -------toRelativeMinuteNum---------
4271299336 4258150699
4271299336 4258150699
164620620 173538540
165074220 173561580
27071820 27071820
-------toRelativeSecondNum--------- -------toRelativeSecondNum---------
2874889696 2085971480
2874889696 2085971480
1287302608 1822377808
1314518608 1823760208
1624309200 1624309200
-------toTime--------- -------toTime---------
-------toYYYYMM--------- -------toYYYYMM---------
192501 190001
192501 190001
228212 229912
228311 229912
202106 202106
-------toYYYYMMDD--------- -------toYYYYMMDD---------
19250101 19000101
19250101 19000101
22821231 22991215
22831111 22991231
20210622 20210622
-------toYYYYMMDDhhmmss--------- -------toYYYYMMDDhhmmss---------
19250101000000 19000101000000
19250101000000 19000101000000
22821231000000 22991215000000
22831111000000 22991231000000
20210622000000 20210622000000
-------addSeconds--------- -------addSeconds---------
1925-01-01 01:00:00.000 1900-01-01 01:00:00.000
1925-01-01 01:00:00.000 1900-01-01 01:00:00.000
2282-12-31 01:00:00.000 2299-12-15 01:00:00.000
2283-11-11 01:00:00.000 2299-12-31 01:00:00.000
2021-06-22 01:00:00.000 2021-06-22 01:00:00.000
-------addMinutes--------- -------addMinutes---------
1925-01-01 01:00:00.000 1900-01-01 01:00:00.000
1925-01-01 01:00:00.000 1900-01-01 01:00:00.000
2282-12-31 01:00:00.000 2299-12-15 01:00:00.000
2283-11-11 01:00:00.000 2299-12-31 01:00:00.000
2021-06-22 01:00:00.000 2021-06-22 01:00:00.000
-------addHours--------- -------addHours---------
1925-01-01 01:00:00.000 1900-01-01 01:00:00.000
1925-01-01 01:00:00.000 1900-01-01 01:00:00.000
2282-12-31 01:00:00.000 2299-12-15 01:00:00.000
2283-11-11 01:00:00.000 2299-12-31 01:00:00.000
2021-06-22 01:00:00.000 2021-06-22 01:00:00.000
-------addDays--------- -------addDays---------
1925-01-08 1900-01-08
1925-01-08 1900-01-08
2283-01-07 2299-12-22
1925-01-07 2299-12-31
2021-06-29 2021-06-29
-------addWeeks--------- -------addWeeks---------
1925-01-08 1900-01-08
1925-01-08 1900-01-08
2283-01-07 2299-12-22
1925-01-07 2299-12-31
2021-06-29 2021-06-29
-------addMonths--------- -------addMonths---------
1925-02-01 1900-02-01
1925-02-01 1900-02-01
2283-01-31 2299-12-31
2283-11-11 2299-12-31
2021-07-22 2021-07-22
-------addQuarters--------- -------addQuarters---------
1925-04-01 1900-04-01
1925-04-01 1900-04-01
2283-03-31 2299-12-31
2283-11-11 2299-12-31
2021-09-22 2021-09-22
-------addYears--------- -------addYears---------
1926-01-01 1901-01-01
1926-01-01 1901-01-01
2283-11-11 2299-12-31
2283-11-11 2299-12-31
2022-06-22 2022-06-22
-------subtractSeconds--------- -------subtractSeconds---------
1925-01-01 00:00:00.000 1900-01-01 00:00:00.000
1925-01-01 00:00:00.000 1900-01-01 00:00:00.000
2282-12-30 23:00:00.000 2299-12-14 23:00:00.000
2283-11-10 23:00:00.000 2299-12-30 23:00:00.000
2021-06-21 23:00:00.000 2021-06-21 23:00:00.000
-------subtractMinutes--------- -------subtractMinutes---------
1925-01-01 00:00:00.000 1900-01-01 00:00:00.000
1925-01-01 00:00:00.000 1900-01-01 00:00:00.000
2282-12-30 23:00:00.000 2299-12-14 23:00:00.000
2283-11-10 23:00:00.000 2299-12-30 23:00:00.000
2021-06-21 23:00:00.000 2021-06-21 23:00:00.000
-------subtractHours--------- -------subtractHours---------
1925-01-01 00:00:00.000 1900-01-01 00:00:00.000
1925-01-01 00:00:00.000 1900-01-01 00:00:00.000
2282-12-30 23:00:00.000 2299-12-14 23:00:00.000
2283-11-10 23:00:00.000 2299-12-30 23:00:00.000
2021-06-21 23:00:00.000 2021-06-21 23:00:00.000
-------subtractDays--------- -------subtractDays---------
2283-11-05 2299-12-31
2283-11-05 2299-12-31
2282-12-24 2299-12-08
2283-11-04 2299-12-24
2021-06-15 2021-06-15
-------subtractWeeks--------- -------subtractWeeks---------
2283-11-05 2299-12-31
2283-11-05 2299-12-31
2282-12-24 2299-12-08
2283-11-04 2299-12-24
2021-06-15 2021-06-15
-------subtractMonths--------- -------subtractMonths---------
1925-01-01 1900-01-01
1925-01-01 1900-01-01
2282-11-30 2299-11-15
2283-10-11 2299-11-30
2021-05-22 2021-05-22
-------subtractQuarters--------- -------subtractQuarters---------
1925-01-01 1900-01-01
1925-01-01 1900-01-01
2282-09-30 2299-09-15
2283-08-11 2299-09-30
2021-03-22 2021-03-22
-------subtractYears--------- -------subtractYears---------
1925-01-01 1900-01-01
1925-01-01 1900-01-01
2281-12-31 2298-12-15
2282-11-11 2298-12-31
2020-06-22 2020-06-22
-------toDate32--------- -------toDate32---------
1925-01-01 2000-01-01 1900-01-01 2000-01-01
1925-01-01 1925-01-01 1900-01-01 1900-01-01
1925-01-01 \N 1900-01-01 \N
1925-01-01 1900-01-01
\N \N
1925-01-01 1900-01-01
1969-12-31 1969-12-31
1970-01-01 1970-01-01
2149-06-06 2149-06-06
2149-06-07 2149-06-07
2283-11-11 2299-12-31

View File

@ -1,7 +1,7 @@
drop table if exists t1; drop table if exists t1;
create table t1(x1 Date32) engine Memory; 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 x1 from t1;
select '-------toYear---------'; select '-------toYear---------';
@ -113,20 +113,19 @@ select subtractQuarters(x1, 1) from t1;
select '-------subtractYears---------'; select '-------subtractYears---------';
select subtractYears(x1, 1) from t1; select subtractYears(x1, 1) from t1;
select '-------toDate32---------'; select '-------toDate32---------';
select toDate32('1925-01-01'), toDate32(toDate('2000-01-01')); select toDate32('1900-01-01'), toDate32(toDate('2000-01-01'));
select toDate32OrZero('1924-01-01'), toDate32OrNull('1924-01-01'); select toDate32OrZero('1899-01-01'), toDate32OrNull('1899-01-01');
select toDate32OrZero(''), toDate32OrNull(''); select toDate32OrZero(''), toDate32OrNull('');
select (select toDate32OrZero('')); select (select toDate32OrZero(''));
select (select toDate32OrNull('')); select (select toDate32OrNull(''));
SELECT toString(T.d) dateStr SELECT toString(T.d) dateStr
FROM FROM
( (
SELECT '1925-01-01'::Date32 d SELECT '1900-01-01'::Date32 d
UNION ALL SELECT '1969-12-31'::Date32 UNION ALL SELECT '1969-12-31'::Date32
UNION ALL SELECT '1970-01-01'::Date32 UNION ALL SELECT '1970-01-01'::Date32
UNION ALL SELECT '2149-06-06'::Date32 UNION ALL SELECT '2149-06-06'::Date32
UNION ALL SELECT '2149-06-07'::Date32 UNION ALL SELECT '2149-06-07'::Date32
UNION ALL SELECT '2283-11-11'::Date32 UNION ALL SELECT '2299-12-31'::Date32
) AS T ) AS T
ORDER BY T.d ORDER BY T.d