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 RoundAgeImpl
|
|
|
|
{
|
|
|
|
using ResultType = UInt8;
|
2023-04-22 17:21:43 +00:00
|
|
|
static constexpr const 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 < 18 ? 17
|
|
|
|
: (x < 25 ? 18
|
|
|
|
: (x < 35 ? 25
|
|
|
|
: (x < 45 ? 35
|
|
|
|
: (x < 55 ? 45
|
|
|
|
: 55)))));
|
|
|
|
}
|
|
|
|
|
|
|
|
#if USE_EMBEDDED_COMPILER
|
|
|
|
static constexpr bool compilable = false;
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
struct NameRoundAge { static constexpr auto name = "roundAge"; };
|
|
|
|
using FunctionRoundAge = FunctionUnaryArithmetic<RoundAgeImpl, NameRoundAge, false>;
|
|
|
|
|
2020-09-07 18:00:37 +00:00
|
|
|
}
|
|
|
|
|
2018-11-26 16:20:40 +00:00
|
|
|
template <> struct FunctionUnaryArithmeticMonotonicity<NameRoundAge> : PositiveMonotonicity {};
|
|
|
|
|
2022-07-04 07:01:39 +00:00
|
|
|
REGISTER_FUNCTION(RoundAge)
|
2018-11-26 16:20:40 +00:00
|
|
|
{
|
|
|
|
factory.registerFunction<FunctionRoundAge>();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|