Add narrowing for toStartOfISOYear; improve 02403_enable_extended_results_for_datetime_functions

This commit is contained in:
Roman Vasin 2022-09-16 08:40:15 +00:00
parent 5c242de43a
commit 7e733887b9
4 changed files with 67 additions and 66 deletions

View File

@ -931,7 +931,7 @@ struct ToStartOfISOYearImpl
static inline UInt16 execute(Int64 t, const DateLUTImpl & time_zone) static inline UInt16 execute(Int64 t, const DateLUTImpl & time_zone)
{ {
return time_zone.toFirstDayNumOfISOYear(time_zone.toDayNum(t)); return t < 0 ? 0 : time_zone.toFirstDayNumOfISOYear(ExtendedDayNum(std::min(Int32(time_zone.toDayNum(t)), Int32(DATE_LUT_MAX_DAY_NUM))));
} }
static inline UInt16 execute(UInt32 t, const DateLUTImpl & time_zone) static inline UInt16 execute(UInt32 t, const DateLUTImpl & time_zone)
{ {
@ -939,7 +939,7 @@ struct ToStartOfISOYearImpl
} }
static inline UInt16 execute(Int32 d, const DateLUTImpl & time_zone) static inline UInt16 execute(Int32 d, const DateLUTImpl & time_zone)
{ {
return time_zone.toFirstDayNumOfISOYear(ExtendedDayNum(d)); return d < 0 ? 0 : time_zone.toFirstDayNumOfISOYear(ExtendedDayNum(std::min(d, Int32(DATE_LUT_MAX_DAY_NUM))));
} }
static inline UInt16 execute(UInt16 d, const DateLUTImpl & time_zone) static inline UInt16 execute(UInt16 d, const DateLUTImpl & time_zone)
{ {

View File

@ -109,10 +109,10 @@
-------toStartOfFifteenMinutes--------- -------toStartOfFifteenMinutes---------
-------toStartOfHour--------- -------toStartOfHour---------
-------toStartOfISOYear--------- -------toStartOfISOYear---------
2079-06-07 1970-01-01
2079-06-07 1970-01-01
2119-07-29 2148-12-30
2119-07-29 2148-12-30
2021-01-04 2021-01-04
-------toRelativeYearNum--------- -------toRelativeYearNum---------
1900 1900

View File

@ -1,56 +1,56 @@
1950-01-01 toStartOfYear;toDate32;true 1920-01-01
Date32 type;toStartOfYear;toDate32;true Date32
1950-01-01 toStartOfYear;toDateTime64;true 1920-01-01
Date32 type;toStartOfYear;toDateTime64;true Date32
1950-01-02 toStartOfISOYear;toDate32;true 1919-12-29
Date32 type;toStartOfISOYear;toDate32;true Date32
1950-01-02 toStartOfISOYear;toDateTime64;true 1919-12-29
Date32 type;toStartOfISOYear;toDateTime64;true Date32
1950-01-01 toStartOfQuarter;toDate32;true 1920-01-01
Date32 type;toStartOfQuarter;toDate32;true Date32
1950-01-01 toStartOfQuarter;toDateTime64;true 1920-01-01
Date32 type;toStartOfQuarter;toDateTime64;true Date32
1950-02-01 toStartOfMonth;toDate32;true 1920-02-01
Date32 type;toStartOfMonth;toDate32;true Date32
1950-02-01 toStartOfMonth;toDateTime64;true 1920-02-01
Date32 type;toStartOfMonth;toDateTime64;true Date32
1950-01-29 toStartOfWeek;toDate32;true 1920-02-01
Date32 type;toStartOfWeek;toDate32;true Date32
1950-01-29 toStartOfWeek;toDateTime64;true 1920-02-01
Date32 type;toStartOfWeek;toDateTime64;true Date32
1950-01-30 toMonday;toDate32;true 1920-02-02
Date32 type;toMonday;toDate32;true Date32
1950-01-30 toMonday;toDateTime64;true 1920-02-02
Date32 type;toMonday;toDateTime64;true Date32
1950-02-28 toLastDayOfMonth;toDate32;true 1920-02-29
Date32 type;toLastDayOfMonth;toDate32;true Date32
1950-02-28 toLastDayOfMonth;toDateTime64;true 1920-02-29
Date32 type;toLastDayOfMonth;toDateTime64;true Date32
1970-01-01 toStartOfYear;toDate32;false 1970-01-01
Date type;toStartOfYear;toDate32;false Date
1970-01-01 toStartOfYear;toDateTime64;false 1970-01-01
Date type;toStartOfYear;toDateTime64;false Date
2129-06-08 toStartOfISOYear;toDate32;false 1970-01-01
Date type;toStartOfISOYear;toDate32;false Date
2129-06-08 toStartOfISOYear;toDateTime64;false 1970-01-01
Date type;toStartOfISOYear;toDateTime64;false Date
1970-01-01 toStartOfQuarter;toDate32;false 1970-01-01
Date type;toStartOfQuarter;toDate32;false Date
1970-01-01 toStartOfQuarter;toDateTime64;false 1970-01-01
Date type;toStartOfQuarter;toDateTime64;false Date
1970-01-01 toStartOfMonth;toDate32;false 1970-01-01
Date type;toStartOfMonth;toDate32;false Date
1970-01-01 toStartOfMonth;toDateTime64;false 1970-01-01
Date type;toStartOfMonth;toDateTime64;false Date
1970-01-01 toStartOfWeek;toDate32;false 1970-01-01
Date type;toStartOfWeek;toDate32;false Date
1970-01-01 toStartOfWeek;toDateTime64;false 1970-01-01
Date type;toStartOfWeek;toDateTime64;false Date
1970-01-01 toMonday;toDate32;false 1970-01-01
Date type;toMonday;toDate32;false Date
1970-01-01 toMonday;toDateTime64;false 1970-01-01
Date type;toMonday;toDateTime64;false Date
1970-01-01 toLastDayOfMonth;toDate32;false 1970-01-01
Date type;toLastDayOfMonth;toDate32;false Date
1970-01-01 toLastDayOfMonth;toDateTime64;false 1970-01-01
Date type;toLastDayOfMonth;toDateTime64;false Date

View File

@ -1,8 +1,9 @@
{% for option_value in ['true', 'false'] -%} {% for option_value in ['true', 'false'] -%}
{% for date_fun in ['toStartOfYear', 'toStartOfISOYear', 'toStartOfQuarter', 'toStartOfMonth', 'toStartOfWeek', 'toMonday', 'toLastDayOfMonth'] -%} {% for date_fun in ['toStartOfYear', 'toStartOfISOYear', 'toStartOfQuarter', 'toStartOfMonth', 'toStartOfWeek', 'toMonday', 'toLastDayOfMonth'] -%}
SELECT {{ date_fun }}(toDate32('1950-02-02')) SETTINGS enable_extended_results_for_datetime_functions = {{ option_value }}; SELECT '{{ date_fun }};toDate32;{{ option_value }}', {{ date_fun }}(toDate32('1920-02-02')) SETTINGS enable_extended_results_for_datetime_functions = {{ option_value }};
SELECT toTypeName({{ date_fun }}(toDate32('1950-02-02'))) SETTINGS enable_extended_results_for_datetime_functions = {{ option_value }}; SELECT 'type;{{ date_fun }};toDate32;{{ option_value }}', toTypeName({{ date_fun }}(toDate32('1920-02-02'))) SETTINGS enable_extended_results_for_datetime_functions = {{ option_value }};
SELECT {{ date_fun }}(toDateTime64('1950-02-02 10:20:30', 3)) SETTINGS enable_extended_results_for_datetime_functions = {{ option_value }}; SELECT '{{ date_fun }};toDateTime64;{{ option_value }}', {{ date_fun }}(toDateTime64('1920-02-02 10:20:30', 3)) SETTINGS enable_extended_results_for_datetime_functions = {{ option_value }};
SELECT toTypeName({{ date_fun }}(toDateTime64('1950-02-02 10:20:30', 3))) SETTINGS enable_extended_results_for_datetime_functions = {{ option_value }}; SELECT 'type;{{ date_fun }};toDateTime64;{{ option_value }}', toTypeName({{ date_fun }}(toDateTime64('1920-02-02 10:20:30', 3))) SETTINGS enable_extended_results_for_datetime_functions = {{ option_value }};
{% endfor -%} {% endfor -%}
{% endfor -%} {% endfor -%}