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

dataroaring pushed a commit to branch branch-3.0
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/branch-3.0 by this push:
     new e7c41278cf9 [branch-3.0](core)Fix format_round will be core when 
entering multiple lines  (#53515)
e7c41278cf9 is described below

commit e7c41278cf946f3f347a4010c54e4a5ed1226fd8
Author: Mryange <[email protected]>
AuthorDate: Sat Jul 19 10:23:52 2025 +0800

    [branch-3.0](core)Fix format_round will be core when entering multiple 
lines  (#53515)
    
    ### What problem does this PR solve?
    
    https://github.com/apache/doris/pull/53314
---
 be/src/vec/functions/function_string.h             |  34 +++++++++++++--------
 .../math_functions/test_format_round.out           | Bin 681 -> 791 bytes
 .../math_functions/test_format_round.groovy        |  13 ++++----
 3 files changed, 28 insertions(+), 19 deletions(-)

diff --git a/be/src/vec/functions/function_string.h 
b/be/src/vec/functions/function_string.h
index b837a2220ce..09122aaf51c 100644
--- a/be/src/vec/functions/function_string.h
+++ b/be/src/vec/functions/function_string.h
@@ -1807,11 +1807,15 @@ public:
         bool is_const;
         std::tie(argument_column_2, is_const) =
                 unpack_if_const(block.get_by_position(arguments[1]).column);
+        auto* result_column = assert_cast<ColumnString*>(res_column.get());
 
-        auto result_column = assert_cast<ColumnString*>(res_column.get());
-
-        RETURN_IF_ERROR(Impl::execute(context, result_column, argument_column, 
argument_column_2,
-                                      input_rows_count));
+        if (is_const) {
+            RETURN_IF_ERROR(Impl::template execute<true>(context, 
result_column, argument_column,
+                                                         argument_column_2, 
input_rows_count));
+        } else {
+            RETURN_IF_ERROR(Impl::template execute<false>(context, 
result_column, argument_column,
+                                                          argument_column_2, 
input_rows_count));
+        }
 
         block.replace_by_position(result, std::move(res_column));
         return Status::OK();
@@ -3180,8 +3184,8 @@ StringRef do_format_round(FunctionContext* context, 
UInt32 scale, T int_value, T
 }
 
 // Note string value must be valid decimal string which contains two digits 
after the decimal point
-static StringRef do_format_round(FunctionContext* context, const string& value,
-                                 Int32 decimal_places) {
+static inline StringRef do_format_round(FunctionContext* context, const 
string& value,
+                                        Int32 decimal_places) {
     bool is_positive = (value[0] != '-');
     int32_t result_len =
             value.size() +
@@ -3361,6 +3365,7 @@ struct FormatRoundDoubleImpl {
         return {std::make_shared<DataTypeFloat64>(), 
std::make_shared<vectorized::DataTypeInt32>()};
     }
 
+    template <bool is_const>
     static Status execute(FunctionContext* context, ColumnString* 
result_column,
                           const ColumnPtr col_ptr, ColumnPtr 
decimal_places_col_ptr,
                           size_t input_rows_count) {
@@ -3369,7 +3374,7 @@ struct FormatRoundDoubleImpl {
         const auto* data_column = assert_cast<const 
ColumnFloat64*>(col_ptr.get());
         // when scale is above 38, we will go here
         for (size_t i = 0; i < input_rows_count; i++) {
-            int32_t decimal_places = arg_column_data_2[i];
+            int32_t decimal_places = 
arg_column_data_2[index_check_const<is_const>(i)];
             if (decimal_places < 0) {
                 return Status::InvalidArgument(
                         "The second argument is {}, it can not be less than 
0.", decimal_places);
@@ -3390,6 +3395,7 @@ struct FormatRoundInt64Impl {
         return {std::make_shared<DataTypeInt64>(), 
std::make_shared<vectorized::DataTypeInt32>()};
     }
 
+    template <bool is_const>
     static Status execute(FunctionContext* context, ColumnString* 
result_column,
                           const ColumnPtr col_ptr, ColumnPtr 
decimal_places_col_ptr,
                           size_t input_rows_count) {
@@ -3397,7 +3403,7 @@ struct FormatRoundInt64Impl {
         const auto& arg_column_data_2 =
                 assert_cast<const 
ColumnInt32*>(decimal_places_col_ptr.get())->get_data();
         for (size_t i = 0; i < input_rows_count; i++) {
-            int32_t decimal_places = arg_column_data_2[i];
+            int32_t decimal_places = 
arg_column_data_2[index_check_const<is_const>(i)];
             if (decimal_places < 0) {
                 return Status::InvalidArgument(
                         "The second argument is {}, it can not be less than 
0.", decimal_places);
@@ -3417,6 +3423,7 @@ struct FormatRoundInt128Impl {
         return {std::make_shared<DataTypeInt128>(), 
std::make_shared<vectorized::DataTypeInt32>()};
     }
 
+    template <bool is_const>
     static Status execute(FunctionContext* context, ColumnString* 
result_column,
                           const ColumnPtr col_ptr, ColumnPtr 
decimal_places_col_ptr,
                           size_t input_rows_count) {
@@ -3427,7 +3434,7 @@ struct FormatRoundInt128Impl {
         // get "170,141,183,460,469,231,731,687,303,715,884,105,727.00" in 
doris,
         // see 
https://github.com/apache/doris/blob/788abf2d7c3c7c2d57487a9608e889e7662d5fb2/be/src/vec/data_types/data_type_number_base.cpp#L124
         for (size_t i = 0; i < input_rows_count; i++) {
-            int32_t decimal_places = arg_column_data_2[i];
+            int32_t decimal_places = 
arg_column_data_2[index_check_const<is_const>(i)];
             if (decimal_places < 0) {
                 return Status::InvalidArgument(
                         "The second argument is {}, it can not be less than 
0.", decimal_places);
@@ -3448,13 +3455,14 @@ struct FormatRoundDecimalImpl {
                 std::make_shared<vectorized::DataTypeInt32>()};
     }
 
+    template <bool is_const>
     static Status execute(FunctionContext* context, ColumnString* 
result_column, ColumnPtr col_ptr,
                           ColumnPtr decimal_places_col_ptr, size_t 
input_rows_count) {
         const auto& arg_column_data_2 =
                 assert_cast<const 
ColumnInt32*>(decimal_places_col_ptr.get())->get_data();
         if (auto* decimalv2_column = 
check_and_get_column<ColumnDecimal<Decimal128V2>>(*col_ptr)) {
             for (size_t i = 0; i < input_rows_count; i++) {
-                int32_t decimal_places = arg_column_data_2[i];
+                int32_t decimal_places = 
arg_column_data_2[index_check_const<is_const>(i)];
                 if (decimal_places < 0) {
                     return Status::InvalidArgument(
                             "The second argument is {}, it can not be less 
than 0.",
@@ -3475,7 +3483,7 @@ struct FormatRoundDecimalImpl {
                            
check_and_get_column<ColumnDecimal<Decimal32>>(*col_ptr)) {
             const UInt32 scale = decimal32_column->get_scale();
             for (size_t i = 0; i < input_rows_count; i++) {
-                int32_t decimal_places = arg_column_data_2[i];
+                int32_t decimal_places = 
arg_column_data_2[index_check_const<is_const>(i)];
                 if (decimal_places < 0) {
                     return Status::InvalidArgument(
                             "The second argument is {}, it can not be less 
than 0.",
@@ -3494,7 +3502,7 @@ struct FormatRoundDecimalImpl {
                            
check_and_get_column<ColumnDecimal<Decimal64>>(*col_ptr)) {
             const UInt32 scale = decimal64_column->get_scale();
             for (size_t i = 0; i < input_rows_count; i++) {
-                int32_t decimal_places = arg_column_data_2[i];
+                int32_t decimal_places = 
arg_column_data_2[index_check_const<is_const>(i)];
                 if (decimal_places < 0) {
                     return Status::InvalidArgument(
                             "The second argument is {}, it can not be less 
than 0.",
@@ -3513,7 +3521,7 @@ struct FormatRoundDecimalImpl {
                            
check_and_get_column<ColumnDecimal<Decimal128V3>>(*col_ptr)) {
             const UInt32 scale = decimal128_column->get_scale();
             for (size_t i = 0; i < input_rows_count; i++) {
-                int32_t decimal_places = arg_column_data_2[i];
+                int32_t decimal_places = 
arg_column_data_2[index_check_const<is_const>(i)];
                 if (decimal_places < 0) {
                     return Status::InvalidArgument(
                             "The second argument is {}, it can not be less 
than 0.",
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 42ce5b1ff28..aa9ccc5aa30 100644
Binary files 
a/regression-test/data/query_p0/sql_functions/math_functions/test_format_round.out
 and 
b/regression-test/data/query_p0/sql_functions/math_functions/test_format_round.out
 differ
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 dfd4a057a36..1af614f6aac 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
@@ -46,15 +46,16 @@ suite("test_format_round", "p0") {
         """
 
         sql """ INSERT INTO test_format_round VALUES
-                    (1, 123, 123456, 123455677788, 123456.1234567, 
123456.1234567);
+                    (1, 123, 123456, 123455677788, 123456.1234567, 
123456.1234567),
+                    (2, 123, 12313, 094720913, 434.1234567, 34.1234567);
             """
         qt_select_default """ SELECT * FROM test_format_round t ORDER BY 
user_id; """
 
-    order_qt_format_round_8 """ select format_round(int_col, 6) from 
test_format_round"""
-    order_qt_format_round_9 """ select format_round(bigint_col, 6) from 
test_format_round"""
-    order_qt_format_round_10 """ select format_round(largeint_col, 6) from 
test_format_round"""
-    order_qt_format_round_12 """ select format_round(double_col, 6) from 
test_format_round"""
-    order_qt_format_round_13 """ select format_round(decimal_col, 6) from 
test_format_round"""
+    order_qt_format_round_8 """ select format_round(int_col, 6) from 
test_format_round order by user_id"""
+    order_qt_format_round_9 """ select format_round(bigint_col, 6) from 
test_format_round order by user_id"""
+    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"""
 
     test {
         sql """select format_round(1234567.8910, -1) """


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

Reply via email to