From 9091ffd7a19992e9ff0797028af1064a57b9bc25 Mon Sep 17 00:00:00 2001 From: skylhd Date: Wed, 10 Jan 2024 15:42:41 +0000 Subject: [PATCH] [CP][BUGFIX] fix lrpad mysql pad len zero --- src/sql/engine/expr/ob_expr_lrpad.cpp | 6 +-- .../static_engine/r/mysql/expr_pad.result | 43 ++++++++++++++++++- .../test_suite/static_engine/t/expr_pad.test | 13 ++++++ 3 files changed, 58 insertions(+), 4 deletions(-) diff --git a/src/sql/engine/expr/ob_expr_lrpad.cpp b/src/sql/engine/expr/ob_expr_lrpad.cpp index 62d7929d23..fa46e1c9ce 100644 --- a/src/sql/engine/expr/ob_expr_lrpad.cpp +++ b/src/sql/engine/expr/ob_expr_lrpad.cpp @@ -552,11 +552,11 @@ int ObExprBaseLRpad::calc_mysql_inner(const LRpadType pad_type, // only substr needed result_size = ObCharset::charpos(cs_type, str_text.ptr(), str_text.length(), int_len); res.set_string(ObString(result_size, str_text.ptr())); + } else if (str_pad.length() == 0) { + res.set_null(); // mysql 5.7 return null while mysql 8.0 return empty string } else { has_set_to_lob_locator = true; - if (str_pad.length() == 0) { - res.set_string(ObString::make_empty_string()); - } else if (OB_FAIL(get_padding_info_mysql(cs_type, str_text, int_len, str_pad, + if (OB_FAIL(get_padding_info_mysql(cs_type, str_text, int_len, str_pad, max_result_size, repeat_count, prefix_size, result_size))) { LOG_WARN("Failed to get padding info", K(ret), K(str_text), K(int_len), K(str_pad), K(max_result_size)); diff --git a/tools/deploy/mysql_test/test_suite/static_engine/r/mysql/expr_pad.result b/tools/deploy/mysql_test/test_suite/static_engine/r/mysql/expr_pad.result index 3e0816bfcb..36c01f16f4 100644 --- a/tools/deploy/mysql_test/test_suite/static_engine/r/mysql/expr_pad.result +++ b/tools/deploy/mysql_test/test_suite/static_engine/r/mysql/expr_pad.result @@ -6124,7 +6124,7 @@ select lpad('a', 5, ''); +------------------+ | lpad('a', 5, '') | +------------------+ -| | +| NULL | +------------------+ select lpad(NULL, 5, 'a'); +--------------------+ @@ -6283,3 +6283,44 @@ select rpad('a', 8, '阿斯'), length(rpad('a', 8, '阿斯')) from dual; | a阿斯阿斯阿斯阿 | 22 | +------------------------+--------------------------------+ +drop table if exists t1; +create table t1(c1 int); +insert into t1 values(18); +select lpad("", cast(c1 as decimal), "") from t1; ++-----------------------------------+ +| lpad("", cast(c1 as decimal), "") | ++-----------------------------------+ +| NULL | ++-----------------------------------+ +select lpad("123", cast(c1 as decimal), "") from t1; ++--------------------------------------+ +| lpad("123", cast(c1 as decimal), "") | ++--------------------------------------+ +| NULL | ++--------------------------------------+ +select lpad("", cast(c1 as decimal), "123") from t1; ++--------------------------------------+ +| lpad("", cast(c1 as decimal), "123") | ++--------------------------------------+ +| 123123123123123123 | ++--------------------------------------+ +select rpad("", cast(c1 as decimal), "") from t1; ++-----------------------------------+ +| rpad("", cast(c1 as decimal), "") | ++-----------------------------------+ +| NULL | ++-----------------------------------+ +select rpad("123", cast(c1 as decimal), "") from t1; ++--------------------------------------+ +| rpad("123", cast(c1 as decimal), "") | ++--------------------------------------+ +| NULL | ++--------------------------------------+ +select rpad("", cast(c1 as decimal), "123") from t1; ++--------------------------------------+ +| rpad("", cast(c1 as decimal), "123") | ++--------------------------------------+ +| 123123123123123123 | ++--------------------------------------+ +drop table t1; + diff --git a/tools/deploy/mysql_test/test_suite/static_engine/t/expr_pad.test b/tools/deploy/mysql_test/test_suite/static_engine/t/expr_pad.test index 97e2b49f1d..4f15d69d65 100644 --- a/tools/deploy/mysql_test/test_suite/static_engine/t/expr_pad.test +++ b/tools/deploy/mysql_test/test_suite/static_engine/t/expr_pad.test @@ -116,4 +116,17 @@ select rpad('a', 6, '阿斯'), length(rpad('a', 6, '阿斯')) from dual; select rpad('a', 7, '阿斯'), length(rpad('a', 7, '阿斯')) from dual; select rpad('a', 8, '阿斯'), length(rpad('a', 8, '阿斯')) from dual; +--disable_warnings +drop table if exists t1; +--enable_warnings +create table t1(c1 int); +insert into t1 values(18); +select lpad("", cast(c1 as decimal), "") from t1; +select lpad("123", cast(c1 as decimal), "") from t1; +select lpad("", cast(c1 as decimal), "123") from t1; +select rpad("", cast(c1 as decimal), "") from t1; +select rpad("123", cast(c1 as decimal), "") from t1; +select rpad("", cast(c1 as decimal), "123") from t1; +drop table t1; + --sleep 2