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

Mryange 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 80020673198 [fix](function) Round Decimal values with zero decimal 
places (#68010)
80020673198 is described below

commit 800206731984abdf5b775ee0670974d5a4571fb5
Author: Mryange <[email protected]>
AuthorDate: Thu Sep 17 09:50:12 2026 +0800

    [fix](function) Round Decimal values with zero decimal places (#68010)
    
    `format_round` skipped rounding for Decimal values when `decimal_places`
    was zero because the rounding branch required a positive decimal-place
    count. Values such as `1.9` and `-1.9` therefore produced truncated
    results instead of `2` and `-2`. The condition now performs rounding
    whenever the input scale exceeds the requested decimal places, including
    zero, and regression coverage verifies positive, negative, and
    table-column Decimal values.
    
    
    ### Release note
    
    None
    
    ### Check List (For Author)
    
    - Test <!-- At least one of them must be included. -->
        - [ ] Regression test
        - [ ] Unit Test
        - [ ] Manual test (add detailed scripts or steps below)
        - [ ] No need to test or manual test. Explain why:
    - [ ] This is a refactor/code format and no logic has been changed.
            - [ ] Previous test can cover this change.
            - [ ] No code files have been changed.
            - [ ] Other reason <!-- Add your reason?  -->
    
    - Behavior changed:
        - [ ] No.
        - [ ] Yes. <!-- Explain the behavior change -->
    
    - Does this need documentation?
        - [ ] No.
    - [ ] Yes. <!-- Add document PR link here. eg:
    https://github.com/apache/doris-website/pull/1214 -->
    
    ### Check List (For Reviewer who merge this PR)
    
    - [ ] Confirm the release note
    - [ ] Confirm test cases
    - [ ] Confirm document
    - [ ] Add branch pick label <!-- Add branch pick label that this PR
    should merge into -->
---
 be/src/exprs/function/function_string_format.h                   | 2 +-
 .../query_p0/sql_functions/math_functions/test_format_round.out  | 9 ++++++++-
 .../sql_functions/math_functions/test_format_round.groovy        | 9 ++++++++-
 3 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/be/src/exprs/function/function_string_format.h 
b/be/src/exprs/function/function_string_format.h
index c5837b37500..a65f0768826 100644
--- a/be/src/exprs/function/function_string_format.h
+++ b/be/src/exprs/function/function_string_format.h
@@ -268,7 +268,7 @@ StringRef do_format_round(FunctionContext* context, UInt32 
scale, T int_value, T
     const bool is_negative = int_value < 0 || frac_value < 0;
 
     // do round to frac_part based on decimal_places
-    if (scale > decimal_places && decimal_places > 0) {
+    if (static_cast<Int32>(scale) > decimal_places) {
         DCHECK(scale <= 38);
         // do rounding, so we need to reserve decimal_places + 1 digits
         auto multiplier =
diff --git 
a/regression-test/data/query_p0/sql_functions/math_functions/test_format_round.out
 
b/regression-test/data/query_p0/sql_functions/math_functions/test_format_round.out
index 9a5e2caa452..1d91fdc4869 100644
--- 
a/regression-test/data/query_p0/sql_functions/math_functions/test_format_round.out
+++ 
b/regression-test/data/query_p0/sql_functions/math_functions/test_format_round.out
@@ -47,8 +47,15 @@
 123,456.123457
 34.123457
 
+-- !format_round_73 --
+2      -2      1       -1
+
+-- !format_round_74 --
+123,456
+34
+
 -- !format_round_14 --
-9,876
+9,877
 
 -- !format_round_15 --
 0.0000001
diff --git 
a/regression-test/suites/query_p0/sql_functions/math_functions/test_format_round.groovy
 
b/regression-test/suites/query_p0/sql_functions/math_functions/test_format_round.groovy
index 9f179c48759..5304e617bcc 100644
--- 
a/regression-test/suites/query_p0/sql_functions/math_functions/test_format_round.groovy
+++ 
b/regression-test/suites/query_p0/sql_functions/math_functions/test_format_round.groovy
@@ -56,6 +56,13 @@ suite("test_format_round", "p0") {
     order_qt_format_round_10 """ select format_round(largeint_col, 6) from 
test_format_round order by user_id"""
     order_qt_format_round_12 """ select format_round(double_col, 6) from 
test_format_round order by user_id"""
     order_qt_format_round_13 """ select format_round(decimal_col, 6) from 
test_format_round order by user_id"""
+    order_qt_format_round_73 """
+        select format_round(cast(1.9 as decimal(9, 1)), 0),
+                format_round(cast(-1.9 as decimal(9, 1)), 0),
+                format_round(cast(1.4 as decimal(9, 1)), 0),
+                format_round(cast(-1.4 as decimal(9, 1)), 0);
+    """
+    order_qt_format_round_74 """ select format_round(decimal_col, 0) from 
test_format_round order by user_id"""
 
     test {
         sql """select format_round(1234567.8910, -1) """
@@ -125,4 +132,4 @@ suite("test_format_round", "p0") {
     order_qt_format_round_69 """ SELECT format_round(2.2250738585072014E-308, 
324) AS result; """
     order_qt_format_round_70 """ SELECT 
format_round(0.000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001,
 0) AS result; """
     order_qt_format_round_71 """ SELECT 
format_round(0.000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001,
 10) AS result; """
-}
\ No newline at end of file
+}


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

Reply via email to