mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-21 23:21:59 +00:00
Add function toStartOfTenMinutes().
This commit is contained in:
parent
2556a96e9e
commit
7cbdb17f5b
@ -188,6 +188,22 @@ struct ToStartOfFiveMinuteImpl
|
||||
using FactorTransform = ZeroTransform;
|
||||
};
|
||||
|
||||
struct ToStartOfTenMinutesImpl
|
||||
{
|
||||
static constexpr auto name = "toStartOfTenMinutes";
|
||||
|
||||
static inline UInt32 execute(UInt32 t, const DateLUTImpl & time_zone)
|
||||
{
|
||||
return time_zone.toStartOfTenMinutes(t);
|
||||
}
|
||||
static inline UInt32 execute(UInt16, const DateLUTImpl &)
|
||||
{
|
||||
return dateIsNotSupported(name);
|
||||
}
|
||||
|
||||
using FactorTransform = ZeroTransform;
|
||||
};
|
||||
|
||||
struct ToStartOfFifteenMinutesImpl
|
||||
{
|
||||
static constexpr auto name = "toStartOfFifteenMinutes";
|
||||
|
@ -21,6 +21,7 @@ void registerFunctionToStartOfQuarter(FunctionFactory &);
|
||||
void registerFunctionToStartOfYear(FunctionFactory &);
|
||||
void registerFunctionToStartOfMinute(FunctionFactory &);
|
||||
void registerFunctionToStartOfFiveMinute(FunctionFactory &);
|
||||
void registerFunctionToStartOfTenMinutes(FunctionFactory &);
|
||||
void registerFunctionToStartOfFifteenMinutes(FunctionFactory &);
|
||||
void registerFunctionToStartOfHour(FunctionFactory &);
|
||||
void registerFunctionToStartOfISOYear(FunctionFactory &);
|
||||
@ -82,6 +83,7 @@ void registerFunctionsDateTime(FunctionFactory & factory)
|
||||
registerFunctionToStartOfYear(factory);
|
||||
registerFunctionToStartOfMinute(factory);
|
||||
registerFunctionToStartOfFiveMinute(factory);
|
||||
registerFunctionToStartOfTenMinutes(factory);
|
||||
registerFunctionToStartOfFifteenMinutes(factory);
|
||||
registerFunctionToStartOfHour(factory);
|
||||
registerFunctionToStartOfISOYear(factory);
|
||||
|
20
dbms/src/Functions/toStartOfTenMinutes.cpp
Normal file
20
dbms/src/Functions/toStartOfTenMinutes.cpp
Normal file
@ -0,0 +1,20 @@
|
||||
#include <Functions/IFunction.h>
|
||||
#include <Functions/FunctionFactory.h>
|
||||
#include <Functions/DateTimeTransforms.h>
|
||||
#include <Functions/FunctionDateOrDateTimeToSomething.h>
|
||||
#include <DataTypes/DataTypesNumber.h>
|
||||
|
||||
|
||||
namespace DB
|
||||
{
|
||||
|
||||
using FunctionToStartOfTenMinutes = FunctionDateOrDateTimeToSomething<DataTypeDateTime, ToStartOfTenMinutesImpl>;
|
||||
|
||||
void registerFunctionToStartOfTenMinutes(FunctionFactory & factory)
|
||||
{
|
||||
factory.registerFunction<FunctionToStartOfTenMinutes>();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -58,16 +58,31 @@
|
||||
0
|
||||
0
|
||||
0
|
||||
2014-09-30 23:50:00
|
||||
2014-09-30 21:50:00
|
||||
2014-09-30 20:50:00
|
||||
2014-10-01 04:50:00
|
||||
2014-09-30 11:50:00
|
||||
2014-09-30 23:00:00
|
||||
2014-09-30 21:00:00
|
||||
2014-09-30 20:00:00
|
||||
2014-10-01 04:00:00
|
||||
2014-09-30 11:00:00
|
||||
2019-02-06 22:57:00
|
||||
2019-02-06 20:57:00
|
||||
2019-02-06 19:57:00
|
||||
2019-02-07 04:57:00
|
||||
2019-02-06 11:57:00
|
||||
2019-02-06 22:55:00
|
||||
2019-02-06 20:55:00
|
||||
2019-02-06 19:55:00
|
||||
2019-02-07 04:55:00
|
||||
2019-02-06 11:55:00
|
||||
2019-02-06 22:50:00
|
||||
2019-02-06 20:50:00
|
||||
2019-02-06 19:50:00
|
||||
2019-02-07 04:50:00
|
||||
2019-02-06 11:50:00
|
||||
2019-02-06 22:45:00
|
||||
2019-02-06 20:45:00
|
||||
2019-02-06 19:45:00
|
||||
2019-02-07 04:45:00
|
||||
2019-02-06 11:45:00
|
||||
2019-02-06 22:00:00
|
||||
2019-02-06 20:00:00
|
||||
2019-02-06 19:00:00
|
||||
2019-02-07 04:00:00
|
||||
2019-02-06 11:00:00
|
||||
44
|
||||
44
|
||||
44
|
||||
|
@ -104,19 +104,43 @@ SELECT toSecond(toDateTime(1412106600), 'Pacific/Pitcairn');
|
||||
|
||||
/* toStartOfMinute */
|
||||
|
||||
SELECT toString(toStartOfMinute(toDateTime(1412106600), 'Europe/Moscow'), 'Europe/Moscow');
|
||||
SELECT toString(toStartOfMinute(toDateTime(1412106600), 'Europe/Paris'), 'Europe/Paris');
|
||||
SELECT toString(toStartOfMinute(toDateTime(1412106600), 'Europe/London'), 'Europe/London');
|
||||
SELECT toString(toStartOfMinute(toDateTime(1412106600), 'Asia/Tokyo'), 'Asia/Tokyo');
|
||||
SELECT toString(toStartOfMinute(toDateTime(1412106600), 'Pacific/Pitcairn'), 'Pacific/Pitcairn');
|
||||
SELECT toString(toStartOfMinute(toDateTime(1549483055), 'Europe/Moscow'), 'Europe/Moscow');
|
||||
SELECT toString(toStartOfMinute(toDateTime(1549483055), 'Europe/Paris'), 'Europe/Paris');
|
||||
SELECT toString(toStartOfMinute(toDateTime(1549483055), 'Europe/London'), 'Europe/London');
|
||||
SELECT toString(toStartOfMinute(toDateTime(1549483055), 'Asia/Tokyo'), 'Asia/Tokyo');
|
||||
SELECT toString(toStartOfMinute(toDateTime(1549483055), 'Pacific/Pitcairn'), 'Pacific/Pitcairn');
|
||||
|
||||
/* toStartOfFiveMinute */
|
||||
|
||||
SELECT toString(toStartOfFiveMinute(toDateTime(1549483055), 'Europe/Moscow'), 'Europe/Moscow');
|
||||
SELECT toString(toStartOfFiveMinute(toDateTime(1549483055), 'Europe/Paris'), 'Europe/Paris');
|
||||
SELECT toString(toStartOfFiveMinute(toDateTime(1549483055), 'Europe/London'), 'Europe/London');
|
||||
SELECT toString(toStartOfFiveMinute(toDateTime(1549483055), 'Asia/Tokyo'), 'Asia/Tokyo');
|
||||
SELECT toString(toStartOfFiveMinute(toDateTime(1549483055), 'Pacific/Pitcairn'), 'Pacific/Pitcairn');
|
||||
|
||||
/* toStartOfTenMinutes */
|
||||
|
||||
SELECT toString(toStartOfTenMinutes(toDateTime(1549483055), 'Europe/Moscow'), 'Europe/Moscow');
|
||||
SELECT toString(toStartOfTenMinutes(toDateTime(1549483055), 'Europe/Paris'), 'Europe/Paris');
|
||||
SELECT toString(toStartOfTenMinutes(toDateTime(1549483055), 'Europe/London'), 'Europe/London');
|
||||
SELECT toString(toStartOfTenMinutes(toDateTime(1549483055), 'Asia/Tokyo'), 'Asia/Tokyo');
|
||||
SELECT toString(toStartOfTenMinutes(toDateTime(1549483055), 'Pacific/Pitcairn'), 'Pacific/Pitcairn');
|
||||
|
||||
/* toStartOfTenMinutes */
|
||||
|
||||
SELECT toString(toStartOfFifteenMinutes(toDateTime(1549483055), 'Europe/Moscow'), 'Europe/Moscow');
|
||||
SELECT toString(toStartOfFifteenMinutes(toDateTime(1549483055), 'Europe/Paris'), 'Europe/Paris');
|
||||
SELECT toString(toStartOfFifteenMinutes(toDateTime(1549483055), 'Europe/London'), 'Europe/London');
|
||||
SELECT toString(toStartOfFifteenMinutes(toDateTime(1549483055), 'Asia/Tokyo'), 'Asia/Tokyo');
|
||||
SELECT toString(toStartOfFifteenMinutes(toDateTime(1549483055), 'Pacific/Pitcairn'), 'Pacific/Pitcairn');
|
||||
|
||||
/* toStartOfHour */
|
||||
|
||||
SELECT toString(toStartOfHour(toDateTime(1412106600), 'Europe/Moscow'), 'Europe/Moscow');
|
||||
SELECT toString(toStartOfHour(toDateTime(1412106600), 'Europe/Paris'), 'Europe/Paris');
|
||||
SELECT toString(toStartOfHour(toDateTime(1412106600), 'Europe/London'), 'Europe/London');
|
||||
SELECT toString(toStartOfHour(toDateTime(1412106600), 'Asia/Tokyo'), 'Asia/Tokyo');
|
||||
SELECT toString(toStartOfHour(toDateTime(1412106600), 'Pacific/Pitcairn'), 'Pacific/Pitcairn');
|
||||
SELECT toString(toStartOfHour(toDateTime(1549483055), 'Europe/Moscow'), 'Europe/Moscow');
|
||||
SELECT toString(toStartOfHour(toDateTime(1549483055), 'Europe/Paris'), 'Europe/Paris');
|
||||
SELECT toString(toStartOfHour(toDateTime(1549483055), 'Europe/London'), 'Europe/London');
|
||||
SELECT toString(toStartOfHour(toDateTime(1549483055), 'Asia/Tokyo'), 'Asia/Tokyo');
|
||||
SELECT toString(toStartOfHour(toDateTime(1549483055), 'Pacific/Pitcairn'), 'Pacific/Pitcairn');
|
||||
|
||||
/* toRelativeYearNum */
|
||||
|
||||
|
@ -284,6 +284,15 @@ public:
|
||||
inline time_t toStartOfFiveMinute(time_t t) const { return t / 300 * 300; }
|
||||
inline time_t toStartOfFifteenMinutes(time_t t) const { return t / 900 * 900; }
|
||||
|
||||
inline time_t toStartOfTenMinutes(time_t t) const
|
||||
{
|
||||
if (offset_is_whole_number_of_hours_everytime)
|
||||
return t / 600 * 600;
|
||||
|
||||
time_t date = find(t).date;
|
||||
return date + (t - date) / 600 * 600;
|
||||
}
|
||||
|
||||
inline time_t toStartOfHour(time_t t) const
|
||||
{
|
||||
if (offset_is_whole_number_of_hours_everytime)
|
||||
|
Loading…
Reference in New Issue
Block a user