From cc85cb4ede8da523b6db9a96d474820b83b862f6 Mon Sep 17 00:00:00 2001 From: zhaochangle Date: Tue, 14 May 2024 09:09:22 +0800 Subject: [PATCH] 1 --- 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 a57e352f2092fe..1406e89cb4e148 100644 --- a/be/src/vec/functions/function_string.h +++ b/be/src/vec/functions/function_string.h @@ -1711,9 +1711,9 @@ class FunctionStringPad : public IFunction { 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 5fc247c7d7f326..7fe3d4b4e5a898 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 630a2d1805ba0a..070e7479726d65 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); """ }