#include #include #include namespace DB { template struct SignImpl { using ResultType = Int8; static const constexpr bool allow_fixed_string = false; static const constexpr bool allow_string_integer = false; static inline NO_SANITIZE_UNDEFINED ResultType apply(A a) { if constexpr (is_decimal || std::is_floating_point_v) return a < A(0) ? -1 : a == A(0) ? 0 : 1; else if constexpr (is_signed_v) return a < 0 ? -1 : a == 0 ? 0 : 1; else if constexpr (is_unsigned_v) return a == 0 ? 0 : 1; } #if USE_EMBEDDED_COMPILER static constexpr bool compilable = false; #endif }; struct NameSign { static constexpr auto name = "sign"; }; using FunctionSign = FunctionUnaryArithmetic; template <> struct FunctionUnaryArithmeticMonotonicity { static bool has() { return true; } static IFunction::Monotonicity get(const Field &, const Field &) { return { .is_monotonic = true }; } }; void registerFunctionSign(FunctionFactory & factory) { factory.registerFunction(FunctionFactory::CaseInsensitive); } }