| 1 | #include <Functions/FunctionFactory.h> |
|---|---|
| 2 | #include <Functions/FunctionUnaryArithmetic.h> |
| 3 | |
| 4 | namespace DB |
| 5 | { |
| 6 | |
| 7 | template <typename A> |
| 8 | struct RoundDurationImpl |
| 9 | { |
| 10 | using ResultType = UInt16; |
| 11 | |
| 12 | static inline ResultType apply(A x) |
| 13 | { |
| 14 | return x < 1 ? 0 |
| 15 | : (x < 10 ? 1 |
| 16 | : (x < 30 ? 10 |
| 17 | : (x < 60 ? 30 |
| 18 | : (x < 120 ? 60 |
| 19 | : (x < 180 ? 120 |
| 20 | : (x < 240 ? 180 |
| 21 | : (x < 300 ? 240 |
| 22 | : (x < 600 ? 300 |
| 23 | : (x < 1200 ? 600 |
| 24 | : (x < 1800 ? 1200 |
| 25 | : (x < 3600 ? 1800 |
| 26 | : (x < 7200 ? 3600 |
| 27 | : (x < 18000 ? 7200 |
| 28 | : (x < 36000 ? 18000 |
| 29 | : 36000)))))))))))))); |
| 30 | } |
| 31 | |
| 32 | #if USE_EMBEDDED_COMPILER |
| 33 | static constexpr bool compilable = false; |
| 34 | #endif |
| 35 | }; |
| 36 | |
| 37 | struct NameRoundDuration { static constexpr auto name = "roundDuration"; }; |
| 38 | using FunctionRoundDuration = FunctionUnaryArithmetic<RoundDurationImpl, NameRoundDuration, false>; |
| 39 | |
| 40 | template <> struct FunctionUnaryArithmeticMonotonicity<NameRoundDuration> : PositiveMonotonicity {}; |
| 41 | |
| 42 | void registerFunctionRoundDuration(FunctionFactory & factory) |
| 43 | { |
| 44 | factory.registerFunction<FunctionRoundDuration>(); |
| 45 | } |
| 46 | |
| 47 | } |
| 48 |