This is an automated email from the ASF dual-hosted git repository.

zclll pushed a commit to branch branch-3.1
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/branch-3.1 by this push:
     new e44689f617e [fix](decimal256) fix casting float/double to decimal256 
(#54401)
e44689f617e is described below

commit e44689f617e93d5ccfd1ada0f37fc7f02f5ea643
Author: TengJianPing <[email protected]>
AuthorDate: Thu Aug 7 11:50:48 2025 +0800

    [fix](decimal256) fix casting float/double to decimal256 (#54401)
    
    ### What problem does this PR solve?
    
    This problem is already fixed on master by the refactoring PR #50940
    
    Related PR:
    3.0: #54400
    2.1: #54402
---
 be/src/vec/data_types/data_type_decimal.h          |  14 +-
 .../datatype_p0/decimalv3/test_decimal256_cast.out | Bin 1433 -> 9361 bytes
 .../datatype_p0/decimalv3/test_decimalv3_cast2.out | Bin 4379 -> 4380 bytes
 regression-test/data/nereids_arith_p0/decimal.out  | Bin 459016 -> 459016 bytes
 .../predefine/test_all_prdefine_type_to_sparse.out | Bin 372581 -> 372581 bytes
 .../decimalv3/test_decimal256_cast.groovy          | 334 +++++++++++++++++++++
 6 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 4703ceef105..1cfa54c8462 100644
--- a/be/src/vec/data_types/data_type_decimal.h
+++ b/be/src/vec/data_types/data_type_decimal.h
@@ -644,6 +644,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])) {
@@ -651,8 +656,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,
@@ -662,8 +667,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/datatype_p0/decimalv3/test_decimalv3_cast2.out 
b/regression-test/data/datatype_p0/decimalv3/test_decimalv3_cast2.out
index 2b9689fb081..586be2b0212 100644
Binary files 
a/regression-test/data/datatype_p0/decimalv3/test_decimalv3_cast2.out and 
b/regression-test/data/datatype_p0/decimalv3/test_decimalv3_cast2.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/data/variant_p0/predefine/test_all_prdefine_type_to_sparse.out
 
b/regression-test/data/variant_p0/predefine/test_all_prdefine_type_to_sparse.out
index 107118ed2fc..16344c482af 100644
Binary files 
a/regression-test/data/variant_p0/predefine/test_all_prdefine_type_to_sparse.out
 and 
b/regression-test/data/variant_p0/predefine/test_all_prdefine_type_to_sparse.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]

Reply via email to