Skip to content

Commit

Permalink
Revert "[fix](round) fix round decimal128 overflow (apache#37733)"
Browse files Browse the repository at this point in the history
This reverts commit 1d3a21f.
  • Loading branch information
cambyzju committed Jul 19, 2024
1 parent 30da34a commit b1690cd
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 48 deletions.
4 changes: 1 addition & 3 deletions be/src/vec/exec/format/format_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ struct DecimalScaleParams {
int64_t scale_factor = 1;

template <typename DecimalPrimitiveType>
static inline constexpr DecimalPrimitiveType::NativeType get_scale_factor(int32_t n) {
static inline constexpr DecimalPrimitiveType get_scale_factor(int32_t n) {
if constexpr (std::is_same_v<DecimalPrimitiveType, Decimal32>) {
return common::exp10_i32(n);
} else if constexpr (std::is_same_v<DecimalPrimitiveType, Decimal64>) {
Expand All @@ -42,8 +42,6 @@ struct DecimalScaleParams {
return common::exp10_i128(n);
} else if constexpr (std::is_same_v<DecimalPrimitiveType, Decimal128V3>) {
return common::exp10_i128(n);
} else if constexpr (std::is_same_v<DecimalPrimitiveType, Decimal256>) {
return common::exp10_i256(n);
} else {
static_assert(!sizeof(DecimalPrimitiveType),
"All types must be matched with if constexpr.");
Expand Down
17 changes: 7 additions & 10 deletions be/src/vec/functions/round.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
#include "vec/core/types.h"
#include "vec/data_types/data_type.h"
#include "vec/data_types/data_type_nullable.h"
#include "vec/exec/format/format_common.h"
#include "vec/functions/function.h"
#if defined(__SSE4_1__) || defined(__aarch64__)
#include "util/sse_util.hpp"
Expand Down Expand Up @@ -127,7 +126,7 @@ struct IntegerRoundingComputation {
__builtin_unreachable();
}

static ALWAYS_INLINE T compute(T x, T scale, T target_scale) {
static ALWAYS_INLINE T compute(T x, T scale, size_t target_scale) {
switch (scale_mode) {
case ScaleMode::Zero:
case ScaleMode::Positive:
Expand Down Expand Up @@ -164,22 +163,21 @@ class DecimalRoundingImpl {
Int16 out_scale) {
Int16 scale_arg = in_scale - out_scale;
if (scale_arg > 0) {
auto scale = DecimalScaleParams::get_scale_factor<T>(scale_arg);
size_t scale = int_exp10(scale_arg);

const NativeType* __restrict p_in = reinterpret_cast<const NativeType*>(in.data());
const NativeType* end_in = reinterpret_cast<const NativeType*>(in.data()) + in.size();
NativeType* __restrict p_out = reinterpret_cast<NativeType*>(out.data());

if (out_scale < 0) {
auto negative_scale = DecimalScaleParams::get_scale_factor<T>(-out_scale);
while (p_in < end_in) {
*p_out = Op::compute(*p_in, scale, negative_scale);
Op::compute(p_in, scale, p_out, int_exp10(-out_scale));
++p_in;
++p_out;
}
} else {
while (p_in < end_in) {
*p_out = Op::compute(*p_in, scale, 1);
Op::compute(p_in, scale, p_out, 1);
++p_in;
++p_out;
}
Expand All @@ -193,12 +191,11 @@ class DecimalRoundingImpl {
Int16 out_scale) {
Int16 scale_arg = in_scale - out_scale;
if (scale_arg > 0) {
auto scale = DecimalScaleParams::get_scale_factor<T>(scale_arg);
size_t scale = int_exp10(scale_arg);
if (out_scale < 0) {
auto negative_scale = DecimalScaleParams::get_scale_factor<T>(-out_scale);
out = Op::compute(in, scale, negative_scale);
Op::compute(&in, scale, &out, int_exp10(-out_scale));
} else {
out = Op::compute(in, scale, 1);
Op::compute(&in, scale, &out, 1);
}
} else {
memcpy(&out, &in, sizeof(NativeType));
Expand Down

This file was deleted.

This file was deleted.

0 comments on commit b1690cd

Please sign in to comment.