From b8452812dffbf39104ca1f1c5053dc9951dfa23a Mon Sep 17 00:00:00 2001 From: zhangstar333 <87313068+zhangstar333@users.noreply.github.com> Date: Mon, 23 Oct 2023 15:47:12 +0800 Subject: [PATCH] [bug](function) fix regexp_extract_all can't handle empty str (#25717) --- be/src/vec/functions/function_regexp.cpp | 1 + .../string_functions/test_string_function_regexp.out | 6 ++++++ .../string_functions/test_string_function_regexp.groovy | 1 + 3 files changed, 8 insertions(+) diff --git a/be/src/vec/functions/function_regexp.cpp b/be/src/vec/functions/function_regexp.cpp index 1a38fe741e..4da133a6f5 100644 --- a/be/src/vec/functions/function_regexp.cpp +++ b/be/src/vec/functions/function_regexp.cpp @@ -361,6 +361,7 @@ struct RegexpExtractAllImpl { } if (res_matches.empty()) { + StringOP::push_empty_string(index_now, result_data, result_offset); return; } diff --git a/regression-test/data/query_p0/sql_functions/string_functions/test_string_function_regexp.out b/regression-test/data/query_p0/sql_functions/string_functions/test_string_function_regexp.out index 1684a03a15..133076ec13 100644 --- a/regression-test/data/query_p0/sql_functions/string_functions/test_string_function_regexp.out +++ b/regression-test/data/query_p0/sql_functions/string_functions/test_string_function_regexp.out @@ -67,6 +67,12 @@ d -- !sql -- ['ab','c','c','c'] +-- !sql_regexp_extract_all -- + 0 + 0 + 0 + 0 + -- !sql -- a-b-c diff --git a/regression-test/suites/query_p0/sql_functions/string_functions/test_string_function_regexp.groovy b/regression-test/suites/query_p0/sql_functions/string_functions/test_string_function_regexp.groovy index e3e04a5456..59414f5c1b 100644 --- a/regression-test/suites/query_p0/sql_functions/string_functions/test_string_function_regexp.groovy +++ b/regression-test/suites/query_p0/sql_functions/string_functions/test_string_function_regexp.groovy @@ -58,6 +58,7 @@ suite("test_string_function_regexp") { qt_sql "select regexp_extract_all('xxfs','f');" qt_sql "select regexp_extract_all('asdfg', '(z|x|c|)');" qt_sql "select regexp_extract_all('abcdfesscca', '(ab|c|)');" + qt_sql_regexp_extract_all "select regexp_extract_all('', '\"([^\"]+)\":'), length(regexp_extract_all('', '\"([^\"]+)\":')) from test_string_function_regexp;" qt_sql "SELECT regexp_replace('a b c', \" \", \"-\");" qt_sql "SELECT regexp_replace('a b c','(b)','<\\\\1>');"