diff --git a/dbms/include/DB/Functions/FunctionsArithmetic.h b/dbms/include/DB/Functions/FunctionsArithmetic.h index b00b31a1158..ea38395fa63 100644 --- a/dbms/include/DB/Functions/FunctionsArithmetic.h +++ b/dbms/include/DB/Functions/FunctionsArithmetic.h @@ -262,6 +262,30 @@ struct BitShiftRightImpl } }; +template +struct LeastImpl +{ + typedef typename NumberTraits::ResultOfIf::Type ResultType; + + template + static inline Result apply(A a, B b) + { + return static_cast(a) < static_cast(b) ? static_cast(a) : static_cast(b); + } +}; + +template +struct GreatestImpl +{ + typedef typename NumberTraits::ResultOfIf::Type ResultType; + + template + static inline Result apply(A a, B b) + { + return static_cast(a) > static_cast(b) ? static_cast(a) : static_cast(b); + } +}; + template struct NegateImpl { @@ -319,6 +343,12 @@ template using Else = T; /// Used to indicate undefined operation struct InvalidType; +template <> +struct DataTypeFromFieldType +{ + using Type = InvalidType; +}; + template struct IsIntegral { static constexpr auto value = false; }; template <> struct IsIntegral { static constexpr auto value = true; }; template <> struct IsIntegral { static constexpr auto value = true; }; @@ -342,11 +372,13 @@ template struct IsDateOrDateTime { static constexpr auto val template <> struct IsDateOrDateTime { static constexpr auto value = true; }; template <> struct IsDateOrDateTime { static constexpr auto value = true; }; -/** Returns appropriate result type for binary operator on dates: +/** Returns appropriate result type for binary operator on dates (or datetimes): * Date + Integral -> Date * Integral + Date -> Date * Date - Date -> Int32 * Date - Integral -> Date + * least(Date, Date) -> Date + * greatest(Date, Date) -> Date * All other operations are not defined and return InvalidType, operations on * distinct date types are also undefined (e.g. DataTypeDate - DataTypeDateTime) */ template