You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by mo...@apache.org on 2023/04/09 02:01:11 UTC

[doris] 08/12: [Bug](DECIMALV3) fix wrong decimal scale returned by function `round` (#18375)

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

morningman pushed a commit to branch branch-1.2-lts
in repository https://gitbox.apache.org/repos/asf/doris.git

commit 5b4d158466a91a3bd9690bac4d84b66ca405d02d
Author: Gabriel <ga...@gmail.com>
AuthorDate: Thu Apr 6 14:44:21 2023 +0800

    [Bug](DECIMALV3) fix wrong decimal scale returned by function `round` (#18375)
---
 be/src/vec/functions/round.h                       |  2 +-
 .../sql_functions/math_functions/test_round.out    |  3 ++
 .../sql_functions/math_functions/test_round.groovy | 40 +++++++++++++++++++++-
 3 files changed, 43 insertions(+), 2 deletions(-)

diff --git a/be/src/vec/functions/round.h b/be/src/vec/functions/round.h
index 456d6264a2..6d24166736 100644
--- a/be/src/vec/functions/round.h
+++ b/be/src/vec/functions/round.h
@@ -457,7 +457,7 @@ struct Dispatcher {
             const auto* const decimal_col = check_and_get_column<ColumnDecimal<T>>(col_general);
             const auto& vec_src = decimal_col->get_data();
 
-            auto col_res = ColumnDecimal<T>::create(vec_src.size(), decimal_col->get_scale());
+            auto col_res = ColumnDecimal<T>::create(vec_src.size(), scale_arg);
             auto& vec_res = col_res->get_data();
 
             if (!vec_res.empty()) {
diff --git a/regression-test/data/query_p0/sql_functions/math_functions/test_round.out b/regression-test/data/query_p0/sql_functions/math_functions/test_round.out
index 6c65a1982f..6363a18165 100644
--- a/regression-test/data/query_p0/sql_functions/math_functions/test_round.out
+++ b/regression-test/data/query_p0/sql_functions/math_functions/test_round.out
@@ -43,3 +43,6 @@
 -- !select --
 10	10	10
 
+-- !query --
+111	001	15.0700	0.2300
+
diff --git a/regression-test/suites/query_p0/sql_functions/math_functions/test_round.groovy b/regression-test/suites/query_p0/sql_functions/math_functions/test_round.groovy
index 7dad51e383..fa00278981 100644
--- a/regression-test/suites/query_p0/sql_functions/math_functions/test_round.groovy
+++ b/regression-test/suites/query_p0/sql_functions/math_functions/test_round.groovy
@@ -48,5 +48,43 @@ suite("test_round") {
     qt_select """ SELECT ceil(col1, -1), ceil(col2, -1), ceil(col3, -1) FROM `${tableName}`; """
     qt_select """ SELECT truncate(col1, -1), truncate(col2, -1), truncate(col3, -1) FROM `${tableName}`; """
 
-    sql """ DROP TABLE IF EXISTS ${tableName} """
+    def tableName1 = "test_round1"
+    sql """ CREATE TABLE `${tableName1}` (
+          `TENANT_ID` varchar(50) NOT NULL,
+          `PUBONLN_PRC` decimalv3(18, 4) NULL,
+          `PRODENTP_CODE` varchar(50) NULL,
+          `ORD_SUMAMT` decimalv3(18, 4) NULL,
+          `PURC_CNT` decimalv3(12, 2) NULL
+        ) ENGINE=OLAP
+        UNIQUE KEY(`TENANT_ID`)
+        DISTRIBUTED BY HASH(`TENANT_ID`) BUCKETS 16
+        PROPERTIES (
+        "replication_allocation" = "tag.location.default: 1",
+        "in_memory" = "false",
+        "storage_format" = "V2",
+        "enable_unique_key_merge_on_write" = "true",
+        "disable_auto_compaction" = "false"
+        ); """
+
+    def tableName2 = "test_round2"
+    sql """ CREATE TABLE `${tableName2}` (
+          `tenant_id` varchar(50) NOT NULL COMMENT '租户ID',
+          `prodentp_code` varchar(50) NULL COMMENT '生产企业代码',
+          `delv_amt` decimalv3(18, 4) NULL DEFAULT "0" COMMENT '配送金额',
+          `ord_sumamt` decimalv3(18, 4) NULL COMMENT '订单总金额'
+        ) ENGINE=OLAP
+        UNIQUE KEY(`tenant_id`, `prodentp_code`)
+        COMMENT '订单明细配送统计'
+        DISTRIBUTED BY HASH(`prodentp_code`) BUCKETS 16
+        PROPERTIES (
+        "replication_allocation" = "tag.location.default: 1",
+        "in_memory" = "false",
+        "storage_format" = "V2",
+        "enable_unique_key_merge_on_write" = "true",
+        "disable_auto_compaction" = "false"
+        );                """
+
+    sql """ insert into ${tableName1} values ('111', 1.2432, '001', 0.2341, 12.1234123); """
+    sql """ insert into ${tableName2} select  TENANT_ID,PRODENTP_CODE,ROUND((MAX(PURC_CNT)*MAX(PUBONLN_PRC)),2) delv_amt,ROUND(SUM(ORD_SUMAMT),2) from ${tableName1} GROUP BY TENANT_ID,PRODENTP_CODE; """
+    qt_query """ select * from ${tableName2} """
 }


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