Skip to content

Commit b1690cd

Browse files
committed
Revert "[fix](round) fix round decimal128 overflow (apache#37733)"
This reverts commit 1d3a21f.
1 parent 30da34a commit b1690cd

File tree

4 files changed

+8
-48
lines changed

4 files changed

+8
-48
lines changed

be/src/vec/exec/format/format_common.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ struct DecimalScaleParams {
3333
int64_t scale_factor = 1;
3434

3535
template <typename DecimalPrimitiveType>
36-
static inline constexpr DecimalPrimitiveType::NativeType get_scale_factor(int32_t n) {
36+
static inline constexpr DecimalPrimitiveType get_scale_factor(int32_t n) {
3737
if constexpr (std::is_same_v<DecimalPrimitiveType, Decimal32>) {
3838
return common::exp10_i32(n);
3939
} else if constexpr (std::is_same_v<DecimalPrimitiveType, Decimal64>) {
@@ -42,8 +42,6 @@ struct DecimalScaleParams {
4242
return common::exp10_i128(n);
4343
} else if constexpr (std::is_same_v<DecimalPrimitiveType, Decimal128V3>) {
4444
return common::exp10_i128(n);
45-
} else if constexpr (std::is_same_v<DecimalPrimitiveType, Decimal256>) {
46-
return common::exp10_i256(n);
4745
} else {
4846
static_assert(!sizeof(DecimalPrimitiveType),
4947
"All types must be matched with if constexpr.");

be/src/vec/functions/round.h

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
#include "vec/core/types.h"
3333
#include "vec/data_types/data_type.h"
3434
#include "vec/data_types/data_type_nullable.h"
35-
#include "vec/exec/format/format_common.h"
3635
#include "vec/functions/function.h"
3736
#if defined(__SSE4_1__) || defined(__aarch64__)
3837
#include "util/sse_util.hpp"
@@ -127,7 +126,7 @@ struct IntegerRoundingComputation {
127126
__builtin_unreachable();
128127
}
129128

130-
static ALWAYS_INLINE T compute(T x, T scale, T target_scale) {
129+
static ALWAYS_INLINE T compute(T x, T scale, size_t target_scale) {
131130
switch (scale_mode) {
132131
case ScaleMode::Zero:
133132
case ScaleMode::Positive:
@@ -164,22 +163,21 @@ class DecimalRoundingImpl {
164163
Int16 out_scale) {
165164
Int16 scale_arg = in_scale - out_scale;
166165
if (scale_arg > 0) {
167-
auto scale = DecimalScaleParams::get_scale_factor<T>(scale_arg);
166+
size_t scale = int_exp10(scale_arg);
168167

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

173172
if (out_scale < 0) {
174-
auto negative_scale = DecimalScaleParams::get_scale_factor<T>(-out_scale);
175173
while (p_in < end_in) {
176-
*p_out = Op::compute(*p_in, scale, negative_scale);
174+
Op::compute(p_in, scale, p_out, int_exp10(-out_scale));
177175
++p_in;
178176
++p_out;
179177
}
180178
} else {
181179
while (p_in < end_in) {
182-
*p_out = Op::compute(*p_in, scale, 1);
180+
Op::compute(p_in, scale, p_out, 1);
183181
++p_in;
184182
++p_out;
185183
}
@@ -193,12 +191,11 @@ class DecimalRoundingImpl {
193191
Int16 out_scale) {
194192
Int16 scale_arg = in_scale - out_scale;
195193
if (scale_arg > 0) {
196-
auto scale = DecimalScaleParams::get_scale_factor<T>(scale_arg);
194+
size_t scale = int_exp10(scale_arg);
197195
if (out_scale < 0) {
198-
auto negative_scale = DecimalScaleParams::get_scale_factor<T>(-out_scale);
199-
out = Op::compute(in, scale, negative_scale);
196+
Op::compute(&in, scale, &out, int_exp10(-out_scale));
200197
} else {
201-
out = Op::compute(in, scale, 1);
198+
Op::compute(&in, scale, &out, 1);
202199
}
203200
} else {
204201
memcpy(&out, &in, sizeof(NativeType));

regression-test/data/nereids_p0/sql_functions/math_functions/test_round_overflow.out

Lines changed: 0 additions & 10 deletions
This file was deleted.

regression-test/suites/nereids_p0/sql_functions/math_functions/test_round_overflow.groovy

Lines changed: 0 additions & 25 deletions
This file was deleted.

0 commit comments

Comments
 (0)