Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions be/src/vec/functions/function_string.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
30 changes: 30 additions & 0 deletions regression-test/data/correctness_p0/test_string_pad_function.out
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,33 @@
\N
10:00

-- !rpad1 --


-- !rpad2 --


-- !rpad3 --
\N

-- !rpad4 --
\N

-- !rpad5 --
\N

-- !lpad1 --


-- !lpad2 --


-- !lpad3 --
\N

-- !lpad4 --
\N

-- !lpad5 --
\N

Original file line number Diff line number Diff line change
Expand Up @@ -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); """
}