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

lihaopeng 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 a0463ea047 [round](decimalv2) round decimalv2 to precision value 
(#22138)
a0463ea047 is described below

commit a0463ea047b4a0483d1e75df91c9ec26c1605fec
Author: Gabriel <[email protected]>
AuthorDate: Tue Jul 25 03:29:48 2023 +0800

    [round](decimalv2) round decimalv2 to precision value (#22138)
    
    * [round](decimalv2) round decimalv2 to precision value
    
    * update
    
    * update`
---
 be/src/vec/functions/round.h                                 |  7 ++++---
 gensrc/script/doris_builtins_functions.py                    |  9 +++++++++
 .../query_p0/sql_functions/math_functions/test_round.out     | 12 ++++++++++++
 .../query_p0/sql_functions/math_functions/test_round.groovy  | 11 +++++++++++
 4 files changed, 36 insertions(+), 3 deletions(-)

diff --git a/be/src/vec/functions/round.h b/be/src/vec/functions/round.h
index 1460fc12ec..b19dc26383 100644
--- a/be/src/vec/functions/round.h
+++ b/be/src/vec/functions/round.h
@@ -151,6 +151,7 @@ private:
 public:
     static NO_INLINE void apply(const Container& in, UInt32 in_scale, 
Container& out,
                                 Int16 out_scale) {
+        constexpr bool is_decimalv2 = IsDecimalV2<T>;
         Int16 scale_arg = in_scale - out_scale;
         if (scale_arg > 0) {
             size_t scale = int_exp10(scale_arg);
@@ -160,15 +161,15 @@ public:
             NativeType* __restrict p_out = 
reinterpret_cast<NativeType*>(out.data());
 
             if (out_scale < 0) {
-                size_t target_scale = int_exp10(-out_scale);
                 while (p_in < end_in) {
-                    Op::compute(p_in, scale, p_out, target_scale);
+                    Op::compute(p_in, scale, p_out,
+                                is_decimalv2 ? int_exp10(9 - out_scale) : 
int_exp10(-out_scale));
                     ++p_in;
                     ++p_out;
                 }
             } else {
                 while (p_in < end_in) {
-                    Op::compute(p_in, scale, p_out, 1);
+                    Op::compute(p_in, scale, p_out, is_decimalv2 ? scale : 1);
                     ++p_in;
                     ++p_out;
                 }
diff --git a/gensrc/script/doris_builtins_functions.py 
b/gensrc/script/doris_builtins_functions.py
index e52fa4e558..2a39f7ca7c 100644
--- a/gensrc/script/doris_builtins_functions.py
+++ b/gensrc/script/doris_builtins_functions.py
@@ -1242,6 +1242,10 @@ visible_functions = {
         [['floor', 'dfloor'], 'DOUBLE', ['DOUBLE'], ''],
         [['round', 'dround'], 'DOUBLE', ['DOUBLE'], ''],
         [['round_bankers'], 'DOUBLE', ['DOUBLE'], ''],
+        [['ceil', 'ceiling', 'dceil'], 'DECIMALV2', ['DECIMALV2'], ''],
+        [['floor', 'dfloor'], 'DECIMALV2', ['DECIMALV2'], ''],
+        [['round', 'dround'], 'DECIMALV2', ['DECIMALV2'], ''],
+        [['round_bankers'], 'DECIMALV2', ['DECIMALV2'], ''],
         [['ceil', 'ceiling', 'dceil'], 'DECIMAL32', ['DECIMAL32'], ''],
         [['floor', 'dfloor'], 'DECIMAL32', ['DECIMAL32'], ''],
         [['round', 'dround'], 'DECIMAL32', ['DECIMAL32'], ''],
@@ -1255,20 +1259,25 @@ visible_functions = {
         [['round', 'dround'], 'DECIMAL128', ['DECIMAL128'], ''],
         [['round_bankers'], 'DECIMAL128', ['DECIMAL128'], ''],
         [['round', 'dround'], 'DOUBLE', ['DOUBLE', 'INT'], ''],
+        [['round', 'dround'], 'DECIMALV2', ['DECIMALV2', 'INT'], ''],
         [['round', 'dround'], 'DECIMAL32', ['DECIMAL32', 'INT'], ''],
         [['round', 'dround'], 'DECIMAL64', ['DECIMAL64', 'INT'], ''],
         [['round', 'dround'], 'DECIMAL128', ['DECIMAL128', 'INT'], ''],
         [['round_bankers', 'round_bankers'], 'DOUBLE', ['DOUBLE', 'INT'], ''],
+        [['round_bankers', 'round_bankers'], 'DECIMALV2', ['DECIMALV2', 
'INT'], ''],
         [['round_bankers'], 'DECIMAL32', ['DECIMAL32', 'INT'], ''],
         [['round_bankers'], 'DECIMAL64', ['DECIMAL64', 'INT'], ''],
         [['round_bankers'], 'DECIMAL128', ['DECIMAL128', 'INT'], ''],
+        [['floor', 'dfloor'], 'DECIMALV2', ['DECIMALV2', 'INT'], ''],
         [['floor', 'dfloor'], 'DECIMAL32', ['DECIMAL32', 'INT'], ''],
         [['floor', 'dfloor'], 'DECIMAL64', ['DECIMAL64', 'INT'], ''],
         [['floor', 'dfloor'], 'DECIMAL128', ['DECIMAL128', 'INT'], ''],
+        [['ceil', 'dceil'], 'DECIMALV2', ['DECIMALV2', 'INT'], ''],
         [['ceil', 'dceil'], 'DECIMAL32', ['DECIMAL32', 'INT'], ''],
         [['ceil', 'dceil'], 'DECIMAL64', ['DECIMAL64', 'INT'], ''],
         [['ceil', 'dceil'], 'DECIMAL128', ['DECIMAL128', 'INT'], ''],
         [['truncate'], 'DOUBLE', ['DOUBLE', 'INT'], ''],
+        [['truncate'], 'DECIMALV2', ['DECIMALV2', 'INT'], ''],
         [['truncate'], 'DECIMAL32', ['DECIMAL32', 'INT'], ''],
         [['truncate'], 'DECIMAL64', ['DECIMAL64', 'INT'], ''],
         [['truncate'], 'DECIMAL128', ['DECIMAL128', 'INT'], ''],
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 c126a6dd55..d6a4c290e7 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
@@ -116,3 +116,15 @@
 -- !query --
 0.000  0.000   0.000
 
+-- !query --
+16.03
+
+-- !query --
+16.02
+
+-- !query --
+16.030000000
+
+-- !query --
+16.020000000
+
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 73626e362e..71fb2677ec 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
@@ -139,4 +139,15 @@
     qt_query """ select cast(round(sum(d1), -2) as decimalv3(27, 3)), 
cast(round(sum(d2), -2) as decimalv3(27, 3)), cast(round(sum(d3), -2) as 
decimalv3(27, 3)) from ${tableName3} """
     qt_query """ select cast(round(sum(d1), -4) as decimalv3(27, 3)), 
cast(round(sum(d2), -4) as decimalv3(27, 3)), cast(round(sum(d3), -4) as 
decimalv3(27, 3)) from ${tableName3} """
 
+    sql """ ADMIN SET FRONTEND CONFIG ("enable_decimal_conversion" = "false"); 
"""
+    sql """ ADMIN SET FRONTEND CONFIG ("disable_decimalv2" = "false"); """
+    sql """ set experimental_enable_nereids_planner=false; """
+    sql """ DROP TABLE IF EXISTS `test_decimalv2` """
+    sql """ CREATE TABLE `test_decimalv2` ( id int, decimal_col DECIMAL(19,5)) 
ENGINE=OLAP duplicate KEY (id) DISTRIBUTED BY HASH(id) BUCKETS 1 PROPERTIES ( 
"replication_allocation" = "tag.location.default: 1"); """
+    sql """ insert into test_decimalv2 values (1, 16.025); """
+    qt_query """ select round(decimal_col,2) from test_decimalv2; """
+    qt_query """ select truncate(decimal_col,2) from test_decimalv2; """
+    qt_query """ select ceil(decimal_col,2) from test_decimalv2; """
+    qt_query """ select floor(decimal_col,2) from test_decimalv2; """
+    sql """ ADMIN SET FRONTEND CONFIG ("enable_decimal_conversion" = "true"); 
"""
 }


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

Reply via email to