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

zclll 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 ce7167e173c [fix](core)Fix format_round will be core when entering 
multiple lines (#53314)
ce7167e173c is described below

commit ce7167e173c1039c39d236d788ad8c6946f4767c
Author: Mryange <[email protected]>
AuthorDate: Wed Jul 16 15:48:18 2025 +0800

    [fix](core)Fix format_round will be core when entering multiple lines 
(#53314)
    
    There is a problem with the implementation of this function.
    unpack_if_const will only obtain the internal data column of the const
    column, but the internal size of the data is already 1.
---
 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 5e52f010700..38862c8fd2c 100644
--- a/be/src/vec/functions/function_string.h
+++ b/be/src/vec/functions/function_string.h
@@ -1590,11 +1590,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();
@@ -3122,8 +3126,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 std::string& 
value,
-                                 Int32 decimal_places) {
+static inline StringRef do_format_round(FunctionContext* context, const 
std::string& value,
+                                        Int32 decimal_places) {
     bool is_positive = (value[0] != '-');
     int32_t result_len =
             value.size() +
@@ -3301,6 +3305,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) {
@@ -3309,7 +3314,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);
@@ -3330,6 +3335,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) {
@@ -3337,7 +3343,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);
@@ -3357,6 +3363,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) {
@@ -3367,7 +3374,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);
@@ -3389,13 +3396,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<ColumnDecimal128V2>(*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.",
@@ -3415,7 +3423,7 @@ struct FormatRoundDecimalImpl {
         } else if (auto* decimal32_column = 
check_and_get_column<ColumnDecimal32>(*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.",
@@ -3433,7 +3441,7 @@ struct FormatRoundDecimalImpl {
         } else if (auto* decimal64_column = 
check_and_get_column<ColumnDecimal64>(*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.",
@@ -3451,7 +3459,7 @@ struct FormatRoundDecimalImpl {
         } else if (auto* decimal128_column = 
check_and_get_column<ColumnDecimal128V3>(*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