mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-10 01:25:21 +00:00
Apply feedback to toStartOfInterval
This commit is contained in:
parent
cf51d801ae
commit
368d01872f
@ -4384,6 +4384,17 @@ Possible values:
|
||||
|
||||
Default value: `ignore`.
|
||||
|
||||
## first_day_of_week
|
||||
|
||||
The first day of the week (Monday or Sunday) used by `toStartOfInterval` and `date_diff` functions when using weeks as units.
|
||||
|
||||
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.
|
||||
@ -5469,9 +5480,3 @@ Default value: 'false'.
|
||||
## allow_suspicious_primary_key {#allow_suspicious_primary_key}
|
||||
|
||||
Allow suspicious `PRIMARY KEY`/`ORDER BY` for MergeTree (i.e. SimpleAggregateFunction).
|
||||
|
||||
## first_day_of_week
|
||||
|
||||
The first day of the week (Monday or Sunday) used by `toStartOfInterval` and `date_diff` functions when using weeks as units.
|
||||
|
||||
Default value: 'Monday'.
|
||||
|
@ -694,11 +694,11 @@ public:
|
||||
/// (round down to monday and divide DayNum by 7; we made an assumption,
|
||||
/// that in domain of the function there was no weeks with any other number of days than 7)
|
||||
template <typename DateOrTime>
|
||||
Int32 toRelativeWeekNum(DateOrTime v, UInt8 day_of_week_mode = 1) const
|
||||
Int32 toRelativeWeekNum(DateOrTime v, UInt8 week_mode = 1) const
|
||||
{
|
||||
const LUTIndex i = toLUTIndex(v);
|
||||
/// We add 8 to avoid underflow at beginning of unix epoch.
|
||||
return toDayNum(i + (8 - toDayOfWeek(i, day_of_week_mode))) / 7;
|
||||
return toDayNum(i + (8 - toDayOfWeek(i, week_mode))) / 7;
|
||||
}
|
||||
|
||||
/// Get year that contains most of the current week. Week begins at monday.
|
||||
@ -1048,7 +1048,7 @@ public:
|
||||
|
||||
template <typename Date>
|
||||
requires std::is_same_v<Date, DayNum> || std::is_same_v<Date, ExtendedDayNum>
|
||||
auto toStartOfWeekInterval(Date d, UInt64 weeks, UInt8 week_mode = 1) const
|
||||
auto toStartOfWeekInterval(Date d, UInt64 weeks, UInt8 week_mode) const
|
||||
{
|
||||
if (weeks == 1)
|
||||
return toFirstDayNumOfWeek(d, week_mode);
|
||||
|
@ -478,19 +478,19 @@ static constexpr auto TO_START_OF_INTERVAL_NAME = "toStartOfInterval";
|
||||
template <>
|
||||
struct ToStartOfInterval<IntervalKind::Kind::Nanosecond>
|
||||
{
|
||||
static UInt32 execute(UInt16, Int64, const DateLUTImpl &, Int64, UInt8 = 1)
|
||||
static UInt32 execute(UInt16, Int64, Int64, UInt8, const DateLUTImpl &)
|
||||
{
|
||||
throwDateIsNotSupported(TO_START_OF_INTERVAL_NAME);
|
||||
}
|
||||
static UInt32 execute(Int32, Int64, const DateLUTImpl &, Int64, UInt8 = 1)
|
||||
static UInt32 execute(Int32, Int64, Int64, UInt8, const DateLUTImpl &)
|
||||
{
|
||||
throwDate32IsNotSupported(TO_START_OF_INTERVAL_NAME);
|
||||
}
|
||||
static UInt32 execute(UInt32, Int64, const DateLUTImpl &, Int64, UInt8 = 1)
|
||||
static UInt32 execute(UInt32, Int64, Int64, UInt8, const DateLUTImpl &)
|
||||
{
|
||||
throwDateTimeIsNotSupported(TO_START_OF_INTERVAL_NAME);
|
||||
}
|
||||
static Int64 execute(Int64 t, Int64 nanoseconds, const DateLUTImpl &, Int64 scale_multiplier, UInt8 = 1)
|
||||
static Int64 execute(Int64 t, Int64 nanoseconds, Int64 scale_multiplier, UInt8, const DateLUTImpl &)
|
||||
{
|
||||
if (scale_multiplier < 1000000000)
|
||||
{
|
||||
@ -513,19 +513,19 @@ struct ToStartOfInterval<IntervalKind::Kind::Nanosecond>
|
||||
template <>
|
||||
struct ToStartOfInterval<IntervalKind::Kind::Microsecond>
|
||||
{
|
||||
static UInt32 execute(UInt16, Int64, const DateLUTImpl &, Int64, UInt8 = 1)
|
||||
static UInt32 execute(UInt16, Int64, Int64, UInt8, const DateLUTImpl &)
|
||||
{
|
||||
throwDateIsNotSupported(TO_START_OF_INTERVAL_NAME);
|
||||
}
|
||||
static UInt32 execute(Int32, Int64, const DateLUTImpl &, Int64, UInt8 = 1)
|
||||
static UInt32 execute(Int32, Int64, Int64, UInt8, const DateLUTImpl &)
|
||||
{
|
||||
throwDate32IsNotSupported(TO_START_OF_INTERVAL_NAME);
|
||||
}
|
||||
static UInt32 execute(UInt32, Int64, const DateLUTImpl &, Int64, UInt8 = 1)
|
||||
static UInt32 execute(UInt32, Int64, Int64, UInt8, const DateLUTImpl &)
|
||||
{
|
||||
throwDateTimeIsNotSupported(TO_START_OF_INTERVAL_NAME);
|
||||
}
|
||||
static Int64 execute(Int64 t, Int64 microseconds, const DateLUTImpl &, Int64 scale_multiplier, UInt8 = 1)
|
||||
static Int64 execute(Int64 t, Int64 microseconds, Int64 scale_multiplier, UInt8, const DateLUTImpl &)
|
||||
{
|
||||
if (scale_multiplier < 1000000)
|
||||
{
|
||||
@ -556,19 +556,19 @@ struct ToStartOfInterval<IntervalKind::Kind::Microsecond>
|
||||
template <>
|
||||
struct ToStartOfInterval<IntervalKind::Kind::Millisecond>
|
||||
{
|
||||
static UInt32 execute(UInt16, Int64, const DateLUTImpl &, Int64, UInt8 = 1)
|
||||
static UInt32 execute(UInt16, Int64, Int64, UInt8, const DateLUTImpl &)
|
||||
{
|
||||
throwDateIsNotSupported(TO_START_OF_INTERVAL_NAME);
|
||||
}
|
||||
static UInt32 execute(Int32, Int64, const DateLUTImpl &, Int64, UInt8 = 1)
|
||||
static UInt32 execute(Int32, Int64, Int64, UInt8, const DateLUTImpl &)
|
||||
{
|
||||
throwDate32IsNotSupported(TO_START_OF_INTERVAL_NAME);
|
||||
}
|
||||
static UInt32 execute(UInt32, Int64, const DateLUTImpl &, Int64, UInt8 = 1)
|
||||
static UInt32 execute(UInt32, Int64, Int64, UInt8, const DateLUTImpl &)
|
||||
{
|
||||
throwDateTimeIsNotSupported(TO_START_OF_INTERVAL_NAME);
|
||||
}
|
||||
static Int64 execute(Int64 t, Int64 milliseconds, const DateLUTImpl &, Int64 scale_multiplier, UInt8 = 1)
|
||||
static Int64 execute(Int64 t, Int64 milliseconds, Int64 scale_multiplier, UInt8, const DateLUTImpl &)
|
||||
{
|
||||
if (scale_multiplier < 1000)
|
||||
{
|
||||
@ -599,19 +599,19 @@ struct ToStartOfInterval<IntervalKind::Kind::Millisecond>
|
||||
template <>
|
||||
struct ToStartOfInterval<IntervalKind::Kind::Second>
|
||||
{
|
||||
static UInt32 execute(UInt16, Int64, const DateLUTImpl &, Int64, UInt8 = 1)
|
||||
static UInt32 execute(UInt16, Int64, Int64, UInt8, const DateLUTImpl &)
|
||||
{
|
||||
throwDateIsNotSupported(TO_START_OF_INTERVAL_NAME);
|
||||
}
|
||||
static UInt32 execute(Int32, Int64, const DateLUTImpl &, Int64, UInt8 = 1)
|
||||
static UInt32 execute(Int32, Int64, Int64, UInt8, const DateLUTImpl &)
|
||||
{
|
||||
throwDate32IsNotSupported(TO_START_OF_INTERVAL_NAME);
|
||||
}
|
||||
static UInt32 execute(UInt32 t, Int64 seconds, const DateLUTImpl & time_zone, Int64, UInt8 = 1)
|
||||
static UInt32 execute(UInt32 t, Int64 seconds, Int64, UInt8, const DateLUTImpl & time_zone)
|
||||
{
|
||||
return time_zone.toStartOfSecondInterval(t, seconds);
|
||||
}
|
||||
static Int64 execute(Int64 t, Int64 seconds, const DateLUTImpl & time_zone, Int64 scale_multiplier, UInt8 = 1)
|
||||
static Int64 execute(Int64 t, Int64 seconds, Int64 scale_multiplier, UInt8, const DateLUTImpl & time_zone)
|
||||
{
|
||||
return time_zone.toStartOfSecondInterval(t / scale_multiplier, seconds);
|
||||
}
|
||||
@ -620,19 +620,19 @@ struct ToStartOfInterval<IntervalKind::Kind::Second>
|
||||
template <>
|
||||
struct ToStartOfInterval<IntervalKind::Kind::Minute>
|
||||
{
|
||||
static UInt32 execute(UInt16, Int64, const DateLUTImpl &, Int64, UInt8 = 1)
|
||||
static UInt32 execute(UInt16, Int64, Int64, UInt8, const DateLUTImpl &)
|
||||
{
|
||||
throwDateIsNotSupported(TO_START_OF_INTERVAL_NAME);
|
||||
}
|
||||
static UInt32 execute(Int32, Int64, const DateLUTImpl &, Int64, UInt8 = 1)
|
||||
static UInt32 execute(Int32, Int64, Int64, UInt8, const DateLUTImpl &)
|
||||
{
|
||||
throwDate32IsNotSupported(TO_START_OF_INTERVAL_NAME);
|
||||
}
|
||||
static UInt32 execute(UInt32 t, Int64 minutes, const DateLUTImpl & time_zone, Int64, UInt8 = 1)
|
||||
static UInt32 execute(UInt32 t, Int64 minutes, Int64, UInt8, const DateLUTImpl & time_zone)
|
||||
{
|
||||
return time_zone.toStartOfMinuteInterval(t, minutes);
|
||||
}
|
||||
static Int64 execute(Int64 t, Int64 minutes, const DateLUTImpl & time_zone, Int64 scale_multiplier, UInt8 = 1)
|
||||
static Int64 execute(Int64 t, Int64 minutes, Int64 scale_multiplier, UInt8, const DateLUTImpl & time_zone)
|
||||
{
|
||||
return time_zone.toStartOfMinuteInterval(t / scale_multiplier, minutes);
|
||||
}
|
||||
@ -641,19 +641,19 @@ struct ToStartOfInterval<IntervalKind::Kind::Minute>
|
||||
template <>
|
||||
struct ToStartOfInterval<IntervalKind::Kind::Hour>
|
||||
{
|
||||
static UInt32 execute(UInt16, Int64, const DateLUTImpl &, Int64, UInt8 = 1)
|
||||
static UInt32 execute(UInt16, Int64, Int64, UInt8, const DateLUTImpl &)
|
||||
{
|
||||
throwDateIsNotSupported(TO_START_OF_INTERVAL_NAME);
|
||||
}
|
||||
static UInt32 execute(Int32, Int64, const DateLUTImpl &, Int64, UInt8 = 1)
|
||||
static UInt32 execute(Int32, Int64, Int64, UInt8, const DateLUTImpl &)
|
||||
{
|
||||
throwDate32IsNotSupported(TO_START_OF_INTERVAL_NAME);
|
||||
}
|
||||
static UInt32 execute(UInt32 t, Int64 hours, const DateLUTImpl & time_zone, Int64, UInt8 = 1)
|
||||
static UInt32 execute(UInt32 t, Int64 hours, Int64, UInt8, const DateLUTImpl & time_zone)
|
||||
{
|
||||
return time_zone.toStartOfHourInterval(t, hours);
|
||||
}
|
||||
static Int64 execute(Int64 t, Int64 hours, const DateLUTImpl & time_zone, Int64 scale_multiplier, UInt8 = 1)
|
||||
static Int64 execute(Int64 t, Int64 hours, Int64 scale_multiplier, UInt8, const DateLUTImpl & time_zone)
|
||||
{
|
||||
return time_zone.toStartOfHourInterval(t / scale_multiplier, hours);
|
||||
}
|
||||
@ -662,19 +662,19 @@ struct ToStartOfInterval<IntervalKind::Kind::Hour>
|
||||
template <>
|
||||
struct ToStartOfInterval<IntervalKind::Kind::Day>
|
||||
{
|
||||
static UInt32 execute(UInt16 d, Int64 days, const DateLUTImpl & time_zone, Int64, UInt8 = 1)
|
||||
static UInt32 execute(UInt16 d, Int64 days, Int64, UInt8, const DateLUTImpl & time_zone)
|
||||
{
|
||||
return static_cast<UInt32>(time_zone.toStartOfDayInterval(ExtendedDayNum(d), days));
|
||||
}
|
||||
static UInt32 execute(Int32 d, Int64 days, const DateLUTImpl & time_zone, Int64, UInt8 = 1)
|
||||
static UInt32 execute(Int32 d, Int64 days, Int64, UInt8, const DateLUTImpl & time_zone)
|
||||
{
|
||||
return static_cast<UInt32>(time_zone.toStartOfDayInterval(ExtendedDayNum(d), days));
|
||||
}
|
||||
static UInt32 execute(UInt32 t, Int64 days, const DateLUTImpl & time_zone, Int64, UInt8 = 1)
|
||||
static UInt32 execute(UInt32 t, Int64 days, Int64, UInt8, const DateLUTImpl & time_zone)
|
||||
{
|
||||
return static_cast<UInt32>(time_zone.toStartOfDayInterval(time_zone.toDayNum(t), days));
|
||||
}
|
||||
static Int64 execute(Int64 t, Int64 days, const DateLUTImpl & time_zone, Int64 scale_multiplier, UInt8 = 1)
|
||||
static Int64 execute(Int64 t, Int64 days, Int64 scale_multiplier, UInt8, const DateLUTImpl & time_zone)
|
||||
{
|
||||
return time_zone.toStartOfDayInterval(time_zone.toDayNum(t / scale_multiplier), days);
|
||||
}
|
||||
@ -683,19 +683,19 @@ struct ToStartOfInterval<IntervalKind::Kind::Day>
|
||||
template <>
|
||||
struct ToStartOfInterval<IntervalKind::Kind::Week>
|
||||
{
|
||||
static UInt16 execute(UInt16 d, Int64 weeks, const DateLUTImpl & time_zone, Int64, UInt8 week_mode = 1)
|
||||
static UInt16 execute(UInt16 d, Int64 weeks, Int64, UInt8 week_mode, const DateLUTImpl & time_zone)
|
||||
{
|
||||
return time_zone.toStartOfWeekInterval(DayNum(d), weeks, week_mode);
|
||||
}
|
||||
static UInt16 execute(Int32 d, Int64 weeks, const DateLUTImpl & time_zone, Int64, UInt8 week_mode = 1)
|
||||
static UInt16 execute(Int32 d, Int64 weeks, Int64, UInt8 week_mode, const DateLUTImpl & time_zone)
|
||||
{
|
||||
return time_zone.toStartOfWeekInterval(ExtendedDayNum(d), weeks, week_mode);
|
||||
}
|
||||
static UInt16 execute(UInt32 t, Int64 weeks, const DateLUTImpl & time_zone, Int64, UInt8 week_mode = 1)
|
||||
static UInt16 execute(UInt32 t, Int64 weeks, Int64, UInt8 week_mode, const DateLUTImpl & time_zone)
|
||||
{
|
||||
return time_zone.toStartOfWeekInterval(time_zone.toDayNum(t), weeks, week_mode);
|
||||
}
|
||||
static UInt16 execute(Int64 t, Int64 weeks, const DateLUTImpl & time_zone, Int64 scale_multiplier, UInt8 week_mode = 1)
|
||||
static UInt16 execute(Int64 t, Int64 weeks, Int64 scale_multiplier, UInt8 week_mode, const DateLUTImpl & time_zone)
|
||||
{
|
||||
return time_zone.toStartOfWeekInterval(time_zone.toDayNum(t / scale_multiplier), weeks, week_mode);
|
||||
}
|
||||
@ -704,19 +704,19 @@ struct ToStartOfInterval<IntervalKind::Kind::Week>
|
||||
template <>
|
||||
struct ToStartOfInterval<IntervalKind::Kind::Month>
|
||||
{
|
||||
static UInt16 execute(UInt16 d, Int64 months, const DateLUTImpl & time_zone, Int64, UInt8 = 1)
|
||||
static UInt16 execute(UInt16 d, Int64 months, Int64, UInt8, const DateLUTImpl & time_zone)
|
||||
{
|
||||
return time_zone.toStartOfMonthInterval(DayNum(d), months);
|
||||
}
|
||||
static UInt16 execute(Int32 d, Int64 months, const DateLUTImpl & time_zone, Int64, UInt8 = 1)
|
||||
static UInt16 execute(Int32 d, Int64 months, Int64, UInt8, const DateLUTImpl & time_zone)
|
||||
{
|
||||
return time_zone.toStartOfMonthInterval(ExtendedDayNum(d), months);
|
||||
}
|
||||
static UInt16 execute(UInt32 t, Int64 months, const DateLUTImpl & time_zone, Int64, UInt8 = 1)
|
||||
static UInt16 execute(UInt32 t, Int64 months, Int64, UInt8, const DateLUTImpl & time_zone)
|
||||
{
|
||||
return time_zone.toStartOfMonthInterval(time_zone.toDayNum(t), months);
|
||||
}
|
||||
static UInt16 execute(Int64 t, Int64 months, const DateLUTImpl & time_zone, Int64 scale_multiplier, UInt8 = 1)
|
||||
static UInt16 execute(Int64 t, Int64 months, Int64 scale_multiplier, UInt8, const DateLUTImpl & time_zone)
|
||||
{
|
||||
return time_zone.toStartOfMonthInterval(time_zone.toDayNum(t / scale_multiplier), months);
|
||||
}
|
||||
@ -725,19 +725,19 @@ struct ToStartOfInterval<IntervalKind::Kind::Month>
|
||||
template <>
|
||||
struct ToStartOfInterval<IntervalKind::Kind::Quarter>
|
||||
{
|
||||
static UInt16 execute(UInt16 d, Int64 quarters, const DateLUTImpl & time_zone, Int64, UInt8 = 1)
|
||||
static UInt16 execute(UInt16 d, Int64 quarters, Int64, UInt8, const DateLUTImpl & time_zone)
|
||||
{
|
||||
return time_zone.toStartOfQuarterInterval(DayNum(d), quarters);
|
||||
}
|
||||
static UInt16 execute(Int32 d, Int64 quarters, const DateLUTImpl & time_zone, Int64, UInt8 = 1)
|
||||
static UInt16 execute(Int32 d, Int64 quarters, Int64, UInt8, const DateLUTImpl & time_zone)
|
||||
{
|
||||
return time_zone.toStartOfQuarterInterval(ExtendedDayNum(d), quarters);
|
||||
}
|
||||
static UInt16 execute(UInt32 t, Int64 quarters, const DateLUTImpl & time_zone, Int64, UInt8 = 1)
|
||||
static UInt16 execute(UInt32 t, Int64 quarters, Int64, UInt8, const DateLUTImpl & time_zone)
|
||||
{
|
||||
return time_zone.toStartOfQuarterInterval(time_zone.toDayNum(t), quarters);
|
||||
}
|
||||
static UInt16 execute(Int64 t, Int64 quarters, const DateLUTImpl & time_zone, Int64 scale_multiplier, UInt8 = 1)
|
||||
static UInt16 execute(Int64 t, Int64 quarters, Int64 scale_multiplier, UInt8, const DateLUTImpl & time_zone)
|
||||
{
|
||||
return time_zone.toStartOfQuarterInterval(time_zone.toDayNum(t / scale_multiplier), quarters);
|
||||
}
|
||||
@ -746,19 +746,19 @@ struct ToStartOfInterval<IntervalKind::Kind::Quarter>
|
||||
template <>
|
||||
struct ToStartOfInterval<IntervalKind::Kind::Year>
|
||||
{
|
||||
static UInt16 execute(UInt16 d, Int64 years, const DateLUTImpl & time_zone, Int64, UInt8 = 1)
|
||||
static UInt16 execute(UInt16 d, Int64 years, Int64, UInt8, const DateLUTImpl & time_zone)
|
||||
{
|
||||
return time_zone.toStartOfYearInterval(DayNum(d), years);
|
||||
}
|
||||
static UInt16 execute(Int32 d, Int64 years, const DateLUTImpl & time_zone, Int64, UInt8 = 1)
|
||||
static UInt16 execute(Int32 d, Int64 years, Int64, UInt8, const DateLUTImpl & time_zone)
|
||||
{
|
||||
return time_zone.toStartOfYearInterval(ExtendedDayNum(d), years);
|
||||
}
|
||||
static UInt16 execute(UInt32 t, Int64 years, const DateLUTImpl & time_zone, Int64, UInt8 = 1)
|
||||
static UInt16 execute(UInt32 t, Int64 years, Int64, UInt8, const DateLUTImpl & time_zone)
|
||||
{
|
||||
return time_zone.toStartOfYearInterval(time_zone.toDayNum(t), years);
|
||||
}
|
||||
static UInt16 execute(Int64 t, Int64 years, const DateLUTImpl & time_zone, Int64 scale_multiplier, UInt8 = 1)
|
||||
static UInt16 execute(Int64 t, Int64 years, Int64 scale_multiplier, UInt8, const DateLUTImpl & time_zone)
|
||||
{
|
||||
return time_zone.toStartOfYearInterval(time_zone.toDayNum(t / scale_multiplier), years);
|
||||
}
|
||||
@ -1741,27 +1741,27 @@ struct ToRelativeWeekNumImpl
|
||||
{
|
||||
static constexpr auto name = "toRelativeWeekNum";
|
||||
|
||||
static auto execute(Int64 t, const DateLUTImpl & time_zone, UInt8 day_of_week_mode = 0)
|
||||
static auto execute(Int64 t, const DateLUTImpl & time_zone, UInt8 week_mode = 0)
|
||||
{
|
||||
if constexpr (precision_ == ResultPrecision::Extended)
|
||||
return static_cast<Int32>(time_zone.toRelativeWeekNum(t, day_of_week_mode));
|
||||
return static_cast<Int32>(time_zone.toRelativeWeekNum(t, week_mode));
|
||||
else
|
||||
return static_cast<UInt16>(time_zone.toRelativeWeekNum(t, day_of_week_mode));
|
||||
return static_cast<UInt16>(time_zone.toRelativeWeekNum(t, week_mode));
|
||||
}
|
||||
static UInt16 execute(UInt32 t, const DateLUTImpl & time_zone, UInt8 day_of_week_mode = 0)
|
||||
static UInt16 execute(UInt32 t, const DateLUTImpl & time_zone, UInt8 week_mode = 0)
|
||||
{
|
||||
return time_zone.toRelativeWeekNum(static_cast<time_t>(t), day_of_week_mode);
|
||||
return time_zone.toRelativeWeekNum(static_cast<time_t>(t), week_mode);
|
||||
}
|
||||
static auto execute(Int32 d, const DateLUTImpl & time_zone, UInt8 day_of_week_mode = 0)
|
||||
static auto execute(Int32 d, const DateLUTImpl & time_zone, UInt8 week_mode = 0)
|
||||
{
|
||||
if constexpr (precision_ == ResultPrecision::Extended)
|
||||
return static_cast<Int32>(time_zone.toRelativeWeekNum(ExtendedDayNum(d), day_of_week_mode));
|
||||
return static_cast<Int32>(time_zone.toRelativeWeekNum(ExtendedDayNum(d), week_mode));
|
||||
else
|
||||
return static_cast<UInt16>(time_zone.toRelativeWeekNum(ExtendedDayNum(d), day_of_week_mode));
|
||||
return static_cast<UInt16>(time_zone.toRelativeWeekNum(ExtendedDayNum(d), week_mode));
|
||||
}
|
||||
static UInt16 execute(UInt16 d, const DateLUTImpl & time_zone, UInt8 day_of_week_mode = 0)
|
||||
static UInt16 execute(UInt16 d, const DateLUTImpl & time_zone, UInt8 week_mode = 0)
|
||||
{
|
||||
return time_zone.toRelativeWeekNum(DayNum(d), day_of_week_mode);
|
||||
return time_zone.toRelativeWeekNum(DayNum(d), week_mode);
|
||||
}
|
||||
static constexpr bool hasPreimage() { return false; }
|
||||
|
||||
|
@ -39,9 +39,17 @@ struct ToStartOfTransform;
|
||||
TRANSFORM_DATE(Year)
|
||||
TRANSFORM_DATE(Quarter)
|
||||
TRANSFORM_DATE(Month)
|
||||
TRANSFORM_DATE(Week)
|
||||
#undef TRANSFORM_DATE
|
||||
|
||||
template <>
|
||||
struct ToStartOfTransform<IntervalKind::Kind::Week>
|
||||
{
|
||||
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<IntervalKind::Kind::Day>
|
||||
{
|
||||
|
@ -1,5 +1,3 @@
|
||||
#include "Core/SettingsEnums.h"
|
||||
#include "Interpreters/Context.h"
|
||||
|
||||
#include <DataTypes/DataTypeDateTime.h>
|
||||
#include <DataTypes/DataTypeDateTime64.h>
|
||||
@ -9,6 +7,7 @@
|
||||
#include <Columns/ColumnsDateTime.h>
|
||||
#include <Columns/ColumnsNumber.h>
|
||||
#include <Columns/ColumnDecimal.h>
|
||||
#include <Core/SettingsEnums.h>
|
||||
#include <Formats/FormatSettings.h>
|
||||
#include <Functions/IFunction.h>
|
||||
#include <Functions/FunctionHelpers.h>
|
||||
@ -17,6 +16,7 @@
|
||||
#include <Functions/DateTimeTransforms.h>
|
||||
#include <Functions/TransformDateTime64.h>
|
||||
|
||||
#include <Interpreters/Context.h>
|
||||
#include <IO/WriteHelpers.h>
|
||||
|
||||
#include <base/find_symbols.h>
|
||||
@ -44,9 +44,9 @@ class DateDiffImpl
|
||||
public:
|
||||
using ColumnDateTime64 = ColumnDecimal<DateTime64>;
|
||||
|
||||
explicit DateDiffImpl(const String & name_, FirstDayOfWeek first_day_of_week)
|
||||
DateDiffImpl(const String & name_, FirstDayOfWeek first_day_of_week_)
|
||||
: name(name_)
|
||||
, enable_default_monday_first(first_day_of_week != FirstDayOfWeek::Sunday)
|
||||
, first_day_of_week(first_day_of_week_)
|
||||
{}
|
||||
|
||||
template <typename Transform>
|
||||
@ -173,12 +173,12 @@ public:
|
||||
template <typename TransformX, typename TransformY, typename T1, typename T2>
|
||||
Int64 calculate(const TransformX & transform_x, const TransformY & transform_y, T1 x, T2 y, const DateLUTImpl & timezone_x, const DateLUTImpl & timezone_y) const
|
||||
{
|
||||
UInt8 day_of_week_mode = enable_default_monday_first ? 0 : 3;
|
||||
UInt8 week_mode = first_day_of_week == FirstDayOfWeek::Monday ? 0 : 3;
|
||||
|
||||
if constexpr (is_diff)
|
||||
{
|
||||
return static_cast<Int64>(transform_y.execute(y, timezone_y, day_of_week_mode))
|
||||
- static_cast<Int64>(transform_x.execute(x, timezone_x, day_of_week_mode));
|
||||
return static_cast<Int64>(transform_y.execute(y, timezone_y, week_mode))
|
||||
- static_cast<Int64>(transform_x.execute(x, timezone_x, week_mode));
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -322,7 +322,7 @@ public:
|
||||
}
|
||||
private:
|
||||
String name;
|
||||
const bool enable_default_monday_first = true;
|
||||
FirstDayOfWeek first_day_of_week;
|
||||
};
|
||||
|
||||
|
||||
@ -439,7 +439,7 @@ public:
|
||||
return res;
|
||||
}
|
||||
private:
|
||||
FirstDayOfWeek first_day_of_week = FirstDayOfWeek::Monday;
|
||||
FirstDayOfWeek first_day_of_week;
|
||||
DateDiffImpl<is_relative> impl{name, first_day_of_week};
|
||||
};
|
||||
|
||||
|
@ -1,9 +1,8 @@
|
||||
#include "Interpreters/Context.h"
|
||||
|
||||
#include <Columns/ColumnsDateTime.h>
|
||||
#include <Columns/ColumnsNumber.h>
|
||||
#include <Common/DateLUTImpl.h>
|
||||
#include <Common/IntervalKind.h>
|
||||
#include <Core/SettingsEnums.h>
|
||||
#include <DataTypes/DataTypeDate.h>
|
||||
#include <DataTypes/DataTypeDateTime.h>
|
||||
#include <DataTypes/DataTypeDateTime64.h>
|
||||
@ -11,6 +10,7 @@
|
||||
#include <Functions/DateTimeTransforms.h>
|
||||
#include <Functions/FunctionFactory.h>
|
||||
#include <Functions/IFunction.h>
|
||||
#include <Interpreters/Context.h>
|
||||
#include <IO/WriteHelpers.h>
|
||||
|
||||
|
||||
@ -27,13 +27,13 @@ namespace ErrorCodes
|
||||
|
||||
class FunctionToStartOfInterval : public IFunction
|
||||
{
|
||||
const bool enable_default_monday_first = true;
|
||||
FirstDayOfWeek first_day_of_week;
|
||||
|
||||
public:
|
||||
static FunctionPtr create(ContextPtr context) { return std::make_shared<FunctionToStartOfInterval>(context); }
|
||||
|
||||
explicit FunctionToStartOfInterval(ContextPtr context)
|
||||
: enable_default_monday_first(context->getSettingsRef().first_day_of_week != FirstDayOfWeek::Sunday)
|
||||
: first_day_of_week(context->getSettingsRef().first_day_of_week)
|
||||
{
|
||||
}
|
||||
|
||||
@ -257,11 +257,11 @@ private:
|
||||
result_data.resize(size);
|
||||
|
||||
Int64 scale_multiplier = DecimalUtils::scaleMultiplier<DateTime64>(scale);
|
||||
UInt8 week_mode = enable_default_monday_first ? 1 : 0;
|
||||
UInt8 week_mode = first_day_of_week == FirstDayOfWeek::Monday ? 1 : 0;
|
||||
|
||||
for (size_t i = 0; i != size; ++i)
|
||||
{
|
||||
result_data[i] = static_cast<ResultFieldType>(ToStartOfInterval<unit>::execute(time_data[i], num_units, time_zone, scale_multiplier, week_mode));
|
||||
result_data[i] = static_cast<ResultFieldType>(ToStartOfInterval<unit>::execute(time_data[i], num_units, scale_multiplier, week_mode, time_zone));
|
||||
}
|
||||
|
||||
return result_col;
|
||||
|
Loading…
Reference in New Issue
Block a user