diff --git a/src/Core/DecimalFunctions.h b/src/Core/DecimalFunctions.h index b82cfd88e98..a0a51651353 100644 --- a/src/Core/DecimalFunctions.h +++ b/src/Core/DecimalFunctions.h @@ -6,6 +6,7 @@ #include #include +#include namespace DB @@ -205,10 +206,13 @@ inline typename DecimalType::NativeType getFractionalPart(const DecimalType & de return getFractionalPartWithScaleMultiplier(decimal, scaleMultiplier(scale)); } -/// Decimal to integer/float conversion +/// Decimal to integer/float conversion with the ability to convert into itself (returns the original value); template To convertTo(const DecimalType & decimal, size_t scale) { + if constexpr (std::is_same_v) + return decimal; + using NativeT = typename DecimalType::NativeType; if constexpr (std::is_floating_point_v) diff --git a/src/Functions/FunctionBinaryArithmetic.h b/src/Functions/FunctionBinaryArithmetic.h index 0f6fbad3065..c871cfd914d 100644 --- a/src/Functions/FunctionBinaryArithmetic.h +++ b/src/Functions/FunctionBinaryArithmetic.h @@ -22,6 +22,7 @@ #include #include #include +#include "Core/DecimalFunctions.h" #include "IFunctionImpl.h" #include "FunctionHelpers.h" #include "IsOperation.h" @@ -209,7 +210,9 @@ struct DecimalBinaryOperation DivideIntegralImpl, /// substitute divide by intDiv (throw on division by zero) Operation>; - using ArrayC = typename ColumnDecimal::Container; + using ArrayC = typename std::conditional_t, + ColumnDecimal, + ColumnVector>::Container; template static void NO_INLINE vectorVector(const ArrayA & a, const ArrayB & b, ArrayC & c, @@ -1015,8 +1018,8 @@ public: /// non-vector result if (col_left_const && col_right_const) { - const NativeResultType const_a = col_left_const->template getValue(); - const NativeResultType const_b = col_right_const->template getValue(); + NativeResultType const_a = col_left_const->template getValue(); + NativeResultType const_b = col_right_const->template getValue(); auto res = check_decimal_overflow ? OpImplCheck::template constantConstant(const_a, const_b, scale_a, scale_b) :