#include #include #include namespace DB { template struct PlusImpl { using ResultType = typename NumberTraits::ResultOfAdditionMultiplication::Type; static const constexpr bool allow_fixed_string = false; static const constexpr bool allow_string_integer = false; static const constexpr bool is_commutative = true; template static inline NO_SANITIZE_UNDEFINED Result apply(A a, B b) { /// Next everywhere, static_cast - so that there is no wrong result in expressions of the form Int64 c = UInt32(a) * Int32(-1). if constexpr (is_big_int_v || is_big_int_v) { using CastA = std::conditional_t, B, A>; using CastB = std::conditional_t, A, B>; return static_cast(static_cast(a)) + static_cast(static_cast(b)); } else return static_cast(a) + b; } /// Apply operation and check overflow. It's used for Deciamal operations. @returns true if overflowed, false otherwise. template static inline bool apply(A a, B b, Result & c) { return common::addOverflow(static_cast(a), b, c); } #if USE_EMBEDDED_COMPILER static constexpr bool compilable = true; static inline llvm::Value * compile(llvm::IRBuilder<> & b, llvm::Value * left, llvm::Value * right, bool) { return left->getType()->isIntegerTy() ? b.CreateAdd(left, right) : b.CreateFAdd(left, right); } #endif }; struct NamePlus { static constexpr auto name = "plus"; }; using FunctionPlus = BinaryArithmeticOverloadResolver; void registerFunctionPlus(FunctionFactory & factory) { factory.registerFunction(); } }