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

gabriellee pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/master by this push:
     new 8785a474926 [fix](DecimalV2)keep the original precision and scale in 
get_data_type_with_default_argument (#56821)
8785a474926 is described below

commit 8785a474926e9ebac21024b3547e1fca50524fe5
Author: Mryange <[email protected]>
AuthorDate: Mon Oct 13 15:11:02 2025 +0800

    [fix](DecimalV2)keep the original precision and scale in 
get_data_type_with_default_argument (#56821)
    
    In the past, the get_data_type_with_default_argument function would set
    the original precision and scale to 27,9, but this will cause problems
    with some codes that rely on original precision and scale. Here, the
    original precision and scale will be maintained.
---
 be/src/vec/data_types/data_type_decimal.cpp        | 16 ++++--
 .../decimalv2/test_decimalv2_rqg.groovy            | 59 ++++++++++++++++++++++
 2 files changed, 72 insertions(+), 3 deletions(-)

diff --git a/be/src/vec/data_types/data_type_decimal.cpp 
b/be/src/vec/data_types/data_type_decimal.cpp
index 75dee568f3c..01eca424c49 100644
--- a/be/src/vec/data_types/data_type_decimal.cpp
+++ b/be/src/vec/data_types/data_type_decimal.cpp
@@ -55,10 +55,20 @@ namespace doris::vectorized {
 DataTypePtr get_data_type_with_default_argument(DataTypePtr type) {
     auto transform = [&](DataTypePtr t) -> DataTypePtr {
         if (t->get_primitive_type() == PrimitiveType::TYPE_DECIMALV2) {
-            auto res = DataTypeFactory::instance().create_data_type(
-                    TYPE_DECIMALV2, t->is_nullable(), 
BeConsts::MAX_DECIMALV2_PRECISION,
-                    BeConsts::MAX_DECIMALV2_SCALE);
+            auto not_nullable_t = remove_nullable(t);
+            const auto* real_type_t = assert_cast<const 
DataTypeDecimalV2*>(not_nullable_t.get());
+            // should keep the original precision and scale
+            DataTypePtr res = std::make_shared<DataTypeDecimalV2>(
+                    BeConsts::MAX_DECIMALV2_PRECISION, 
BeConsts::MAX_DECIMALV2_SCALE,
+                    real_type_t->get_original_precision(), 
real_type_t->get_original_scale());
+
+            // keep nullable property
+            if (t->is_nullable()) {
+                res = make_nullable(res);
+            }
+
             DCHECK_EQ(res->get_scale(), BeConsts::MAX_DECIMALV2_SCALE);
+
             return res;
         } else if (t->get_primitive_type() == PrimitiveType::TYPE_BINARY ||
                    t->get_primitive_type() == 
PrimitiveType::TYPE_LAMBDA_FUNCTION) {
diff --git 
a/regression-test/suites/datatype_p0/decimalv2/test_decimalv2_rqg.groovy 
b/regression-test/suites/datatype_p0/decimalv2/test_decimalv2_rqg.groovy
new file mode 100644
index 00000000000..f5c9615740a
--- /dev/null
+++ b/regression-test/suites/datatype_p0/decimalv2/test_decimalv2_rqg.groovy
@@ -0,0 +1,59 @@
+// 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_rqg") {
+
+
+    sql """ADMIN SET FRONTEND CONFIG ('disable_decimalv2' = 'false')"""
+
+    sql """
+        CREATE TABLE IF NOT EXISTS TEMPDATA(id INT, data INT) DISTRIBUTED BY 
HASH(id) BUCKETS 1 PROPERTIES ('replication_num' = '1');
+    """
+    sql """
+        INSERT INTO TEMPDATA values(1, 1);
+    """
+
+    sql """CREATE TABLE IF NOT EXISTS 
DECIMALV2_10_0_DATA_NOT_EMPTY_NOT_NULLABLE(id INT, data DECIMALV2(10,0)  NOT 
NULL) DISTRIBUTED BY HASH(id) BUCKETS 1 PROPERTIES ('replication_num' = '1');"""
+
+    sql """
+    INSERT INTO DECIMALV2_10_0_DATA_NOT_EMPTY_NOT_NULLABLE values (0, 
1234567890);"""
+    sql """
+    INSERT INTO DECIMALV2_10_0_DATA_NOT_EMPTY_NOT_NULLABLE values (1, 
9999999999);"""
+    sql """
+    INSERT INTO DECIMALV2_10_0_DATA_NOT_EMPTY_NOT_NULLABLE values (2, 
1000000000);"""
+    sql """
+    INSERT INTO DECIMALV2_10_0_DATA_NOT_EMPTY_NOT_NULLABLE values (3, 
1111111111);"""
+    sql """
+    INSERT INTO DECIMALV2_10_0_DATA_NOT_EMPTY_NOT_NULLABLE values (4, 
-1234567890);"""
+    sql """
+    INSERT INTO DECIMALV2_10_0_DATA_NOT_EMPTY_NOT_NULLABLE values (5, 
-9999999999);"""
+    sql """
+    INSERT INTO DECIMALV2_10_0_DATA_NOT_EMPTY_NOT_NULLABLE values (6, 
-1000000000);"""
+    sql """
+    INSERT INTO DECIMALV2_10_0_DATA_NOT_EMPTY_NOT_NULLABLE values (7, 
-1111111111);"""
+    sql """
+    INSERT INTO DECIMALV2_10_0_DATA_NOT_EMPTY_NOT_NULLABLE values (8, 1);"""
+    sql """
+    INSERT INTO DECIMALV2_10_0_DATA_NOT_EMPTY_NOT_NULLABLE values (9, 0);"""
+    sql """
+    INSERT INTO DECIMALV2_10_0_DATA_NOT_EMPTY_NOT_NULLABLE values (10, -1);"""
+
+
+    sql """
+        SELECT CEIL(ARG0,CAST(-1 AS INT)) FROM (SELECT TEMPDATA . data, 
TABLE0.ARG0 FROM TEMPDATA CROSS JOIN (SELECT data AS ARG0 FROM 
DECIMALV2_10_0_DATA_NOT_EMPTY_NOT_NULLABLE ) AS TABLE0) t ;
+    """
+}
\ No newline at end of file


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to