mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-22 15:42:02 +00:00
Added function "toDayOfYear" [#CLICKHOUSE-3716]
This commit is contained in:
parent
adb0f65bee
commit
55bc0bb46b
@ -62,6 +62,7 @@ void registerFunctionsDateTime(FunctionFactory & factory)
|
||||
factory.registerFunction<FunctionToMonth>();
|
||||
factory.registerFunction<FunctionToDayOfMonth>();
|
||||
factory.registerFunction<FunctionToDayOfWeek>();
|
||||
factory.registerFunction<FunctionToDayOfYear>();
|
||||
factory.registerFunction<FunctionToHour>();
|
||||
factory.registerFunction<FunctionToMinute>();
|
||||
factory.registerFunction<FunctionToSecond>();
|
||||
|
@ -351,6 +351,22 @@ struct ToDayOfWeekImpl
|
||||
using FactorTransform = ToMondayImpl;
|
||||
};
|
||||
|
||||
struct ToDayOfYearImpl
|
||||
{
|
||||
static constexpr auto name = "toDayOfYear";
|
||||
|
||||
static inline UInt16 execute(UInt32 t, const DateLUTImpl & time_zone)
|
||||
{
|
||||
return time_zone.toDayOfYear(t);
|
||||
}
|
||||
static inline UInt16 execute(UInt16 d, const DateLUTImpl & time_zone)
|
||||
{
|
||||
return time_zone.toDayOfYear(DayNum(d));
|
||||
}
|
||||
|
||||
using FactorTransform = ToStartOfYearImpl;
|
||||
};
|
||||
|
||||
struct ToHourImpl
|
||||
{
|
||||
static constexpr auto name = "toHour";
|
||||
@ -1560,6 +1576,7 @@ using FunctionToQuarter = FunctionDateOrDateTimeToSomething<DataTypeUInt8, ToQua
|
||||
using FunctionToMonth = FunctionDateOrDateTimeToSomething<DataTypeUInt8, ToMonthImpl>;
|
||||
using FunctionToDayOfMonth = FunctionDateOrDateTimeToSomething<DataTypeUInt8, ToDayOfMonthImpl>;
|
||||
using FunctionToDayOfWeek = FunctionDateOrDateTimeToSomething<DataTypeUInt8, ToDayOfWeekImpl>;
|
||||
using FunctionToDayOfYear = FunctionDateOrDateTimeToSomething<DataTypeUInt16, ToDayOfYearImpl>;
|
||||
using FunctionToHour = FunctionDateOrDateTimeToSomething<DataTypeUInt8, ToHourImpl>;
|
||||
using FunctionToMinute = FunctionDateOrDateTimeToSomething<DataTypeUInt8, ToMinuteImpl>;
|
||||
using FunctionToSecond = FunctionDateOrDateTimeToSomething<DataTypeUInt8, ToSecondImpl>;
|
||||
|
@ -309,6 +309,9 @@ public:
|
||||
inline unsigned toYear(DayNum d) const { return lut[d].year; }
|
||||
inline unsigned toDayOfWeek(DayNum d) const { return lut[d].day_of_week; }
|
||||
inline unsigned toDayOfMonth(DayNum d) const { return lut[d].day_of_month; }
|
||||
inline unsigned toDayOfYear(DayNum d) const { return d + 1 - toFirstDayNumOfYear(d); }
|
||||
|
||||
inline unsigned toDayOfYear(time_t t) const { return toDayOfYear(toDayNum(t)); }
|
||||
|
||||
/// Number of week from some fixed moment in the past. Week begins at monday.
|
||||
/// (round down to monday and divide DayNum by 7; we made an assumption,
|
||||
|
Loading…
Reference in New Issue
Block a user