diff --git a/docs/en/operations/settings/settings.md b/docs/en/operations/settings/settings.md index 5518fd7e1ec..4f158a4fd6e 100644 --- a/docs/en/operations/settings/settings.md +++ b/docs/en/operations/settings/settings.md @@ -4373,17 +4373,6 @@ Possible values: Default value: `ignore`. -## first_day_of_week - -The first day of the week assumed by [`toStartOfInterval`](../../sql-reference/functions/date-time-functions.md#toStartOfInterval) function when using weeks as unit. - -Possible values: - -- Monday - Week starts on Monday -- Sunday - Week starts on Sunday - -Default value: 'Monday'. - ## optimize_move_to_prewhere {#optimize_move_to_prewhere} Enables or disables automatic [PREWHERE](../../sql-reference/statements/select/prewhere.md) optimization in [SELECT](../../sql-reference/statements/select/index.md) queries. diff --git a/docs/en/sql-reference/functions/date-time-functions.md b/docs/en/sql-reference/functions/date-time-functions.md index 51f841657d9..39971cbed7a 100644 --- a/docs/en/sql-reference/functions/date-time-functions.md +++ b/docs/en/sql-reference/functions/date-time-functions.md @@ -1052,7 +1052,7 @@ toStartOfWeek(t[, mode[, timezone]]) **Arguments** - `t` - a [Date](../data-types/date.md), [Date32](../data-types/date32.md), [DateTime](../data-types/datetime.md) or [DateTime64](../data-types/datetime64.md) -- `mode` - determines the first day of the week as described in the [toWeek()](date-time-functions#toweek) function. Default: 0 +- `mode` - determines the first day of the week as described in the [toWeek()](date-time-functions#toweek) function - `timezone` - Optional parameter, it behaves like any other conversion function **Returned value** @@ -1413,7 +1413,7 @@ toStartOfFifteenMinutes(toDateTime('2023-04-21 10:20:00')): 2023-04-21 10:15:00 toStartOfFifteenMinutes(toDateTime('2023-04-21 10:23:00')): 2023-04-21 10:15:00 ``` -## toStartOfInterval +## toStartOfInterval(date_or_date_with_time, INTERVAL x unit \[, time_zone\]) This function generalizes other `toStartOf*()` functions. For example, - `toStartOfInterval(t, INTERVAL 1 year)` returns the same as `toStartOfYear(t)`, @@ -1440,8 +1440,6 @@ The calculation is performed relative to specific points in time: (*) hour intervals are special: the calculation is always performed relative to 00:00:00 (midnight) of the current day. As a result, only hour values between 1 and 23 are useful. -If unit `week` was specified, `toStartOfInterval` assumes by default that weeks start on Monday. You can change this behavior with setting [`first_day_of_week`](../../operations/settings/settings.md/#first-day-of-week) - **See Also** - [date_trunc](#date_trunc) @@ -1675,7 +1673,7 @@ Like [fromDaysSinceYearZero](#fromDaysSinceYearZero) but returns a [Date32](../. Returns the `unit` component of the difference between `startdate` and `enddate`. The difference is calculated using a precision of 1 nanosecond. E.g. the difference between `2021-12-29` and `2022-01-01` is 3 days for `day` unit, 0 months for `month` unit, 0 years for `year` unit. -For an alternative to `age`, see function `date_diff`. +For an alternative to `age`, see function `date\_diff`. **Syntax** @@ -1749,9 +1747,9 @@ Result: Returns the count of the specified `unit` boundaries crossed between the `startdate` and the `enddate`. The difference is calculated using relative units, e.g. the difference between `2021-12-29` and `2022-01-01` is 3 days for unit `day` (see [toRelativeDayNum](#torelativedaynum)), 1 month for unit `month` (see [toRelativeMonthNum](#torelativemonthnum)) and 1 year for unit `year` (see [toRelativeYearNum](#torelativeyearnum)). -If unit `week` was specified, `date_diff` assumes that weeks start on Monday. Note that this behavior is different from that of function `toWeek()` in which weeks start by default on Sunday. +If unit `week` was specified, `date\_diff` assumes that weeks start on Monday. Note that this behavior is different from that of function `toWeek()` in which weeks start by default on Sunday. -For an alternative to `date_diff`, see function `age`. +For an alternative to `date\_diff`, see function `age`. **Syntax** @@ -2885,7 +2883,7 @@ Result: ## fromUnixTimestamp -This function converts a Unix timestamp to a calendar date and a time of a day. +This function converts a Unix timestamp to a calendar date and a time of a day. It can be called in two ways: diff --git a/src/Common/DateLUTImpl.h b/src/Common/DateLUTImpl.h index f969803b6c5..01cbae3d447 100644 --- a/src/Common/DateLUTImpl.h +++ b/src/Common/DateLUTImpl.h @@ -1048,20 +1048,16 @@ public: template requires std::is_same_v || std::is_same_v - auto toStartOfWeekInterval(Date d, UInt64 weeks, UInt8 week_mode) const + auto toStartOfWeekInterval(Date d, UInt64 weeks) const { if (weeks == 1) - return toFirstDayNumOfWeek(d, week_mode); - - bool monday_first_mode = week_mode & static_cast(WeekModeFlag::MONDAY_FIRST); - // January 1st 1970 was Thursday so we need this 4-days offset to make weeks start on Monday, or - // 3 days to start on Sunday. - auto offset = monday_first_mode ? 4 : 3; + return toFirstDayNumOfWeek(d); UInt64 days = weeks * 7; + // January 1st 1970 was Thursday so we need this 4-days offset to make weeks start on Monday. if constexpr (std::is_same_v) - return DayNum(offset + (d - offset) / days * days); + return DayNum(4 + (d - 4) / days * days); else - return ExtendedDayNum(static_cast(offset + (d - offset) / days * days)); + return ExtendedDayNum(static_cast(4 + (d - 4) / days * days)); } template diff --git a/src/Core/Settings.h b/src/Core/Settings.h index f332b51bf1d..7e010c046be 100644 --- a/src/Core/Settings.h +++ b/src/Core/Settings.h @@ -551,7 +551,6 @@ class IColumn; M(Bool, formatdatetime_parsedatetime_m_is_month_name, true, "Formatter '%M' in functions 'formatDateTime()' and 'parseDateTime()' print/parse the month name instead of minutes.", 0) \ M(Bool, parsedatetime_parse_without_leading_zeros, true, "Formatters '%c', '%l' and '%k' in function 'parseDateTime()' parse months and hours without leading zeros.", 0) \ M(Bool, formatdatetime_format_without_leading_zeros, false, "Formatters '%c', '%l' and '%k' in function 'formatDateTime()' print months and hours without leading zeros.", 0) \ - M(FirstDayOfWeek, first_day_of_week, FirstDayOfWeek::Monday, "The first day of the week (Monday or Sunday) used by date/time functions (default: Monday).", 0) \ \ M(UInt64, max_partitions_per_insert_block, 100, "Limit maximum number of partitions in single INSERTed block. Zero means unlimited. Throw exception if the block contains too many partitions. This setting is a safety threshold, because using large number of partitions is a common misconception.", 0) \ M(Bool, throw_on_max_partitions_per_insert_block, true, "Used with max_partitions_per_insert_block. If true (default), an exception will be thrown when max_partitions_per_insert_block is reached. If false, details of the insert query reaching this limit with the number of partitions will be logged. This can be useful if you're trying to understand the impact on users when changing max_partitions_per_insert_block.", 0) \ diff --git a/src/Core/SettingsChangesHistory.h b/src/Core/SettingsChangesHistory.h index da6e4e11031..ac58f1e0052 100644 --- a/src/Core/SettingsChangesHistory.h +++ b/src/Core/SettingsChangesHistory.h @@ -92,7 +92,6 @@ static std::map sett {"query_cache_system_table_handling", "save", "throw", "The query cache no longer caches results of queries against system tables"}, {"input_format_json_ignore_unnecessary_fields", false, true, "Ignore unnecessary fields and not parse them. Enabling this may not throw exceptions on json strings of invalid format or with duplicated fields"}, {"input_format_hive_text_allow_variable_number_of_columns", false, true, "Ignore extra columns in Hive Text input (if file has more columns than expected) and treat missing fields in Hive Text input as default values."}, - {"first_day_of_week", "Monday", "Monday", "Added a setting for the first day of the week for date/time functions"}, {"allow_experimental_database_replicated", false, true, "Database engine Replicated is now in Beta stage"}, {"temporary_data_in_cache_reserve_space_wait_lock_timeout_milliseconds", (10 * 60 * 1000), (10 * 60 * 1000), "Wait time to lock cache for sapce reservation in temporary data in filesystem cache"}, {"azure_allow_parallel_part_upload", "true", "true", "Use multiple threads for azure multipart upload."}, diff --git a/src/Core/SettingsEnums.cpp b/src/Core/SettingsEnums.cpp index 545719c3ca5..0caf6e8d609 100644 --- a/src/Core/SettingsEnums.cpp +++ b/src/Core/SettingsEnums.cpp @@ -229,8 +229,4 @@ IMPLEMENT_SETTING_ENUM(SQLSecurityType, ErrorCodes::BAD_ARGUMENTS, {{"DEFINER", SQLSecurityType::DEFINER}, {"INVOKER", SQLSecurityType::INVOKER}, {"NONE", SQLSecurityType::NONE}}) - -IMPLEMENT_SETTING_ENUM(FirstDayOfWeek, ErrorCodes::BAD_ARGUMENTS, - {{"Monday", FirstDayOfWeek::Monday}, - {"Sunday", FirstDayOfWeek::Sunday}}) } diff --git a/src/Core/SettingsEnums.h b/src/Core/SettingsEnums.h index b1d9403b15d..b17ff11d428 100644 --- a/src/Core/SettingsEnums.h +++ b/src/Core/SettingsEnums.h @@ -370,12 +370,4 @@ DECLARE_SETTING_ENUM(SchemaInferenceMode) DECLARE_SETTING_ENUM_WITH_RENAME(DateTimeOverflowBehavior, FormatSettings::DateTimeOverflowBehavior) DECLARE_SETTING_ENUM(SQLSecurityType) - -enum class FirstDayOfWeek -{ - Monday, - Sunday -}; - -DECLARE_SETTING_ENUM(FirstDayOfWeek) } diff --git a/src/Functions/DateTimeTransforms.h b/src/Functions/DateTimeTransforms.h index ed2ed66b0b0..a489c3cb859 100644 --- a/src/Functions/DateTimeTransforms.h +++ b/src/Functions/DateTimeTransforms.h @@ -478,19 +478,19 @@ static constexpr auto TO_START_OF_INTERVAL_NAME = "toStartOfInterval"; template <> struct ToStartOfInterval { - static UInt32 execute(UInt16, Int64, Int64, UInt8, const DateLUTImpl &) + static UInt32 execute(UInt16, Int64, const DateLUTImpl &, Int64) { throwDateIsNotSupported(TO_START_OF_INTERVAL_NAME); } - static UInt32 execute(Int32, Int64, Int64, UInt8, const DateLUTImpl &) + static UInt32 execute(Int32, Int64, const DateLUTImpl &, Int64) { throwDate32IsNotSupported(TO_START_OF_INTERVAL_NAME); } - static UInt32 execute(UInt32, Int64, Int64, UInt8, const DateLUTImpl &) + static UInt32 execute(UInt32, Int64, const DateLUTImpl &, Int64) { throwDateTimeIsNotSupported(TO_START_OF_INTERVAL_NAME); } - static Int64 execute(Int64 t, Int64 nanoseconds, Int64 scale_multiplier, UInt8, const DateLUTImpl &) + static Int64 execute(Int64 t, Int64 nanoseconds, const DateLUTImpl &, Int64 scale_multiplier) { if (scale_multiplier < 1000000000) { @@ -513,19 +513,19 @@ struct ToStartOfInterval template <> struct ToStartOfInterval { - static UInt32 execute(UInt16, Int64, Int64, UInt8, const DateLUTImpl &) + static UInt32 execute(UInt16, Int64, const DateLUTImpl &, Int64) { throwDateIsNotSupported(TO_START_OF_INTERVAL_NAME); } - static UInt32 execute(Int32, Int64, Int64, UInt8, const DateLUTImpl &) + static UInt32 execute(Int32, Int64, const DateLUTImpl &, Int64) { throwDate32IsNotSupported(TO_START_OF_INTERVAL_NAME); } - static UInt32 execute(UInt32, Int64, Int64, UInt8, const DateLUTImpl &) + static UInt32 execute(UInt32, Int64, const DateLUTImpl &, Int64) { throwDateTimeIsNotSupported(TO_START_OF_INTERVAL_NAME); } - static Int64 execute(Int64 t, Int64 microseconds, Int64 scale_multiplier, UInt8, const DateLUTImpl &) + static Int64 execute(Int64 t, Int64 microseconds, const DateLUTImpl &, Int64 scale_multiplier) { if (scale_multiplier < 1000000) { @@ -556,19 +556,19 @@ struct ToStartOfInterval template <> struct ToStartOfInterval { - static UInt32 execute(UInt16, Int64, Int64, UInt8, const DateLUTImpl &) + static UInt32 execute(UInt16, Int64, const DateLUTImpl &, Int64) { throwDateIsNotSupported(TO_START_OF_INTERVAL_NAME); } - static UInt32 execute(Int32, Int64, Int64, UInt8, const DateLUTImpl &) + static UInt32 execute(Int32, Int64, const DateLUTImpl &, Int64) { throwDate32IsNotSupported(TO_START_OF_INTERVAL_NAME); } - static UInt32 execute(UInt32, Int64, Int64, UInt8, const DateLUTImpl &) + static UInt32 execute(UInt32, Int64, const DateLUTImpl &, Int64) { throwDateTimeIsNotSupported(TO_START_OF_INTERVAL_NAME); } - static Int64 execute(Int64 t, Int64 milliseconds, Int64 scale_multiplier, UInt8, const DateLUTImpl &) + static Int64 execute(Int64 t, Int64 milliseconds, const DateLUTImpl &, Int64 scale_multiplier) { if (scale_multiplier < 1000) { @@ -599,19 +599,19 @@ struct ToStartOfInterval template <> struct ToStartOfInterval { - static UInt32 execute(UInt16, Int64, Int64, UInt8, const DateLUTImpl &) + static UInt32 execute(UInt16, Int64, const DateLUTImpl &, Int64) { throwDateIsNotSupported(TO_START_OF_INTERVAL_NAME); } - static UInt32 execute(Int32, Int64, Int64, UInt8, const DateLUTImpl &) + static UInt32 execute(Int32, Int64, const DateLUTImpl &, Int64) { throwDate32IsNotSupported(TO_START_OF_INTERVAL_NAME); } - static UInt32 execute(UInt32 t, Int64 seconds, Int64, UInt8, const DateLUTImpl & time_zone) + static UInt32 execute(UInt32 t, Int64 seconds, const DateLUTImpl & time_zone, Int64) { return time_zone.toStartOfSecondInterval(t, seconds); } - static Int64 execute(Int64 t, Int64 seconds, Int64 scale_multiplier, UInt8, const DateLUTImpl & time_zone) + static Int64 execute(Int64 t, Int64 seconds, const DateLUTImpl & time_zone, Int64 scale_multiplier) { return time_zone.toStartOfSecondInterval(t / scale_multiplier, seconds); } @@ -620,19 +620,19 @@ struct ToStartOfInterval template <> struct ToStartOfInterval { - static UInt32 execute(UInt16, Int64, Int64, UInt8, const DateLUTImpl &) + static UInt32 execute(UInt16, Int64, const DateLUTImpl &, Int64) { throwDateIsNotSupported(TO_START_OF_INTERVAL_NAME); } - static UInt32 execute(Int32, Int64, Int64, UInt8, const DateLUTImpl &) + static UInt32 execute(Int32, Int64, const DateLUTImpl &, Int64) { throwDate32IsNotSupported(TO_START_OF_INTERVAL_NAME); } - static UInt32 execute(UInt32 t, Int64 minutes, Int64, UInt8, const DateLUTImpl & time_zone) + static UInt32 execute(UInt32 t, Int64 minutes, const DateLUTImpl & time_zone, Int64) { return time_zone.toStartOfMinuteInterval(t, minutes); } - static Int64 execute(Int64 t, Int64 minutes, Int64 scale_multiplier, UInt8, const DateLUTImpl & time_zone) + static Int64 execute(Int64 t, Int64 minutes, const DateLUTImpl & time_zone, Int64 scale_multiplier) { return time_zone.toStartOfMinuteInterval(t / scale_multiplier, minutes); } @@ -641,19 +641,19 @@ struct ToStartOfInterval template <> struct ToStartOfInterval { - static UInt32 execute(UInt16, Int64, Int64, UInt8, const DateLUTImpl &) + static UInt32 execute(UInt16, Int64, const DateLUTImpl &, Int64) { throwDateIsNotSupported(TO_START_OF_INTERVAL_NAME); } - static UInt32 execute(Int32, Int64, Int64, UInt8, const DateLUTImpl &) + static UInt32 execute(Int32, Int64, const DateLUTImpl &, Int64) { throwDate32IsNotSupported(TO_START_OF_INTERVAL_NAME); } - static UInt32 execute(UInt32 t, Int64 hours, Int64, UInt8, const DateLUTImpl & time_zone) + static UInt32 execute(UInt32 t, Int64 hours, const DateLUTImpl & time_zone, Int64) { return time_zone.toStartOfHourInterval(t, hours); } - static Int64 execute(Int64 t, Int64 hours, Int64 scale_multiplier, UInt8, const DateLUTImpl & time_zone) + static Int64 execute(Int64 t, Int64 hours, const DateLUTImpl & time_zone, Int64 scale_multiplier) { return time_zone.toStartOfHourInterval(t / scale_multiplier, hours); } @@ -662,19 +662,19 @@ struct ToStartOfInterval template <> struct ToStartOfInterval { - static UInt32 execute(UInt16 d, Int64 days, Int64, UInt8, const DateLUTImpl & time_zone) + static UInt32 execute(UInt16 d, Int64 days, const DateLUTImpl & time_zone, Int64) { return static_cast(time_zone.toStartOfDayInterval(ExtendedDayNum(d), days)); } - static UInt32 execute(Int32 d, Int64 days, Int64, UInt8, const DateLUTImpl & time_zone) + static UInt32 execute(Int32 d, Int64 days, const DateLUTImpl & time_zone, Int64) { return static_cast(time_zone.toStartOfDayInterval(ExtendedDayNum(d), days)); } - static UInt32 execute(UInt32 t, Int64 days, Int64, UInt8, const DateLUTImpl & time_zone) + static UInt32 execute(UInt32 t, Int64 days, const DateLUTImpl & time_zone, Int64) { return static_cast(time_zone.toStartOfDayInterval(time_zone.toDayNum(t), days)); } - static Int64 execute(Int64 t, Int64 days, Int64 scale_multiplier, UInt8, const DateLUTImpl & time_zone) + static Int64 execute(Int64 t, Int64 days, const DateLUTImpl & time_zone, Int64 scale_multiplier) { return time_zone.toStartOfDayInterval(time_zone.toDayNum(t / scale_multiplier), days); } @@ -683,40 +683,40 @@ struct ToStartOfInterval template <> struct ToStartOfInterval { - static UInt16 execute(UInt16 d, Int64 weeks, Int64, UInt8 week_mode, const DateLUTImpl & time_zone) + static UInt16 execute(UInt16 d, Int64 weeks, const DateLUTImpl & time_zone, Int64) { - return time_zone.toStartOfWeekInterval(DayNum(d), weeks, week_mode); + return time_zone.toStartOfWeekInterval(DayNum(d), weeks); } - static UInt16 execute(Int32 d, Int64 weeks, Int64, UInt8 week_mode, const DateLUTImpl & time_zone) + static UInt16 execute(Int32 d, Int64 weeks, const DateLUTImpl & time_zone, Int64) { - return time_zone.toStartOfWeekInterval(ExtendedDayNum(d), weeks, week_mode); + return time_zone.toStartOfWeekInterval(ExtendedDayNum(d), weeks); } - static UInt16 execute(UInt32 t, Int64 weeks, Int64, UInt8 week_mode, const DateLUTImpl & time_zone) + static UInt16 execute(UInt32 t, Int64 weeks, const DateLUTImpl & time_zone, Int64) { - return time_zone.toStartOfWeekInterval(time_zone.toDayNum(t), weeks, week_mode); + return time_zone.toStartOfWeekInterval(time_zone.toDayNum(t), weeks); } - static UInt16 execute(Int64 t, Int64 weeks, Int64 scale_multiplier, UInt8 week_mode, const DateLUTImpl & time_zone) + static UInt16 execute(Int64 t, Int64 weeks, const DateLUTImpl & time_zone, Int64 scale_multiplier) { - return time_zone.toStartOfWeekInterval(time_zone.toDayNum(t / scale_multiplier), weeks, week_mode); + return time_zone.toStartOfWeekInterval(time_zone.toDayNum(t / scale_multiplier), weeks); } }; template <> struct ToStartOfInterval { - static UInt16 execute(UInt16 d, Int64 months, Int64, UInt8, const DateLUTImpl & time_zone) + static UInt16 execute(UInt16 d, Int64 months, const DateLUTImpl & time_zone, Int64) { return time_zone.toStartOfMonthInterval(DayNum(d), months); } - static UInt16 execute(Int32 d, Int64 months, Int64, UInt8, const DateLUTImpl & time_zone) + static UInt16 execute(Int32 d, Int64 months, const DateLUTImpl & time_zone, Int64) { return time_zone.toStartOfMonthInterval(ExtendedDayNum(d), months); } - static UInt16 execute(UInt32 t, Int64 months, Int64, UInt8, const DateLUTImpl & time_zone) + static UInt16 execute(UInt32 t, Int64 months, const DateLUTImpl & time_zone, Int64) { return time_zone.toStartOfMonthInterval(time_zone.toDayNum(t), months); } - static UInt16 execute(Int64 t, Int64 months, Int64 scale_multiplier, UInt8, const DateLUTImpl & time_zone) + static UInt16 execute(Int64 t, Int64 months, const DateLUTImpl & time_zone, Int64 scale_multiplier) { return time_zone.toStartOfMonthInterval(time_zone.toDayNum(t / scale_multiplier), months); } @@ -725,19 +725,19 @@ struct ToStartOfInterval template <> struct ToStartOfInterval { - static UInt16 execute(UInt16 d, Int64 quarters, Int64, UInt8, const DateLUTImpl & time_zone) + static UInt16 execute(UInt16 d, Int64 quarters, const DateLUTImpl & time_zone, Int64) { return time_zone.toStartOfQuarterInterval(DayNum(d), quarters); } - static UInt16 execute(Int32 d, Int64 quarters, Int64, UInt8, const DateLUTImpl & time_zone) + static UInt16 execute(Int32 d, Int64 quarters, const DateLUTImpl & time_zone, Int64) { return time_zone.toStartOfQuarterInterval(ExtendedDayNum(d), quarters); } - static UInt16 execute(UInt32 t, Int64 quarters, Int64, UInt8, const DateLUTImpl & time_zone) + static UInt16 execute(UInt32 t, Int64 quarters, const DateLUTImpl & time_zone, Int64) { return time_zone.toStartOfQuarterInterval(time_zone.toDayNum(t), quarters); } - static UInt16 execute(Int64 t, Int64 quarters, Int64 scale_multiplier, UInt8, const DateLUTImpl & time_zone) + static UInt16 execute(Int64 t, Int64 quarters, const DateLUTImpl & time_zone, Int64 scale_multiplier) { return time_zone.toStartOfQuarterInterval(time_zone.toDayNum(t / scale_multiplier), quarters); } @@ -746,19 +746,19 @@ struct ToStartOfInterval template <> struct ToStartOfInterval { - static UInt16 execute(UInt16 d, Int64 years, Int64, UInt8, const DateLUTImpl & time_zone) + static UInt16 execute(UInt16 d, Int64 years, const DateLUTImpl & time_zone, Int64) { return time_zone.toStartOfYearInterval(DayNum(d), years); } - static UInt16 execute(Int32 d, Int64 years, Int64, UInt8, const DateLUTImpl & time_zone) + static UInt16 execute(Int32 d, Int64 years, const DateLUTImpl & time_zone, Int64) { return time_zone.toStartOfYearInterval(ExtendedDayNum(d), years); } - static UInt16 execute(UInt32 t, Int64 years, Int64, UInt8, const DateLUTImpl & time_zone) + static UInt16 execute(UInt32 t, Int64 years, const DateLUTImpl & time_zone, Int64) { return time_zone.toStartOfYearInterval(time_zone.toDayNum(t), years); } - static UInt16 execute(Int64 t, Int64 years, Int64 scale_multiplier, UInt8, const DateLUTImpl & time_zone) + static UInt16 execute(Int64 t, Int64 years, const DateLUTImpl & time_zone, Int64 scale_multiplier) { return time_zone.toStartOfYearInterval(time_zone.toDayNum(t / scale_multiplier), years); } diff --git a/src/Functions/FunctionsTimeWindow.h b/src/Functions/FunctionsTimeWindow.h index b3c68cd0c18..6183d25c8bd 100644 --- a/src/Functions/FunctionsTimeWindow.h +++ b/src/Functions/FunctionsTimeWindow.h @@ -39,17 +39,9 @@ struct ToStartOfTransform; TRANSFORM_DATE(Year) TRANSFORM_DATE(Quarter) TRANSFORM_DATE(Month) + TRANSFORM_DATE(Week) #undef TRANSFORM_DATE - template <> - struct ToStartOfTransform - { - static auto execute(UInt32 t, UInt64 delta, const DateLUTImpl & time_zone) - { - return time_zone.toStartOfWeekInterval(time_zone.toDayNum(t), delta, /*week_mode*/ 1); - } - }; - template <> struct ToStartOfTransform { diff --git a/src/Functions/toStartOfInterval.cpp b/src/Functions/toStartOfInterval.cpp index f125e439766..7f25a317466 100644 --- a/src/Functions/toStartOfInterval.cpp +++ b/src/Functions/toStartOfInterval.cpp @@ -2,7 +2,6 @@ #include #include #include -#include #include #include #include @@ -10,7 +9,6 @@ #include #include #include -#include #include @@ -28,13 +26,9 @@ namespace ErrorCodes class FunctionToStartOfInterval : public IFunction { public: - static constexpr auto name = "toStartOfInterval"; + static FunctionPtr create(ContextPtr) { return std::make_shared(); } - static FunctionPtr create(ContextPtr context) { return std::make_shared(context); } - explicit FunctionToStartOfInterval(ContextPtr context) - : first_day_of_week(context->getSettingsRef().first_day_of_week) - { - } + static constexpr auto name = "toStartOfInterval"; String getName() const override { return name; } bool isVariadic() const override { return true; } size_t getNumberOfArguments() const override { return 0; } @@ -253,16 +247,13 @@ private: auto & result_data = col_to->getData(); result_data.resize(size); - const Int64 scale_multiplier = DecimalUtils::scaleMultiplier(scale); - const UInt8 week_mode = (first_day_of_week == FirstDayOfWeek::Monday) ? 1 : 0; + Int64 scale_multiplier = DecimalUtils::scaleMultiplier(scale); for (size_t i = 0; i != size; ++i) - result_data[i] = static_cast(ToStartOfInterval::execute(time_data[i], num_units, scale_multiplier, week_mode, time_zone)); + result_data[i] = static_cast(ToStartOfInterval::execute(time_data[i], num_units, time_zone, scale_multiplier)); return result_col; } - - const FirstDayOfWeek first_day_of_week; }; REGISTER_FUNCTION(ToStartOfInterval) diff --git a/tests/queries/0_stateless/03005_first_day_of_week.reference b/tests/queries/0_stateless/03005_first_day_of_week.reference deleted file mode 100644 index 381802c07a2..00000000000 --- a/tests/queries/0_stateless/03005_first_day_of_week.reference +++ /dev/null @@ -1,4 +0,0 @@ --- toStartOfInterval -2024-01-02 00:00:00 2024-01-01 2023-12-25 -2024-01-02 00:00:00 2024-01-01 2023-12-25 -2024-01-02 00:00:00 2023-12-31 2023-12-24 diff --git a/tests/queries/0_stateless/03005_first_day_of_week.sql b/tests/queries/0_stateless/03005_first_day_of_week.sql deleted file mode 100644 index c7213875fdb..00000000000 --- a/tests/queries/0_stateless/03005_first_day_of_week.sql +++ /dev/null @@ -1,21 +0,0 @@ --- Testing behavior of date/time functions under setting 'first_day_of_week'. - -SELECT '-- toStartOfInterval'; - --- default behavior -SELECT - toDateTime('2024-01-02 00:00:00', 'UTC') dt, - toStartOfInterval(dt, INTERVAL 1 WEEK), -- Monday, Jan 01 - toStartOfInterval(dt, INTERVAL 2 WEEK); -- Monday, Dec 25 - -SELECT - toDateTime('2024-01-02 00:00:00', 'UTC') dt, - toStartOfInterval(dt, INTERVAL 1 WEEK), -- Monday, Jan 01 - toStartOfInterval(dt, INTERVAL 2 WEEK) -- Monday, Dec 25 -SETTINGS first_day_of_week = 'Monday'; - -SELECT - toDateTime('2024-01-02 00:00:00', 'UTC') dt, - toStartOfInterval(dt, INTERVAL 1 WEEK), -- Sunday, Dec 31 - toStartOfInterval(dt, INTERVAL 2 WEEK) -- Sunday, Dec 24 -SETTINGS first_day_of_week = 'Sunday';