diff --git a/src/Core/DecimalFunctions.h b/src/Core/DecimalFunctions.h index bd30568bb313ce621aa51b8bbd425c2f63b98723..2b916cbf5384df3a6c166a7d53e8b96410819c60 100644 --- a/src/Core/DecimalFunctions.h +++ b/src/Core/DecimalFunctions.h @@ -6,6 +6,7 @@ #include #include +#include namespace DB diff --git a/src/Functions/FunctionBinaryArithmetic.h b/src/Functions/FunctionBinaryArithmetic.h index 8c684d3578f574038b450bd5e2bf5e3b209df572..848de3445852ad3e53fcfa0022c403b502ac1608 100644 --- a/src/Functions/FunctionBinaryArithmetic.h +++ b/src/Functions/FunctionBinaryArithmetic.h @@ -3,6 +3,8 @@ // Include this first, because `#define _asan_poison_address` from // llvm/Support/Compiler.h conflicts with its forward declaration in // sanitizer/asan_interface.h +#include +#include #include #include @@ -20,6 +22,7 @@ #include #include #include +#include "Core/DecimalFunctions.h" #include "IFunctionImpl.h" #include "FunctionHelpers.h" #include "IsOperation.h" @@ -43,6 +46,8 @@ # pragma GCC diagnostic pop #endif +#include + namespace DB { @@ -57,6 +62,117 @@ namespace ErrorCodes extern const int NUMBER_OF_ARGUMENTS_DOESNT_MATCH; } +namespace traits_ +{ +struct InvalidType; /// Used to indicate undefined operation + +template struct Case : std::bool_constant { using type = T; }; + +/// Switch, ...> -- select the first Ti for which Ci is true, InvalidType if none. +template using Switch = typename std::disjunction>::type; + +template +using DataTypeFromFieldType = std::conditional_t, + InvalidType, DataTypeNumber>; + +template constexpr bool IsIntegral = false; +template <> inline constexpr bool IsIntegral = true; +template <> inline constexpr bool IsIntegral = true; +template <> inline constexpr bool IsIntegral = true; +template <> inline constexpr bool IsIntegral = true; +template <> inline constexpr bool IsIntegral = true; +template <> inline constexpr bool IsIntegral = true; +template <> inline constexpr bool IsIntegral = true; +template <> inline constexpr bool IsIntegral = true; + +template constexpr bool IsExtended = false; +template <> inline constexpr bool IsExtended = true; +template <> inline constexpr bool IsExtended = true; +template <> inline constexpr bool IsExtended = true; + +template constexpr bool IsIntegralOrExtended = IsIntegral || IsExtended; +template constexpr bool IsIntegralOrExtendedOrDecimal = + IsIntegralOrExtended || + IsDataTypeDecimal; + +template constexpr bool IsFloatingPoint = false; +template <> inline constexpr bool IsFloatingPoint = true; +template <> inline constexpr bool IsFloatingPoint = true; + +template constexpr bool IsDateOrDateTime = false; +template <> inline constexpr bool IsDateOrDateTime = true; +template <> inline constexpr bool IsDateOrDateTime = true; + +template constexpr bool UseLeftDecimal = false; +template <> inline constexpr bool UseLeftDecimal, DataTypeDecimal> = true; +template <> inline constexpr bool UseLeftDecimal, DataTypeDecimal> = true; +template <> inline constexpr bool UseLeftDecimal, DataTypeDecimal> = true; +template <> inline constexpr bool UseLeftDecimal, DataTypeDecimal> = true; +template <> inline constexpr bool UseLeftDecimal, DataTypeDecimal> = true; +template <> inline constexpr bool UseLeftDecimal, DataTypeDecimal> = true; + +template