| 1 | #include <Functions/FunctionFactory.h> |
|---|---|
| 2 | #include <Functions/FunctionUnaryArithmetic.h> |
| 3 | |
| 4 | namespace DB |
| 5 | { |
| 6 | |
| 7 | template <typename A> |
| 8 | struct RoundAgeImpl |
| 9 | { |
| 10 | using ResultType = UInt8; |
| 11 | |
| 12 | static inline ResultType apply(A x) |
| 13 | { |
| 14 | return x < 1 ? 0 |
| 15 | : (x < 18 ? 17 |
| 16 | : (x < 25 ? 18 |
| 17 | : (x < 35 ? 25 |
| 18 | : (x < 45 ? 35 |
| 19 | : (x < 55 ? 45 |
| 20 | : 55))))); |
| 21 | } |
| 22 | |
| 23 | #if USE_EMBEDDED_COMPILER |
| 24 | static constexpr bool compilable = false; |
| 25 | #endif |
| 26 | }; |
| 27 | |
| 28 | struct NameRoundAge { static constexpr auto name = "roundAge"; }; |
| 29 | using FunctionRoundAge = FunctionUnaryArithmetic<RoundAgeImpl, NameRoundAge, false>; |
| 30 | |
| 31 | template <> struct FunctionUnaryArithmeticMonotonicity<NameRoundAge> : PositiveMonotonicity {}; |
| 32 | |
| 33 | void registerFunctionRoundAge(FunctionFactory & factory) |
| 34 | { |
| 35 | factory.registerFunction<FunctionRoundAge>(); |
| 36 | } |
| 37 | |
| 38 | } |
| 39 |