2018-11-26 16:20:40 +00:00
|
|
|
#include <Functions/FunctionFactory.h>
|
|
|
|
#include <Functions/FunctionUnaryArithmetic.h>
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
2020-09-07 18:00:37 +00:00
|
|
|
namespace
|
|
|
|
{
|
2018-11-26 16:20:40 +00:00
|
|
|
|
|
|
|
template <typename A>
|
|
|
|
struct RoundDurationImpl
|
|
|
|
{
|
|
|
|
using ResultType = UInt16;
|
2023-04-22 17:21:43 +00:00
|
|
|
static constexpr bool allow_string_or_fixed_string = false;
|
2018-11-26 16:20:40 +00:00
|
|
|
|
|
|
|
static inline ResultType apply(A x)
|
|
|
|
{
|
|
|
|
return x < 1 ? 0
|
|
|
|
: (x < 10 ? 1
|
|
|
|
: (x < 30 ? 10
|
|
|
|
: (x < 60 ? 30
|
|
|
|
: (x < 120 ? 60
|
|
|
|
: (x < 180 ? 120
|
|
|
|
: (x < 240 ? 180
|
|
|
|
: (x < 300 ? 240
|
|
|
|
: (x < 600 ? 300
|
|
|
|
: (x < 1200 ? 600
|
|
|
|
: (x < 1800 ? 1200
|
|
|
|
: (x < 3600 ? 1800
|
|
|
|
: (x < 7200 ? 3600
|
|
|
|
: (x < 18000 ? 7200
|
|
|
|
: (x < 36000 ? 18000
|
|
|
|
: 36000))))))))))))));
|
|
|
|
}
|
|
|
|
|
|
|
|
#if USE_EMBEDDED_COMPILER
|
|
|
|
static constexpr bool compilable = false;
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
struct NameRoundDuration { static constexpr auto name = "roundDuration"; };
|
|
|
|
using FunctionRoundDuration = FunctionUnaryArithmetic<RoundDurationImpl, NameRoundDuration, false>;
|
|
|
|
|
2020-09-07 18:00:37 +00:00
|
|
|
}
|
|
|
|
|
2018-11-26 16:20:40 +00:00
|
|
|
template <> struct FunctionUnaryArithmeticMonotonicity<NameRoundDuration> : PositiveMonotonicity {};
|
|
|
|
|
2022-07-04 07:01:39 +00:00
|
|
|
REGISTER_FUNCTION(RoundDuration)
|
2018-11-26 16:20:40 +00:00
|
|
|
{
|
|
|
|
factory.registerFunction<FunctionRoundDuration>();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|