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

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

commit d5ab2787ba77e694be4a580c6cda4541bb5bb367
Author: zclllyybb <[email protected]>
AuthorDate: Tue May 14 19:53:44 2024 +0800

    [Fix](function) fix pad functions behaviour of empty pad string (#34796)
    
    fix pad functions behaviour of empty pad string
---
 be/src/vec/functions/function_string.h             |  4 +--
 .../correctness_p0/test_string_pad_function.out    | 30 ++++++++++++++++++++++
 .../correctness_p0/test_string_pad_function.groovy | 11 ++++++++
 3 files changed, 43 insertions(+), 2 deletions(-)

diff --git a/be/src/vec/functions/function_string.h 
b/be/src/vec/functions/function_string.h
index 515f9ad11ac..61339bbd9cf 100644
--- a/be/src/vec/functions/function_string.h
+++ b/be/src/vec/functions/function_string.h
@@ -1710,9 +1710,9 @@ public:
                                                 res_chars, res_offsets);
                     continue;
                 }
+
+                // make compatible with mysql. return empty string if pad is 
empty
                 if (pad_char_size == 0) {
-                    // return NULL when the string to be paded is missing
-                    null_map_data[i] = true;
                     StringOP::push_empty_string(i, res_chars, res_offsets);
                     continue;
                 }
diff --git a/regression-test/data/correctness_p0/test_string_pad_function.out 
b/regression-test/data/correctness_p0/test_string_pad_function.out
index 5fc247c7d7f..7fe3d4b4e5a 100644
--- a/regression-test/data/correctness_p0/test_string_pad_function.out
+++ b/regression-test/data/correctness_p0/test_string_pad_function.out
@@ -7,3 +7,33 @@
 \N
 10:00
 
+-- !rpad1 --
+
+
+-- !rpad2 --
+
+
+-- !rpad3 --
+\N
+
+-- !rpad4 --
+\N
+
+-- !rpad5 --
+\N
+
+-- !lpad1 --
+
+
+-- !lpad2 --
+
+
+-- !lpad3 --
+\N
+
+-- !lpad4 --
+\N
+
+-- !lpad5 --
+\N
+
diff --git 
a/regression-test/suites/correctness_p0/test_string_pad_function.groovy 
b/regression-test/suites/correctness_p0/test_string_pad_function.groovy
index 630a2d1805b..070e7479726 100644
--- a/regression-test/suites/correctness_p0/test_string_pad_function.groovy
+++ b/regression-test/suites/correctness_p0/test_string_pad_function.groovy
@@ -43,4 +43,15 @@ suite("test_string_pad_function") {
     qt_select_rpad """
         select CASE WHEN table_pad.a = 1 THEN CONCAT(RPAD(b, 2, 0), ':00') END 
result from table_pad order by result;
     """
+
+    qt_rpad1 """ SELECT rpad("", 5, ""); """
+    qt_rpad2 """ SELECT rpad("123", 5, ""); """
+    qt_rpad3 """ SELECT rpad("123", -1, ""); """
+    qt_rpad4 """ SELECT rpad(NULL, 1, ""); """
+    qt_rpad5 """ SELECT rpad("123", 0, NULL); """
+    qt_lpad1 """ SELECT lpad("", 5, ""); """
+    qt_lpad2 """ SELECT lpad("123", 5, ""); """
+    qt_lpad3 """ SELECT lpad("123", -1, ""); """
+    qt_lpad4 """ SELECT lpad(NULL, 0, ""); """
+    qt_lpad5 """ SELECT lpad("123", 2, NULL); """
 }


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

Reply via email to