From d5ab2787ba77e694be4a580c6cda4541bb5bb367 Mon Sep 17 00:00:00 2001 From: zclllyybb Date: Tue, 14 May 2024 19:53:44 +0800 Subject: [PATCH] [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 +-- .../test_string_pad_function.out | 30 +++++++++++++++++++ .../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 515f9ad11a..61339bbd9c 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 5fc247c7d7..7fe3d4b4e5 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 630a2d1805..070e747972 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); """ }