Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion be/src/vec/data_types/data_type_decimal.h
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,13 @@ void convert_from_decimal(typename ToDataType::FieldType* dst,
} else {
auto multiplier = FromDataType::get_scale_multiplier(scale);
for (size_t i = 0; i < size; ++i) {
dst[i] = static_cast<ToFieldType>(src[i].value) / multiplier.value;
if constexpr (IsDecimal256<FromFieldType>) {
dst[i] = static_cast<ToFieldType>(static_cast<long double>(src[i].value) /
static_cast<long double>(multiplier.value));
} else {
dst[i] = static_cast<ToFieldType>(static_cast<double>(src[i].value) /
static_cast<double>(multiplier.value));
}
}
}
if constexpr (narrow_integral) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,21 @@
-- !decimal256_cast10 --
10 0

-- !decimal256_cast_to_double_1 --
-- !decimal256_cast_to_float1 --
1.2345678E7

-- !decimal256_cast_to_float2 --
1.2345678E7

-- !decimal256_cast_to_float3 --
1 1.2345678E7
2 1.00000003E16
3 2.5079478E-7
4 1.0

-- !decimal256_cast_to_double_1 --
1 1.2345678E7
2 1.0E16
3 2.507947739348449E-7
4 1.0

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-- This file is automatically generated. You should know what you did if you want to edit this
-- !decimal128_to_float_1 --
-9.999999E34
-1.0E35
-32769.79
-32768.79
-9999.999
Expand All @@ -9,9 +9,9 @@
99.999
127.789
9999.999
32767.787
32768.125
9.999999E34
32767.79
32768.12
1.0E35

-- !decimal128_to_double_1 --
-1.0E35
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
suite("test_decimal256_cast") {
sql "set enable_nereids_planner = true;"
sql "set enable_decimal256 = true;"
// sql """
// set debug_skip_fold_constant=true;
// """
sql """
set debug_skip_fold_constant=true;
"""

qt_decimal256_cast0 """SELECT /*+ SET_VAR(enable_fold_constant_by_be = false) */
cast(999999999999999999999999999999999999999999999999999999999999999999.9999999999 as decimalv3(76,10));"""
Expand Down Expand Up @@ -74,18 +74,12 @@ suite("test_decimal256_cast") {
select k1, cast(v1 as decimalv3(76, 0)) from cast_to_dec256 order by k1, v1;
"""

// test {
// sql """
// select /*+SET_VAR(enable_fold_constant_by_be = true) */cast(cast("12345678.000000000000000000000000000000001" as decimalv3(76, 60)) as float);
// """
// exception "Arithmetic overflow"
// }
// test {
// sql """
// select /*+SET_VAR(enable_fold_constant_by_be = false) */cast(cast("12345678.000000000000000000000000000000001" as decimalv3(76, 60)) as float);
// """
// exception "Arithmetic overflow"
// }
qt_decimal256_cast_to_float1 """
select /*+SET_VAR(enable_fold_constant_by_be = true) */cast(cast("12345678.000000000000000000000000000000001" as decimalv3(76, 60)) as float);
"""
qt_decimal256_cast_to_float2 """
select /*+SET_VAR(enable_fold_constant_by_be = false) */cast(cast("12345678.000000000000000000000000000000001" as decimalv3(76, 60)) as float);
"""

sql """
drop table if exists dec256cast_to_float;
Expand All @@ -100,16 +94,64 @@ suite("test_decimal256_cast") {
);
"""
sql """
insert into dec256cast_to_float values (1, "12345678.000000000000000000000000000000001");
insert into dec256cast_to_float values
(1, "12345678.000000000000000000000000000000001"),
(2, "9999999999999999.999999999999999999999999999999999999999999999999999999999999"),
(3, "0.000000250794773934844880991039000000000000000000000000000000"),
(4, "0.999999999999999999999999999999999999999999999999999999999999");
"""

qt_decimal256_cast_to_float3 """
select k1, cast(v1 as float) from dec256cast_to_float order by 1;
"""
qt_decimal256_cast_to_double_1 """
select k1, cast(v1 as double) from dec256cast_to_float order by 1;
"""

test {
sql """
select cast(v1 as float) from dec256cast_to_float;
"""
sql """select /*+SET_VAR(debug_skip_fold_constant = false) */cast(cast("1000000000000000000000000000000000000000000000000000000000000000000000.111111" as decimalv3(76, 6)) as float);"""
exception "Arithmetic overflow"
}
qt_decimal256_cast_to_double_1 """
select cast(v1 as double) from dec256cast_to_float;
test {
sql """select /*+SET_VAR(debug_skip_fold_constant = true) */cast(cast("1000000000000000000000000000000000000000000000000000000000000000000000.111111" as decimalv3(76, 6)) as float);"""
exception "Arithmetic overflow"
}

test {
sql """select /*+SET_VAR(debug_skip_fold_constant = false) */cast(cast("9999999999999999999999999999999999999999999999999999999999999999999999.999999" as decimalv3(76, 6)) as float);"""
exception "Arithmetic overflow"
}
test {
sql """select /*+SET_VAR(debug_skip_fold_constant = true) */cast(cast("9999999999999999999999999999999999999999999999999999999999999999999999.999999" as decimalv3(76, 6)) as float);"""
exception "Arithmetic overflow"
}

sql "drop table if exists dec256cast_to_float_overflow"
sql """
create table dec256cast_to_float_overflow (
k1 int,
v1 decimalv3(76, 6)
) distributed by hash(k1)
properties (
'replication_num' = '1'
);
"""
sql """
insert into dec256cast_to_float_overflow values (1, "1000000000000000000000000000000000000000000000000000000000000000000000.111111");
"""
test {
sql "select cast(v1 as float) from dec256cast_to_float_overflow;"
exception "Arithmetic overflow"
}
sql """
truncate table dec256cast_to_float_overflow;
"""
sql """
insert into dec256cast_to_float_overflow values (1, "9999999999999999999999999999999999999999999999999999999999999999999999.999999");
"""
test {
sql "select cast(v1 as float) from dec256cast_to_float_overflow;"
exception "Arithmetic overflow"
}

}
Loading