diff --git a/be/src/vec/functions/function_binary_arithmetic.h b/be/src/vec/functions/function_binary_arithmetic.h index e9f088369c..5c98e72486 100644 --- a/be/src/vec/functions/function_binary_arithmetic.h +++ b/be/src/vec/functions/function_binary_arithmetic.h @@ -295,12 +295,15 @@ struct DecimalBinaryOperation { for (size_t i = 0; i < size; ++i) { c[i] = apply_scaled_div(a, b[i]); } - return; - } - - /// default: use it if no return before - for (size_t i = 0; i < size; ++i) { - c[i] = apply(a, b[i]); + } else if constexpr (IsDecimalV2 || IsDecimalV2) { + DecimalV2Value da(a); + for (size_t i = 0; i < size; ++i) { + c[i] = Op::template apply(da, DecimalV2Value(b[i])).value(); + } + } else { + for (size_t i = 0; i < size; ++i) { + c[i] = apply(a, b[i]); + } } } @@ -413,12 +416,7 @@ private: if constexpr (IsDecimalV2 || IsDecimalV2) { // Now, Doris only support decimal +-*/ decimal. // overflow in consider in operator - DecimalV2Value l(a); - DecimalV2Value r(b); - auto ans = Op::template apply(l, r); - NativeResultType result; - memcpy(&result, &ans, sizeof(NativeResultType)); - return result; + return Op::template apply(DecimalV2Value(a), DecimalV2Value(b)).value(); } else { if constexpr (OpTraits::can_overflow && check_overflow) { NativeResultType res; diff --git a/be/src/vec/functions/minus.cpp b/be/src/vec/functions/minus.cpp index 0568fe80bc..7c72d0145c 100644 --- a/be/src/vec/functions/minus.cpp +++ b/be/src/vec/functions/minus.cpp @@ -35,7 +35,7 @@ struct MinusImpl { } template - static inline DecimalV2Value apply(DecimalV2Value a, DecimalV2Value b) { + static inline DecimalV2Value apply(const DecimalV2Value& a, const DecimalV2Value& b) { return DecimalV2Value(a.value() - b.value()); }