Merge pull request #67558 from yariks5s/fix_datetime64_toStartOfWeek

Fix toStartOfWeek wrong result with DateTime64
This commit is contained in:
Yarik Briukhovetskyi 2024-08-02 20:42:29 +00:00 committed by GitHub
commit 593af842f5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 10 additions and 4 deletions

View File

@ -24,7 +24,7 @@ namespace DB
static constexpr auto millisecond_multiplier = 1'000; static constexpr auto millisecond_multiplier = 1'000;
static constexpr auto microsecond_multiplier = 1'000'000; static constexpr auto microsecond_multiplier = 1'000'000;
static constexpr auto nanosecond_multiplier = 1'000'000'000; static constexpr auto nanosecond_multiplier = 1'000'000'000;
static constexpr FormatSettings::DateTimeOverflowBehavior default_date_time_overflow_behavior = FormatSettings::DateTimeOverflowBehavior::Ignore; static constexpr FormatSettings::DateTimeOverflowBehavior default_date_time_overflow_behavior = FormatSettings::DateTimeOverflowBehavior::Ignore;
@ -381,11 +381,13 @@ struct ToStartOfWeekImpl
static UInt16 execute(Int64 t, UInt8 week_mode, const DateLUTImpl & time_zone) static UInt16 execute(Int64 t, UInt8 week_mode, const DateLUTImpl & time_zone)
{ {
return time_zone.toFirstDayNumOfWeek(time_zone.toDayNum(t), week_mode); const int res = time_zone.toFirstDayNumOfWeek(time_zone.toDayNum(t), week_mode);
return std::max(res, 0);
} }
static UInt16 execute(UInt32 t, UInt8 week_mode, const DateLUTImpl & time_zone) static UInt16 execute(UInt32 t, UInt8 week_mode, const DateLUTImpl & time_zone)
{ {
return time_zone.toFirstDayNumOfWeek(time_zone.toDayNum(t), week_mode); const int res = time_zone.toFirstDayNumOfWeek(time_zone.toDayNum(t), week_mode);
return std::max(res, 0);
} }
static UInt16 execute(Int32 d, UInt8 week_mode, const DateLUTImpl & time_zone) static UInt16 execute(Int32 d, UInt8 week_mode, const DateLUTImpl & time_zone)
{ {

View File

@ -64,7 +64,7 @@ toStartOfMonth;toDateTime64;false 2099-07-07
type;toStartOfMonth;toDateTime64;false Date type;toStartOfMonth;toDateTime64;false Date
toStartOfWeek;toDate32;false 2099-07-07 toStartOfWeek;toDate32;false 2099-07-07
type;toStartOfWeek;toDate32;false Date type;toStartOfWeek;toDate32;false Date
toStartOfWeek;toDateTime64;false 2099-07-07 toStartOfWeek;toDateTime64;false 1970-01-01
type;toStartOfWeek;toDateTime64;false Date type;toStartOfWeek;toDateTime64;false Date
toMonday;toDate32;false 2099-07-08 toMonday;toDate32;false 2099-07-08
type;toMonday;toDate32;false Date type;toMonday;toDate32;false Date

View File

@ -0,0 +1,2 @@
1970-01-01
1970-01-01

View File

@ -0,0 +1,2 @@
SELECT toStartOfWeek(toDateTime64('1970-01-01', 6));
SELECT toStartOfWeek(toDateTime('1970-01-01'));