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 639c7ee7fba [fix](decimalv2) fix scale of decimalv2 to string (#35222) 
(#35359)
639c7ee7fba is described below

commit 639c7ee7fba06e9dac495db38c96cabc2cc8607c
Author: TengJianPing <18241664+jackte...@users.noreply.github.com>
AuthorDate: Fri May 24 17:20:43 2024 +0800

    [fix](decimalv2) fix scale of decimalv2 to string (#35222) (#35359)
    
    * [fix](decimalv2) fix scale of decimalv2 to string
---
 be/src/vec/data_types/data_type_decimal.cpp        |  11 ++-
 be/src/vec/data_types/data_type_decimal.h          |  33 ++++++-
 be/src/vec/data_types/data_type_factory.cpp        |   6 +-
 be/test/vec/data_types/from_string_test.cpp        |   6 +-
 .../data_types/serde/data_type_serde_csv_test.cpp  |   4 +-
 .../data_types/serde/data_type_serde_text_test.cpp |  32 +++++--
 .../java/org/apache/doris/qe/SessionVariable.java  |   6 --
 .../decimalv2/test_decimalv2_cast_to_string.out    |  46 +++++++++
 .../decimalv3/test_decimalv3_cast_to_string.out    |  26 ++++++
 .../decimalv2/test_decimalv2_cast_to_string.groovy | 103 +++++++++++++++++++++
 .../decimalv3/test_decimalv3_cast_to_string.groovy |  68 ++++++++++++++
 11 files changed, 317 insertions(+), 24 deletions(-)

diff --git a/be/src/vec/data_types/data_type_decimal.cpp 
b/be/src/vec/data_types/data_type_decimal.cpp
index 384ffc83ce6..6532a5f0b7a 100644
--- a/be/src/vec/data_types/data_type_decimal.cpp
+++ b/be/src/vec/data_types/data_type_decimal.cpp
@@ -64,8 +64,13 @@ std::string DataTypeDecimal<T>::to_string(const IColumn& 
column, size_t row_num)
     ColumnPtr ptr = result.first;
     row_num = result.second;
 
-    auto value = assert_cast<const ColumnType&>(*ptr).get_element(row_num);
-    return value.to_string(scale);
+    if constexpr (!IsDecimalV2<T>) {
+        auto value = assert_cast<const ColumnType&>(*ptr).get_element(row_num);
+        return value.to_string(scale);
+    } else {
+        auto value = (DecimalV2Value)assert_cast<const 
ColumnType&>(*ptr).get_element(row_num);
+        return value.to_string(get_format_scale());
+    }
 }
 
 template <typename T>
@@ -81,7 +86,7 @@ void DataTypeDecimal<T>::to_string(const IColumn& column, 
size_t row_num,
         ostr.write(str.data(), str.size());
     } else {
         auto value = (DecimalV2Value)assert_cast<const 
ColumnType&>(*ptr).get_element(row_num);
-        auto str = value.to_string(scale);
+        auto str = value.to_string(get_format_scale());
         ostr.write(str.data(), str.size());
     }
 }
diff --git a/be/src/vec/data_types/data_type_decimal.h 
b/be/src/vec/data_types/data_type_decimal.h
index bd82ae36290..a2f4170f236 100644
--- a/be/src/vec/data_types/data_type_decimal.h
+++ b/be/src/vec/data_types/data_type_decimal.h
@@ -22,8 +22,6 @@
 #include <fmt/format.h>
 #include <gen_cpp/Types_types.h>
 #include <glog/logging.h>
-#include <stddef.h>
-#include <stdint.h>
 
 #include <algorithm>
 #include <cassert>
@@ -144,12 +142,28 @@ public:
 
     static constexpr size_t max_precision() { return 
max_decimal_precision<T>(); }
 
-    DataTypeDecimal(UInt32 precision = 27, UInt32 scale = 9) : 
precision(precision), scale(scale) {
+    DataTypeDecimal(UInt32 precision = 27, UInt32 scale = 9,
+                    UInt32 arg_original_precision = UINT32_MAX,
+                    UInt32 arg_original_scale = UINT32_MAX)
+            : precision(precision),
+              scale(scale),
+              original_precision(arg_original_precision),
+              original_scale(arg_original_scale) {
         check_type_precision(precision);
         check_type_scale(scale);
+        if (UINT32_MAX != original_precision) {
+            check_type_precision(original_precision);
+        }
+        if (UINT32_MAX != original_scale) {
+            check_type_scale(scale);
+        }
     }
 
-    DataTypeDecimal(const DataTypeDecimal& rhs) : precision(rhs.precision), 
scale(rhs.scale) {}
+    DataTypeDecimal(const DataTypeDecimal& rhs)
+            : precision(rhs.precision),
+              scale(rhs.scale),
+              original_precision(rhs.original_precision),
+              original_scale(rhs.original_scale) {}
 
     const char* get_family_name() const override { return "Decimal"; }
     std::string do_get_name() const override;
@@ -248,6 +262,9 @@ public:
 
     [[nodiscard]] UInt32 get_precision() const override { return precision; }
     [[nodiscard]] UInt32 get_scale() const override { return scale; }
+    [[nodiscard]] UInt32 get_format_scale() const {
+        return UINT32_MAX == original_scale ? scale : original_scale;
+    }
     T get_scale_multiplier() const { return get_scale_multiplier(scale); }
 
     T whole_part(T x) const {
@@ -323,6 +340,14 @@ public:
 private:
     const UInt32 precision;
     const UInt32 scale;
+
+    // For decimalv2 only, record the original(schema) precision and scale.
+    // UINT32_MAX means original precision and scale are unknown.
+    // Decimalv2 will be converted to Decimal(27, 9) in memory when doing any 
calculations,
+    // but when casting decimalv2 to string, it's better to keep the presion 
and
+    // scale of it's original value in schema.
+    UInt32 original_precision = UINT32_MAX;
+    UInt32 original_scale = UINT32_MAX;
 };
 
 template <typename T, typename U>
diff --git a/be/src/vec/data_types/data_type_factory.cpp 
b/be/src/vec/data_types/data_type_factory.cpp
index 59d2113008f..9c40588ed31 100644
--- a/be/src/vec/data_types/data_type_factory.cpp
+++ b/be/src/vec/data_types/data_type_factory.cpp
@@ -188,7 +188,8 @@ DataTypePtr DataTypeFactory::create_data_type(const 
TypeDescriptor& col_desc, bo
         nested = std::make_shared<vectorized::DataTypeBitMap>();
         break;
     case TYPE_DECIMALV2:
-        nested = 
std::make_shared<vectorized::DataTypeDecimal<vectorized::Decimal128V2>>(27, 9);
+        nested = 
std::make_shared<vectorized::DataTypeDecimal<vectorized::Decimal128V2>>(
+                27, 9, col_desc.precision, col_desc.scale);
         break;
     case TYPE_QUANTILE_STATE:
         nested = std::make_shared<vectorized::DataTypeQuantileState>();
@@ -414,7 +415,8 @@ DataTypePtr 
DataTypeFactory::_create_primitive_data_type(const FieldType& type,
         result = std::make_shared<vectorized::DataTypeBitMap>();
         break;
     case FieldType::OLAP_FIELD_TYPE_DECIMAL:
-        result = 
std::make_shared<vectorized::DataTypeDecimal<vectorized::Decimal128V2>>(27, 9);
+        result = 
std::make_shared<vectorized::DataTypeDecimal<vectorized::Decimal128V2>>(
+                27, 9, precision, scale);
         break;
     case FieldType::OLAP_FIELD_TYPE_QUANTILE_STATE:
         result = std::make_shared<vectorized::DataTypeQuantileState>();
diff --git a/be/test/vec/data_types/from_string_test.cpp 
b/be/test/vec/data_types/from_string_test.cpp
index 83b65f0fa3a..01515b805d9 100644
--- a/be/test/vec/data_types/from_string_test.cpp
+++ b/be/test/vec/data_types/from_string_test.cpp
@@ -158,7 +158,11 @@ TEST(FromStringTest, ScalaWrapperFieldVsDataType) {
             DataTypePtr data_type_ptr;
             int precision = 0;
             int scale = 0;
-            if (type == FieldType::OLAP_FIELD_TYPE_DECIMAL32) {
+            if (type == FieldType::OLAP_FIELD_TYPE_DECIMAL) {
+                data_type_ptr = 
DataTypeFactory::instance().create_data_type(type, 27, 9);
+                precision = 27;
+                scale = 9;
+            } else if (type == FieldType::OLAP_FIELD_TYPE_DECIMAL32) {
                 // decimal32(7, 2)
                 data_type_ptr = 
DataTypeFactory::instance().create_data_type(type, 9, 2);
                 precision = 9;
diff --git a/be/test/vec/data_types/serde/data_type_serde_csv_test.cpp 
b/be/test/vec/data_types/serde/data_type_serde_csv_test.cpp
index ca730fe7bc9..9f9fe9043b9 100644
--- a/be/test/vec/data_types/serde/data_type_serde_csv_test.cpp
+++ b/be/test/vec/data_types/serde/data_type_serde_csv_test.cpp
@@ -125,7 +125,9 @@ TEST(CsvSerde, ScalaDataTypeSerdeCsvTest) {
         for (auto type_pair : arithmetic_scala_field_types) {
             auto type = std::get<0>(type_pair);
             DataTypePtr data_type_ptr;
-            if (type == FieldType::OLAP_FIELD_TYPE_DECIMAL32) {
+            if (type == FieldType::OLAP_FIELD_TYPE_DECIMAL) {
+                data_type_ptr = 
DataTypeFactory::instance().create_data_type(type, 27, 9);
+            } else if (type == FieldType::OLAP_FIELD_TYPE_DECIMAL32) {
                 // decimal32(7, 2)
                 data_type_ptr = 
DataTypeFactory::instance().create_data_type(type, 9, 2);
             } else if (type == FieldType::OLAP_FIELD_TYPE_DECIMAL64) {
diff --git a/be/test/vec/data_types/serde/data_type_serde_text_test.cpp 
b/be/test/vec/data_types/serde/data_type_serde_text_test.cpp
index 2e85c2c3dc1..2affbc36c86 100644
--- a/be/test/vec/data_types/serde/data_type_serde_text_test.cpp
+++ b/be/test/vec/data_types/serde/data_type_serde_text_test.cpp
@@ -125,7 +125,9 @@ TEST(TextSerde, ScalaDataTypeSerdeTextTest) {
         for (auto type_pair : arithmetic_scala_field_types) {
             auto type = std::get<0>(type_pair);
             DataTypePtr data_type_ptr;
-            if (type == FieldType::OLAP_FIELD_TYPE_DECIMAL32) {
+            if (type == FieldType::OLAP_FIELD_TYPE_DECIMAL) {
+                data_type_ptr = 
DataTypeFactory::instance().create_data_type(type, 27, 9);
+            } else if (type == FieldType::OLAP_FIELD_TYPE_DECIMAL32) {
                 // decimal32(7, 2)
                 data_type_ptr = 
DataTypeFactory::instance().create_data_type(type, 9, 2);
             } else if (type == FieldType::OLAP_FIELD_TYPE_DECIMAL64) {
@@ -442,8 +444,12 @@ TEST(TextSerde, ComplexTypeSerdeTextTest) {
         // array type
         for (auto type_pair : nested_field_types) {
             auto type = std::get<0>(type_pair);
-            DataTypePtr nested_data_type_ptr =
-                    DataTypeFactory::instance().create_data_type(type, 0, 0);
+            DataTypePtr nested_data_type_ptr;
+            if (type == FieldType::OLAP_FIELD_TYPE_DECIMAL) {
+                nested_data_type_ptr = 
DataTypeFactory::instance().create_data_type(type, 27, 9);
+            } else {
+                nested_data_type_ptr = 
DataTypeFactory::instance().create_data_type(type, 0, 0);
+            }
             DataTypePtr array_data_type_ptr = make_nullable(
                     
std::make_shared<DataTypeArray>(make_nullable(nested_data_type_ptr)));
 
@@ -611,8 +617,14 @@ TEST(TextSerde, ComplexTypeSerdeTextTest) {
             auto value_type = std::get<1>(type_pair);
             DataTypePtr nested_key_type_ptr =
                     DataTypeFactory::instance().create_data_type(key_type, 0, 
0);
-            DataTypePtr nested_value_type_ptr =
-                    DataTypeFactory::instance().create_data_type(value_type, 
0, 0);
+            DataTypePtr nested_value_type_ptr;
+            if (value_type == FieldType::OLAP_FIELD_TYPE_DECIMAL) {
+                nested_value_type_ptr =
+                        
DataTypeFactory::instance().create_data_type(value_type, 27, 9);
+            } else {
+                nested_value_type_ptr =
+                        
DataTypeFactory::instance().create_data_type(value_type, 0, 0);
+            }
             DataTypePtr map_data_type_ptr = 
make_nullable(std::make_shared<DataTypeMap>(
                     make_nullable(nested_key_type_ptr), 
make_nullable(nested_value_type_ptr)));
 
@@ -697,8 +709,14 @@ TEST(TextSerde, ComplexTypeSerdeTextTest) {
             auto value_type = std::get<1>(type_pair);
             DataTypePtr nested_key_type_ptr =
                     DataTypeFactory::instance().create_data_type(key_type, 0, 
0);
-            DataTypePtr nested_value_type_ptr =
-                    DataTypeFactory::instance().create_data_type(value_type, 
0, 0);
+            DataTypePtr nested_value_type_ptr;
+            if (value_type == FieldType::OLAP_FIELD_TYPE_DECIMAL) {
+                nested_value_type_ptr =
+                        
DataTypeFactory::instance().create_data_type(value_type, 27, 9);
+            } else {
+                nested_value_type_ptr =
+                        
DataTypeFactory::instance().create_data_type(value_type, 0, 0);
+            }
             DataTypePtr map_data_type_ptr = std::make_shared<DataTypeMap>(
                     make_nullable(nested_key_type_ptr), 
make_nullable(nested_value_type_ptr));
 
diff --git a/fe/fe-core/src/main/java/org/apache/doris/qe/SessionVariable.java 
b/fe/fe-core/src/main/java/org/apache/doris/qe/SessionVariable.java
index bb245e4912b..602c10249d3 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/qe/SessionVariable.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/qe/SessionVariable.java
@@ -862,8 +862,6 @@ public class SessionVariable implements Serializable, 
Writable {
     public String defaultStorageEngine = "olap";
     @VariableMgr.VarAttr(name = DEFAULT_TMP_STORAGE_ENGINE)
     public String defaultTmpStorageEngine = "olap";
-    @VariableMgr.VarAttr(name = DIV_PRECISION_INCREMENT)
-    public int divPrecisionIncrement = 4;
 
     // -1 means unset, BE will use its config value
     @VariableMgr.VarAttr(name = MAX_SCAN_KEY_NUM)
@@ -2485,10 +2483,6 @@ public class SessionVariable implements Serializable, 
Writable {
         this.storageEngine = storageEngine;
     }
 
-    public int getDivPrecisionIncrement() {
-        return divPrecisionIncrement;
-    }
-
     public int getMaxScanKeyNum() {
         return maxScanKeyNum;
     }
diff --git 
a/regression-test/data/datatype_p0/decimalv2/test_decimalv2_cast_to_string.out 
b/regression-test/data/datatype_p0/decimalv2/test_decimalv2_cast_to_string.out
new file mode 100644
index 00000000000..dca5f03143d
--- /dev/null
+++ 
b/regression-test/data/datatype_p0/decimalv2/test_decimalv2_cast_to_string.out
@@ -0,0 +1,46 @@
+-- This file is automatically generated. You should know what you did if you 
want to edit this
+-- !cast1 --
+\N     \N
+-999999999999999999.999999999  -999999999999999999.999999999
+-999999999999999999.000000000  -999999999999999999.000000000
+-1.123000000   -1.123000000
+-1.000000000   -1.000000000
+-0.100000000   -0.100000000
+-1E-9  -0.000000001
+0E-9   0.000000000
+1E-9   0.000000001
+0.100000000    0.100000000
+1.000000000    1.000000000
+1.123000000    1.123000000
+999999999999999999.000000000   999999999999999999.000000000
+999999999999999999.999999999   999999999999999999.999999999
+
+-- !cast2 --
+\N     \N
+-9999999.999   -9999999.999
+-9999999.001   -9999999.001
+-9999999.000   -9999999.000
+-1.123 -1.123
+-1.123 -1.123
+-1.100 -1.100
+-1.000 -1.000
+-0.100 -0.100
+-0.001 -0.001
+0.000  0.000
+0.001  0.001
+0.100  0.100
+1.000  1.000
+1.100  1.100
+1.123  1.123
+1.123  1.123
+9999999.000    9999999.000
+9999999.001    9999999.001
+9999999.999    9999999.999
+
+-- !join1 --
+1.123  1.1230
+
+-- !cast_join1 --
+
+-- !cast_join2 --
+
diff --git 
a/regression-test/data/datatype_p0/decimalv3/test_decimalv3_cast_to_string.out 
b/regression-test/data/datatype_p0/decimalv3/test_decimalv3_cast_to_string.out
new file mode 100644
index 00000000000..c4622cdcb42
--- /dev/null
+++ 
b/regression-test/data/datatype_p0/decimalv3/test_decimalv3_cast_to_string.out
@@ -0,0 +1,26 @@
+-- This file is automatically generated. You should know what you did if you 
want to edit this
+-- !cast1 --
+\N     \N
+-99999999999999999999999999999999.999999       
-99999999999999999999999999999999.999999
+-99999999999999999999999999999999.000001       
-99999999999999999999999999999999.000001
+-99999999999999999999999999999999.000000       
-99999999999999999999999999999999.000000
+-1.123000      -1.123000
+-1.000000      -1.000000
+-0.100000      -0.100000
+-0.000001      -0.000001
+0.000000       0.000000
+0.000001       0.000001
+0.100000       0.100000
+1.000000       1.000000
+1.123000       1.123000
+99999999999999999999999999999999.000000        
99999999999999999999999999999999.000000
+99999999999999999999999999999999.000001        
99999999999999999999999999999999.000001
+99999999999999999999999999999999.999999        
99999999999999999999999999999999.999999
+
+-- !join1 --
+1.123  1.1230
+
+-- !cast_join1 --
+
+-- !cast_join2 --
+
diff --git 
a/regression-test/suites/datatype_p0/decimalv2/test_decimalv2_cast_to_string.groovy
 
b/regression-test/suites/datatype_p0/decimalv2/test_decimalv2_cast_to_string.groovy
new file mode 100644
index 00000000000..28c7de8aed0
--- /dev/null
+++ 
b/regression-test/suites/datatype_p0/decimalv2/test_decimalv2_cast_to_string.groovy
@@ -0,0 +1,103 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+suite("test_decimalv2_cast_to_string", "nonConcurrent") {
+    def config_row = sql """ ADMIN SHOW FRONTEND CONFIG LIKE 
'disable_decimalv2'; """
+    String old_value1 = config_row[0][1]
+    config_row = sql """ ADMIN SHOW FRONTEND CONFIG LIKE 
'enable_decimal_conversion'; """
+    String old_value2 = config_row[0][1]
+
+    sql """
+        admin set frontend config("enable_decimal_conversion" = "false");
+    """
+    sql """
+        admin set frontend config("disable_decimalv2" = "false");
+    """
+
+    sql """
+        drop table if exists decimalv2_cast_to_string_test;
+    """
+    sql """
+        create table decimalv2_cast_to_string_test (k1 decimalv2(27,9)) 
distributed by hash(k1) properties("replication_num"="1");
+    """
+    sql """
+        insert into decimalv2_cast_to_string_test  values (null), (0), (1), 
(1.123), (0.1), (0.000000001), (999999999999999999), 
(999999999999999999.999999999);
+    """
+    sql """
+        insert into decimalv2_cast_to_string_test  values (-1), (-1.123), 
(-0.1), (-0.000000001), (-999999999999999999), (-999999999999999999.999999999);
+    """
+
+    qt_cast1 """
+        select k1, cast(k1 as varchar) from decimalv2_cast_to_string_test 
order by 1;
+    """
+
+    sql """
+        drop table if exists decimalv2_cast_to_string_test2;
+    """
+    sql """
+        create table decimalv2_cast_to_string_test2 (k1 decimalv2(10,3)) 
distributed by hash(k1) properties("replication_num"="1");
+    """
+    sql """
+        insert into decimalv2_cast_to_string_test2 values (null), (0), (0.1), 
(0.001), (1), (1.1), (1.123), (1.123456789), (9999999), (9999999.001), 
(9999999.999);
+    """
+    sql """
+        insert into decimalv2_cast_to_string_test2 values (-0.1), (-0.001), 
(-1), (-1.1), (-1.123), (-1.123456789), (-9999999), (-9999999.001), 
(-9999999.999);
+    """
+
+    qt_cast2 """
+        select k1, cast(k1 as varchar) from decimalv2_cast_to_string_test2 
order by 1;
+    """
+
+    sql """
+        drop table if exists decimalv2_cast_to_string_join_test_l;
+    """
+    sql """
+        drop table if exists decimalv2_cast_to_string_join_test_r;
+    """
+    sql """
+        create table decimalv2_cast_to_string_join_test_l(k1 decimalv2(10, 3)) 
distributed by hash(k1) properties("replication_num"="1");
+    """
+    sql """
+        create table decimalv2_cast_to_string_join_test_r(kk1 decimalv2(10, 
4)) distributed by hash(kk1) properties("replication_num"="1");
+    """
+    sql """
+        insert into decimalv2_cast_to_string_join_test_l values (1.123);
+    """
+    sql """
+        insert into decimalv2_cast_to_string_join_test_r values (1.123);
+    """
+    qt_join1 """
+        select * from decimalv2_cast_to_string_join_test_l, 
decimalv2_cast_to_string_join_test_r where k1 = kk1 order by 1, 2;
+    """
+    // scale is different, cast result will not equal
+    qt_cast_join1 """
+        select k1, cast(k1 as char(16)) k1cast, kk1, cast(kk1 as char(16)) 
kk1cast
+            from decimalv2_cast_to_string_join_test_l, 
decimalv2_cast_to_string_join_test_r
+        where cast(k1 as char(16)) = cast(kk1 as char(16)) order by 1, 2;
+    """
+    qt_cast_join2 """
+        select k1, cast(k1 as varchar) k1cast, kk1, cast(kk1 as varchar) 
kk1cast
+            from decimalv2_cast_to_string_join_test_l, 
decimalv2_cast_to_string_join_test_r
+        where cast(k1 as varchar) = cast(kk1 as varchar) order by 1, 2;
+    """
+
+    // restore disable_decimalv2 to old_value
+    sql """ ADMIN SET FRONTEND CONFIG ("disable_decimalv2" = "${old_value1}"); 
"""
+
+    // restore enable_decimal_conversion to old_value
+    sql """ ADMIN SET FRONTEND CONFIG ("enable_decimal_conversion" = 
"${old_value2}"); """
+}
\ No newline at end of file
diff --git 
a/regression-test/suites/datatype_p0/decimalv3/test_decimalv3_cast_to_string.groovy
 
b/regression-test/suites/datatype_p0/decimalv3/test_decimalv3_cast_to_string.groovy
new file mode 100644
index 00000000000..57d900d0d6d
--- /dev/null
+++ 
b/regression-test/suites/datatype_p0/decimalv3/test_decimalv3_cast_to_string.groovy
@@ -0,0 +1,68 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+suite("test_decimalv3_cast_to_string") {
+    sql """
+        drop table if exists decimalv3_cast_to_string_test;
+    """
+    sql """
+        create table decimalv3_cast_to_string_test (k1 decimalv3(38,6)) 
distributed by hash(k1) properties("replication_num"="1");
+    """
+    sql """
+        insert into decimalv3_cast_to_string_test values (null), (0), (1), 
(1.123), (0.1), (0.000001), (99999999999999999999999999999999), 
("99999999999999999999999999999999.000001"), 
("99999999999999999999999999999999.999999");
+    """
+    sql """
+        insert into decimalv3_cast_to_string_test values (-1), (-1.123), 
(-0.1), (-0.000001), (-99999999999999999999999999999999), 
("-99999999999999999999999999999999.000001"), 
("-99999999999999999999999999999999.999999");
+    """
+
+    qt_cast1 """
+        select k1, cast(k1 as varchar) from decimalv3_cast_to_string_test 
order by 1;
+    """
+
+    sql """
+        drop table if exists decimalv3_cast_to_string_join_test_l;
+    """
+    sql """
+        drop table if exists decimalv3_cast_to_string_join_test_r;
+    """
+    sql """
+        create table decimalv3_cast_to_string_join_test_l(k1 decimalv3(10, 3)) 
distributed by hash(k1) properties("replication_num"="1");
+    """
+    sql """
+        create table decimalv3_cast_to_string_join_test_r(kk1 decimalv3(10, 
4)) distributed by hash(kk1) properties("replication_num"="1");
+    """
+    sql """
+        insert into decimalv3_cast_to_string_join_test_l values (1.123);
+    """
+    sql """
+        insert into decimalv3_cast_to_string_join_test_r values (1.123);
+    """
+    qt_join1 """
+        select * from decimalv3_cast_to_string_join_test_l, 
decimalv3_cast_to_string_join_test_r where k1 = kk1 order by 1, 2;
+    """
+    // scale is different, cast result will not equal
+    qt_cast_join1 """
+        select k1, cast(k1 as char(16)) k1cast, kk1, cast(kk1 as char(16)) 
kk1cast
+            from decimalv3_cast_to_string_join_test_l, 
decimalv3_cast_to_string_join_test_r
+        where cast(k1 as char(16)) = cast(kk1 as char(16)) order by 1, 2;
+    """
+    qt_cast_join2 """
+        select k1, cast(k1 as varchar) k1cast, kk1, cast(kk1 as varchar) 
kk1cast
+            from decimalv3_cast_to_string_join_test_l, 
decimalv3_cast_to_string_join_test_r
+        where cast(k1 as varchar) = cast(kk1 as varchar) order by 1, 2;
+    """
+}
\ No newline at end of file


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to