This is an automated email from the ASF dual-hosted git repository.
yiguolei pushed a commit to branch branch-2.1
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-2.1 by this push:
new dcef9eecb79 [fix](decimal256) fix casting float/double to decimal256
(#54402)
dcef9eecb79 is described below
commit dcef9eecb796e989ea14fc034c3d975b4c73e104
Author: TengJianPing <[email protected]>
AuthorDate: Thu Aug 7 16:05:39 2025 +0800
[fix](decimal256) fix casting float/double to decimal256 (#54402)
### What problem does this PR solve?
Issue Number: close #xxx
Related PR: #xxx
Problem Summary:
### Release note
None
### Check List (For Author)
- Test <!-- At least one of them must be included. -->
- [ ] Regression test
- [ ] Unit Test
- [ ] Manual test (add detailed scripts or steps below)
- [ ] No need to test or manual test. Explain why:
- [ ] This is a refactor/code format and no logic has been changed.
- [ ] Previous test can cover this change.
- [ ] No code files have been changed.
- [ ] Other reason <!-- Add your reason? -->
- Behavior changed:
- [ ] No.
- [ ] Yes. <!-- Explain the behavior change -->
- Does this need documentation?
- [ ] No.
- [ ] Yes. <!-- Add document PR link here. eg:
https://github.com/apache/doris-website/pull/1214 -->
### Check List (For Reviewer who merge this PR)
- [ ] Confirm the release note
- [ ] Confirm test cases
- [ ] Confirm document
- [ ] Add branch pick label <!-- Add branch pick label that this PR
should merge into -->
---
be/src/vec/data_types/data_type_decimal.h | 14 +-
.../datatype_p0/decimalv3/test_decimal256_cast.out | Bin 1433 -> 9361 bytes
regression-test/data/nereids_arith_p0/decimal.out | Bin 459016 -> 459016 bytes
.../decimalv3/test_decimal256_cast.groovy | 334 +++++++++++++++++++++
4 files changed, 344 insertions(+), 4 deletions(-)
diff --git a/be/src/vec/data_types/data_type_decimal.h
b/be/src/vec/data_types/data_type_decimal.h
index 12c7975e057..5c7ad534b07 100644
--- a/be/src/vec/data_types/data_type_decimal.h
+++ b/be/src/vec/data_types/data_type_decimal.h
@@ -685,6 +685,11 @@ void convert_to_decimal(typename ToDataType::FieldType*
dst,
if constexpr (std::is_floating_point_v<FromFieldType>) {
auto multiplier = ToDataType::get_scale_multiplier(to_scale);
+ // For decimal256, we need to use long double to avoid overflow when
+ // static casting the multiplier to floating type, and also to be as
precise as possible;
+ // For other decimal types, we use double to be as precise as possible.
+ using DoubleType = std::conditional_t<IsDecimal256<typename
ToDataType::FieldType>,
+ long double, double>;
if constexpr (narrow_integral) {
for (size_t i = 0; i < size; ++i) {
if (!std::isfinite(src[i])) {
@@ -692,8 +697,8 @@ void convert_to_decimal(typename ToDataType::FieldType* dst,
ErrorCode::ARITHMETIC_OVERFLOW_ERRROR,
"Decimal convert overflow. Cannot convert infinity
or NaN to decimal");
}
- FromFieldType tmp = src[i] * multiplier;
- if (tmp <= FromFieldType(min_result) || tmp >=
FromFieldType(max_result)) {
+ DoubleType tmp = src[i] *
static_cast<DoubleType>(multiplier.value);
+ if (tmp <= DoubleType(min_result.value) || tmp >=
DoubleType(max_result.value)) {
ToDataType to_data_type(to_precision, to_scale);
throw Exception(
ErrorCode::ARITHMETIC_OVERFLOW_ERRROR,
@@ -703,8 +708,9 @@ void convert_to_decimal(typename ToDataType::FieldType* dst,
}
}
for (size_t i = 0; i < size; ++i) {
- dst[i].value = typename ToDataType::FieldType::NativeType(
- FromFieldType(src[i] * multiplier.value + ((src[i] >= 0) ?
0.5 : -0.5)));
+ dst[i].value = static_cast<ToDataType::FieldType::NativeType>(
+ static_cast<double>(src[i] *
static_cast<DoubleType>(multiplier.value) +
+ ((src[i] >= 0) ? 0.5 : -0.5)));
}
} else {
using DecimalFrom =
diff --git
a/regression-test/data/datatype_p0/decimalv3/test_decimal256_cast.out
b/regression-test/data/datatype_p0/decimalv3/test_decimal256_cast.out
index 3ba2863a6fd..e4498b435d8 100644
Binary files
a/regression-test/data/datatype_p0/decimalv3/test_decimal256_cast.out and
b/regression-test/data/datatype_p0/decimalv3/test_decimal256_cast.out differ
diff --git a/regression-test/data/nereids_arith_p0/decimal.out
b/regression-test/data/nereids_arith_p0/decimal.out
index 7b0e2bc82b2..8be58f2ff1b 100644
Binary files a/regression-test/data/nereids_arith_p0/decimal.out and
b/regression-test/data/nereids_arith_p0/decimal.out differ
diff --git
a/regression-test/suites/datatype_p0/decimalv3/test_decimal256_cast.groovy
b/regression-test/suites/datatype_p0/decimalv3/test_decimal256_cast.groovy
index 64c5d87cac0..2b04f2c5eab 100644
--- a/regression-test/suites/datatype_p0/decimalv3/test_decimal256_cast.groovy
+++ b/regression-test/suites/datatype_p0/decimalv3/test_decimal256_cast.groovy
@@ -154,4 +154,338 @@ suite("test_decimal256_cast") {
exception "Arithmetic overflow"
}
+ // cast float to decimal256
+ qt_cast_float_to_decimal256_const_1_1 """select
/*+SET_VAR(debug_skip_fold_constant = true) */cast(cast("219.77718" as float)
as decimalv3(76, 38));"""
+ qt_cast_float_to_decimal256_const_1_2 """select
/*+SET_VAR(debug_skip_fold_constant = false) */cast(cast("219.77718" as float)
as decimalv3(76, 38));"""
+
+ qt_cast_float_to_decimal256_const_2_1 """select
/*+SET_VAR(debug_skip_fold_constant = true) */cast(cast("-219.77718" as float)
as decimalv3(76, 38));"""
+ qt_cast_float_to_decimal256_const_2_2 """select
/*+SET_VAR(debug_skip_fold_constant = false) */cast(cast("-219.77718" as float)
as decimalv3(76, 38));"""
+
+ qt_cast_float_to_decimal256_const_3_1 """select
/*+SET_VAR(debug_skip_fold_constant = true)
*/cast(cast("99999999999999999999999999999999999998.99999999999999999999999999999999999999"
as float) as decimalv3(76, 38));"""
+ qt_cast_float_to_decimal256_const_3_2 """select
/*+SET_VAR(debug_skip_fold_constant = false)
*/cast(cast("99999999999999999999999999999999999998.99999999999999999999999999999999999999"
as float) as decimalv3(76, 38));"""
+
+ qt_cast_float_to_decimal256_const_4_1 """select
/*+SET_VAR(debug_skip_fold_constant = true)
*/cast(cast("-99999999999999999999999999999999999998.99999999999999999999999999999999999999"
as float) as decimalv3(76, 38));"""
+ qt_cast_float_to_decimal256_const_4_2 """select
/*+SET_VAR(debug_skip_fold_constant = false)
*/cast(cast("-99999999999999999999999999999999999998.99999999999999999999999999999999999999"
as float) as decimalv3(76, 38));"""
+
+ qt_cast_float_to_decimal256_const_5_1 """select
/*+SET_VAR(debug_skip_fold_constant = true)
*/cast(cast("9999999999999999999999999999998.999999999999999999999999999999999999999999999"
as float) as decimalv3(76, 45));"""
+ qt_cast_float_to_decimal256_const_5_2 """select
/*+SET_VAR(debug_skip_fold_constant = false)
*/cast(cast("9999999999999999999999999999998.999999999999999999999999999999999999999999999"
as float) as decimalv3(76, 45));"""
+
+ qt_cast_float_to_decimal256_const_6_1 """select
/*+SET_VAR(debug_skip_fold_constant = true)
*/cast(cast("-9999999999999999999999999999998.999999999999999999999999999999999999999999999"
as float) as decimalv3(76, 45));"""
+ qt_cast_float_to_decimal256_const_6_2 """select
/*+SET_VAR(debug_skip_fold_constant = false)
*/cast(cast("-9999999999999999999999999999998.999999999999999999999999999999999999999999999"
as float) as decimalv3(76, 45));"""
+
+ qt_cast_float_to_decimal256_const_7_1 """select
/*+SET_VAR(debug_skip_fold_constant = true)
*/cast(cast("0.8999999999999999999999999999999999999999999999999999999999999999999999999999"
as float) as decimalv3(76, 76));"""
+ qt_cast_float_to_decimal256_const_7_2 """select
/*+SET_VAR(debug_skip_fold_constant = false)
*/cast(cast("0.8999999999999999999999999999999999999999999999999999999999999999999999999999"
as float) as decimalv3(76, 76));"""
+
+ qt_cast_float_to_decimal256_const_8_1 """select
/*+SET_VAR(debug_skip_fold_constant = true)
*/cast(cast("-0.8999999999999999999999999999999999999999999999999999999999999999999999999999"
as float) as decimalv3(76, 76));"""
+ qt_cast_float_to_decimal256_const_8_2 """select
/*+SET_VAR(debug_skip_fold_constant = false)
*/cast(cast("-0.8999999999999999999999999999999999999999999999999999999999999999999999999999"
as float) as decimalv3(76, 76));"""
+
+ qt_cast_float_to_decimal256_const_9_1 """select
/*+SET_VAR(debug_skip_fold_constant = true) */cast(cast("3.402e38" as float) as
decimalv3(76, 37));"""
+ qt_cast_float_to_decimal256_const_9_2 """select
/*+SET_VAR(debug_skip_fold_constant = false) */cast(cast("3.402e38" as float)
as decimalv3(76, 37));"""
+ qt_cast_float_to_decimal256_const_10_1 """select
/*+SET_VAR(debug_skip_fold_constant = true) */cast(cast("-3.402e38" as float)
as decimalv3(76, 37));"""
+ qt_cast_float_to_decimal256_const_10_2 """select
/*+SET_VAR(debug_skip_fold_constant = false) */cast(cast("-3.402e38" as float)
as decimalv3(76, 37));"""
+
+ sql """
+ drop table if exists cast_to_float_to_decimal256;
+ """
+ sql """
+ create table cast_to_float_to_decimal256 (
+ k1 int,
+ v1 float
+ ) properties ('replication_num' = '1');
+ """
+ sql """
+ insert into cast_to_float_to_decimal256 values
+ (0, "219.77718"), (1, "-219.77718"),
+ (2,
"99999999999999999999999999999999999998.99999999999999999999999999999999999999"),
+ (3,
"-99999999999999999999999999999999999998.99999999999999999999999999999999999999"),
+ (4,
"9999999999999999999999999999998.999999999999999999999999999999999999999999999"),
+ (5,
"-9999999999999999999999999999998.999999999999999999999999999999999999999999999"),
+ (6,
"0.9999999999999999999999999999999999999999999999999999999999999999999999999999"),
+ (7,
"-0.9999999999999999999999999999999999999999999999999999999999999999999999999999"),
+ (8, "0.97718"),
+ (9, "-0.97718"),
+ (10, "3.402e38"),
+ (11, "-3.402e38");
+ """
+ qt_cast_float_to_decimal256_1 """
+ select k1, cast(v1 as decimalv3(76, 0)) from
cast_to_float_to_decimal256 order by k1;
+ """
+
+ sql """
+ drop table if exists cast_to_float_to_decimal256;
+ """
+ sql """
+ create table cast_to_float_to_decimal256 (
+ k1 int,
+ v1 float
+ ) properties ('replication_num' = '1');
+ """
+ sql """
+ insert into cast_to_float_to_decimal256 values
+ (0, "219.77718"), (1, "-219.77718"),
+ (2,
"99999999999999999999999999999999999998.99999999999999999999999999999999999999"),
+ (3,
"-99999999999999999999999999999999999998.99999999999999999999999999999999999999"),
+ (4,
"9999999999999999999999999999998.999999999999999999999999999999999999999999999"),
+ (5,
"-9999999999999999999999999999998.999999999999999999999999999999999999999999999"),
+ (6,
"0.9999999999999999999999999999999999999999999999999999999999999999999999999999"),
+ (7,
"-0.9999999999999999999999999999999999999999999999999999999999999999999999999999"),
+ (8, "0.97718"),
+ (9, "-0.97718");
+ """
+ qt_cast_float_to_decimal256_2 """
+ select k1, cast(v1 as decimalv3(76, 38)) from
cast_to_float_to_decimal256 order by k1;
+ """
+
+ sql """
+ drop table if exists cast_to_float_to_decimal256;
+ """
+ sql """
+ create table cast_to_float_to_decimal256 (
+ k1 int,
+ v1 float
+ ) properties ('replication_num' = '1');
+ """
+ sql """
+ insert into cast_to_float_to_decimal256 values
+ (0, "219.77718"), (1, "-219.77718"),
+ (4,
"9999999999999999999999999999998.999999999999999999999999999999999999999999999"),
+ (5,
"-9999999999999999999999999999998.999999999999999999999999999999999999999999999"),
+ (6,
"0.9999999999999999999999999999999999999999999999999999999999999999999999999999"),
+ (7,
"-0.9999999999999999999999999999999999999999999999999999999999999999999999999999"),
+ (8, "0.97718"),
+ (9, "0.97718");
+ """
+ qt_cast_float_to_decimal256_3 """
+ select k1, cast(v1 as decimalv3(76, 45)) from
cast_to_float_to_decimal256 order by k1;
+ """
+
+ sql """
+ drop table if exists cast_to_float_to_decimal256;
+ """
+ sql """
+ create table cast_to_float_to_decimal256 (
+ k1 int,
+ v1 float
+ ) properties ('replication_num' = '1');
+ """
+ sql """
+ insert into cast_to_float_to_decimal256 values
+ (6,
"0.8999999999999999999999999999999999999999999999999999999999999999999999999999"),
+ (7,
"-0.8999999999999999999999999999999999999999999999999999999999999999999999999999");
+ """
+ qt_cast_float_to_decimal256_4 """
+ select k1, cast(v1 as decimalv3(76, 76)) from
cast_to_float_to_decimal256 order by k1;
+ """
+
+ // cast double to decimal256
+ qt_cast_double_to_decimal256_const_1_1 """select
/*+SET_VAR(debug_skip_fold_constant = true) */cast(cast("219.77718" as double)
as decimalv3(76, 38));"""
+ qt_cast_double_to_decimal256_const_1_2 """select
/*+SET_VAR(debug_skip_fold_constant = false) */cast(cast("219.77718" as double)
as decimalv3(76, 38));"""
+
+ qt_cast_double_to_decimal256_const_2_1 """select
/*+SET_VAR(debug_skip_fold_constant = true) */cast(cast("-219.77718" as double)
as decimalv3(76, 38));"""
+ qt_cast_double_to_decimal256_const_2_2 """select
/*+SET_VAR(debug_skip_fold_constant = false) */cast(cast("-219.77718" as
double) as decimalv3(76, 38));"""
+
+ qt_cast_double_to_decimal256_const_3_1 """select
/*+SET_VAR(debug_skip_fold_constant = true)
*/cast(cast("99999999999999999999999999999999999998.99999999999999999999999999999999999999"
as double) as decimalv3(76, 38));"""
+ qt_cast_double_to_decimal256_const_3_2 """select
/*+SET_VAR(debug_skip_fold_constant = false)
*/cast(cast("99999999999999999999999999999999999998.99999999999999999999999999999999999999"
as double) as decimalv3(76, 38));"""
+
+ qt_cast_double_to_decimal256_const_4_1 """select
/*+SET_VAR(debug_skip_fold_constant = true)
*/cast(cast("-99999999999999999999999999999999999998.99999999999999999999999999999999999999"
as double) as decimalv3(76, 38));"""
+ qt_cast_double_to_decimal256_const_4_2 """select
/*+SET_VAR(debug_skip_fold_constant = false)
*/cast(cast("-99999999999999999999999999999999999998.99999999999999999999999999999999999999"
as double) as decimalv3(76, 38));"""
+
+ qt_cast_double_to_decimal256_const_5_1 """select
/*+SET_VAR(debug_skip_fold_constant = true)
*/cast(cast("9999999999999999999999999999998.999999999999999999999999999999999999999999999"
as double) as decimalv3(76, 45));"""
+ qt_cast_double_to_decimal256_const_5_2 """select
/*+SET_VAR(debug_skip_fold_constant = false)
*/cast(cast("9999999999999999999999999999998.999999999999999999999999999999999999999999999"
as double) as decimalv3(76, 45));"""
+
+ qt_cast_double_to_decimal256_const_6_1 """select
/*+SET_VAR(debug_skip_fold_constant = true)
*/cast(cast("-9999999999999999999999999999998.999999999999999999999999999999999999999999999"
as double) as decimalv3(76, 45));"""
+ qt_cast_double_to_decimal256_const_6_2 """select
/*+SET_VAR(debug_skip_fold_constant = false)
*/cast(cast("-9999999999999999999999999999998.999999999999999999999999999999999999999999999"
as double) as decimalv3(76, 45));"""
+
+ qt_cast_double_to_decimal256_const_7_1 """select
/*+SET_VAR(debug_skip_fold_constant = true)
*/cast(cast("0.9899999999999999999999999999999999999999999999999999999999999999999999999999"
as double) as decimalv3(76, 76));"""
+ qt_cast_double_to_decimal256_const_7_2 """select
/*+SET_VAR(debug_skip_fold_constant = false)
*/cast(cast("0.9899999999999999999999999999999999999999999999999999999999999999999999999999"
as double) as decimalv3(76, 76));"""
+
+ qt_cast_double_to_decimal256_const_8_1 """select
/*+SET_VAR(debug_skip_fold_constant = true)
*/cast(cast("-0.9899999999999999999999999999999999999999999999999999999999999999999999999999"
as double) as decimalv3(76, 76));"""
+ qt_cast_double_to_decimal256_const_8_2 """select
/*+SET_VAR(debug_skip_fold_constant = false)
*/cast(cast("-0.9899999999999999999999999999999999999999999999999999999999999999999999999999"
as double) as decimalv3(76, 76));"""
+
+ qt_cast_double_to_decimal256_const_9_1 """select
/*+SET_VAR(debug_skip_fold_constant = true) */cast(cast("9.899e75" as double)
as decimalv3(76, 0));"""
+ qt_cast_double_to_decimal256_const_9_2 """select
/*+SET_VAR(debug_skip_fold_constant = false) */cast(cast("9.899e75" as double)
as decimalv3(76, 0));"""
+ qt_cast_double_to_decimal256_const_10_1 """select
/*+SET_VAR(debug_skip_fold_constant = true) */cast(cast("-9.899e75" as double)
as decimalv3(76, 0));"""
+ qt_cast_double_to_decimal256_const_10_2 """select
/*+SET_VAR(debug_skip_fold_constant = false) */cast(cast("-9.899e75" as double)
as decimalv3(76, 0));"""
+
+ sql """
+ drop table if exists cast_to_double_to_decimal256;
+ """
+ sql """
+ create table cast_to_double_to_decimal256 (
+ k1 int,
+ v1 double
+ ) properties ('replication_num' = '1');
+ """
+ sql """
+ insert into cast_to_double_to_decimal256 values
+ (0, "219.77718"), (1, "-219.77718"),
+ (2,
"99999999999999999999999999999999999998.99999999999999999999999999999999999999"),
+ (3,
"-99999999999999999999999999999999999998.99999999999999999999999999999999999999"),
+ (4,
"9999999999999999999999999999998.999999999999999999999999999999999999999999999"),
+ (5,
"-9999999999999999999999999999998.999999999999999999999999999999999999999999999"),
+ (6,
"0.9999999999999999999999999999999999999999999999999999999999999999999999999999"),
+ (7,
"-0.9999999999999999999999999999999999999999999999999999999999999999999999999999"),
+ (8, "0.97718"),
+ (9, "-0.97718"),
+ (10, "3.402e38"),
+ (11, "-3.402e38"),
+ (12, "9.899e75"),
+ (13, "9.899e75");
+ """
+ qt_cast_double_to_decimal256_1 """
+ select k1, cast(v1 as decimalv3(76, 0)) from
cast_to_double_to_decimal256 order by k1;
+ """
+
+ sql """
+ drop table if exists cast_to_double_to_decimal256;
+ """
+ sql """
+ create table cast_to_double_to_decimal256 (
+ k1 int,
+ v1 double
+ ) properties ('replication_num' = '1');
+ """
+ sql """
+ insert into cast_to_double_to_decimal256 values
+ (0, "219.77718"), (1, "-219.77718"),
+ (2,
"99999999999999999999999999999999999998.99999999999999999999999999999999999999"),
+ (3,
"-99999999999999999999999999999999999998.99999999999999999999999999999999999999"),
+ (4,
"9999999999999999999999999999998.999999999999999999999999999999999999999999999"),
+ (5,
"-9999999999999999999999999999998.999999999999999999999999999999999999999999999"),
+ (6,
"0.9999999999999999999999999999999999999999999999999999999999999999999999999999"),
+ (7,
"-0.9999999999999999999999999999999999999999999999999999999999999999999999999999"),
+ (8, "0.97718"),
+ (9, "-0.97718");
+ """
+ qt_cast_double_to_decimal256_2 """
+ select k1, cast(v1 as decimalv3(76, 38)) from
cast_to_double_to_decimal256 order by k1;
+ """
+
+ sql """
+ drop table if exists cast_to_double_to_decimal256;
+ """
+ sql """
+ create table cast_to_double_to_decimal256 (
+ k1 int,
+ v1 double
+ ) properties ('replication_num' = '1');
+ """
+ sql """
+ insert into cast_to_double_to_decimal256 values
+ (0, "219.77718"), (1, "-219.77718"),
+ (4,
"9999999999999999999999999999998.999999999999999999999999999999999999999999999"),
+ (5,
"-9999999999999999999999999999998.999999999999999999999999999999999999999999999"),
+ (6,
"0.9999999999999999999999999999999999999999999999999999999999999999999999999999"),
+ (7,
"-0.9999999999999999999999999999999999999999999999999999999999999999999999999999"),
+ (8, "0.97718"),
+ (9, "0.97718");
+ """
+ qt_cast_double_to_decimal256_3 """
+ select k1, cast(v1 as decimalv3(76, 45)) from
cast_to_double_to_decimal256 order by k1;
+ """
+
+ sql """
+ drop table if exists cast_to_double_to_decimal256;
+ """
+ sql """
+ create table cast_to_double_to_decimal256 (
+ k1 int,
+ v1 double
+ ) properties ('replication_num' = '1');
+ """
+ sql """
+ insert into cast_to_double_to_decimal256 values
+ (6,
"0.8999999999999999999999999999999999999999999999999999999999999999999999999999"),
+ (7,
"-0.8999999999999999999999999999999999999999999999999999999999999999999999999999");
+ """
+ qt_cast_double_to_decimal256_4 """
+ select k1, cast(v1 as decimalv3(76, 76)) from
cast_to_double_to_decimal256 order by k1;
+ """
+
+ // test cast float to decimal256 overflow
+ test {
+ sql """select /*+SET_VAR(debug_skip_fold_constant = true)
*/cast(cast("219.77718" as float) as decimalv3(76, 74));"""
+ exception "Arithmetic overflow"
+ }
+ test {
+ sql """select /*+SET_VAR(debug_skip_fold_constant = false)
*/cast(cast("219.77718" as float) as decimalv3(76, 74));"""
+ exception "Arithmetic overflow"
+ }
+ test {
+ sql """select /*+SET_VAR(debug_skip_fold_constant = true)
*/cast(cast("-219.77718" as float) as decimalv3(76, 74));"""
+ exception "Arithmetic overflow"
+ }
+ test {
+ sql """select /*+SET_VAR(debug_skip_fold_constant = false)
*/cast(cast("-219.77718" as float) as decimalv3(76, 74));"""
+ exception "Arithmetic overflow"
+ }
+
+ test {
+ sql """select /*+SET_VAR(debug_skip_fold_constant = true)
*/cast(cast("3.402e38" as float) as decimalv3(76, 38));"""
+ exception "Arithmetic overflow"
+ }
+ test {
+ sql """select /*+SET_VAR(debug_skip_fold_constant = false)
*/cast(cast("3.402e38" as float) as decimalv3(76, 38));"""
+ exception "Arithmetic overflow"
+ }
+ test {
+ sql """select /*+SET_VAR(debug_skip_fold_constant = true)
*/cast(cast("-3.402e38" as float) as decimalv3(76, 38));"""
+ exception "Arithmetic overflow"
+ }
+ test {
+ sql """select /*+SET_VAR(debug_skip_fold_constant = false)
*/cast(cast("-3.402e38" as float) as decimalv3(76, 38));"""
+ exception "Arithmetic overflow"
+ }
+
+ // test cast double to decimal256 overflow
+ test {
+ sql """select /*+SET_VAR(debug_skip_fold_constant = true)
*/cast(cast("219.77718" as double) as decimalv3(76, 74));"""
+ exception "Arithmetic overflow"
+ }
+ test {
+ sql """select /*+SET_VAR(debug_skip_fold_constant = false)
*/cast(cast("219.77718" as double) as decimalv3(76, 74));"""
+ exception "Arithmetic overflow"
+ }
+ test {
+ sql """select /*+SET_VAR(debug_skip_fold_constant = true)
*/cast(cast("-219.77718" as double) as decimalv3(76, 74));"""
+ exception "Arithmetic overflow"
+ }
+ test {
+ sql """select /*+SET_VAR(debug_skip_fold_constant = false)
*/cast(cast("-219.77718" as double) as decimalv3(76, 74));"""
+ exception "Arithmetic overflow"
+ }
+
+ test {
+ sql """select /*+SET_VAR(debug_skip_fold_constant = true)
*/cast(cast("3.402e38" as double) as decimalv3(76, 38));"""
+ exception "Arithmetic overflow"
+ }
+ test {
+ sql """select /*+SET_VAR(debug_skip_fold_constant = false)
*/cast(cast("3.402e38" as double) as decimalv3(76, 38));"""
+ exception "Arithmetic overflow"
+ }
+ test {
+ sql """select /*+SET_VAR(debug_skip_fold_constant = true)
*/cast(cast("-3.402e38" as double) as decimalv3(76, 38));"""
+ exception "Arithmetic overflow"
+ }
+ test {
+ sql """select /*+SET_VAR(debug_skip_fold_constant = false)
*/cast(cast("-3.402e38" as double) as decimalv3(76, 38));"""
+ exception "Arithmetic overflow"
+ }
+
+ test {
+ sql """select /*+SET_VAR(debug_skip_fold_constant = true)
*/cast(cast("9.899e76" as double) as decimalv3(76, 0));"""
+ exception "Arithmetic overflow"
+ }
+ test {
+ sql """select /*+SET_VAR(debug_skip_fold_constant = false)
*/cast(cast("9.899e76" as double) as decimalv3(76, 0));"""
+ exception "Arithmetic overflow"
+ }
+ test {
+ sql """select /*+SET_VAR(debug_skip_fold_constant = true)
*/cast(cast("-9.899e76" as double) as decimalv3(76, 0));"""
+ exception "Arithmetic overflow"
+ }
+ test {
+ sql """select /*+SET_VAR(debug_skip_fold_constant = false)
*/cast(cast("-9.899e76" as double) as decimalv3(76, 0));"""
+ exception "Arithmetic overflow"
+ }
}
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]