This is an automated email from the ASF dual-hosted git repository. xuyang pushed a commit to branch branch-2.0 in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-2.0 by this push: new 9beaab24ecc [fix](branch20) fix unexpected be core in string search function (#31460) 9beaab24ecc is described below commit 9beaab24ecc41592925e029188fda73aa987384c Author: xy720 <22125576+xy...@users.noreply.github.com> AuthorDate: Tue Feb 27 17:29:22 2024 +0800 [fix](branch20) fix unexpected be core in string search function (#31460) cherry-pick: #31312 --- .../functions/functions_multi_string_position.cpp | 15 +++++++------ .../functions/functions_multi_string_search.cpp | 15 +++++++------ .../apache/doris/analysis/FunctionCallExpr.java | 3 +++ .../java/org/apache/doris/catalog/FunctionSet.java | 6 +++++ .../test_multi_string_position.groovy | 24 ++++++++++++++++++++ .../test_multi_string_search.groovy | 26 +++++++++++++++++++++- 6 files changed, 74 insertions(+), 15 deletions(-) diff --git a/be/src/vec/functions/functions_multi_string_position.cpp b/be/src/vec/functions/functions_multi_string_position.cpp index f3230325638..47597145913 100644 --- a/be/src/vec/functions/functions_multi_string_position.cpp +++ b/be/src/vec/functions/functions_multi_string_position.cpp @@ -80,26 +80,22 @@ public: Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments, size_t result, size_t input_rows_count) override { auto haystack_column = block.get_by_position(arguments[0]).column; - auto haystack_ptr = haystack_column; - auto needles_column = block.get_by_position(arguments[1]).column; - auto needles_ptr = needles_column; bool haystack_nullable = false; bool needles_nullable = false; if (haystack_column->is_nullable()) { - haystack_ptr = check_and_get_column<ColumnNullable>(haystack_column.get()) - ->get_nested_column_ptr(); haystack_nullable = true; } if (needles_column->is_nullable()) { - needles_ptr = check_and_get_column<ColumnNullable>(needles_column.get()) - ->get_nested_column_ptr(); needles_nullable = true; } + auto haystack_ptr = remove_nullable(haystack_column); + auto needles_ptr = remove_nullable(needles_column); + const ColumnString* col_haystack_vector = check_and_get_column<ColumnString>(&*haystack_ptr); const ColumnConst* col_haystack_const = @@ -110,6 +106,11 @@ public: const ColumnConst* col_needles_const = check_and_get_column_const<ColumnArray>(needles_ptr.get()); + if (!col_needles_const && !col_needles_vector) + return Status::InvalidArgument( + "function '{}' encountered unsupported needles column, found {}", name, + needles_column->get_name()); + if (col_haystack_const && col_needles_vector) { return Status::InvalidArgument( "function '{}' doesn't support search with non-constant needles " diff --git a/be/src/vec/functions/functions_multi_string_search.cpp b/be/src/vec/functions/functions_multi_string_search.cpp index bc7b68dea59..bcd5ad0a5d5 100644 --- a/be/src/vec/functions/functions_multi_string_search.cpp +++ b/be/src/vec/functions/functions_multi_string_search.cpp @@ -78,26 +78,22 @@ public: Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments, size_t result, size_t input_rows_count) override { auto haystack_column = block.get_by_position(arguments[0]).column; - auto haystack_ptr = haystack_column; - auto needles_column = block.get_by_position(arguments[1]).column; - auto needles_ptr = needles_column; bool haystack_nullable = false; bool needles_nullable = false; if (haystack_column->is_nullable()) { - haystack_ptr = check_and_get_column<ColumnNullable>(haystack_column.get()) - ->get_nested_column_ptr(); haystack_nullable = true; } if (needles_column->is_nullable()) { - needles_ptr = check_and_get_column<ColumnNullable>(needles_column.get()) - ->get_nested_column_ptr(); needles_nullable = true; } + auto haystack_ptr = remove_nullable(haystack_column); + auto needles_ptr = remove_nullable(needles_column); + const ColumnString* col_haystack_vector = check_and_get_column<ColumnString>(&*haystack_ptr); const ColumnConst* col_haystack_const = @@ -108,6 +104,11 @@ public: const ColumnConst* col_needles_const = check_and_get_column_const<ColumnArray>(needles_ptr.get()); + if (!col_needles_const && !col_needles_vector) + return Status::InvalidArgument( + "function '{}' encountered unsupported needles column, found {}", name, + needles_column->get_name()); + if (col_haystack_const && col_needles_vector) return Status::InvalidArgument( "function '{}' doesn't support search with non-constant needles " diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/FunctionCallExpr.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/FunctionCallExpr.java index 9f607ca7311..2e8f443f6ba 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/FunctionCallExpr.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/FunctionCallExpr.java @@ -81,6 +81,9 @@ public class FunctionCallExpr extends Expr { String.CASE_INSENSITIVE_ORDER) .add("round").add("round_bankers").add("ceil").add("floor") .add("truncate").add("dround").add("dceil").add("dfloor").build(); + public static final ImmutableSet<String> STRING_SEARCH_FUNCTION_SET = new ImmutableSortedSet.Builder( + String.CASE_INSENSITIVE_ORDER) + .add("multi_search_all_positions").add("multi_match_any").build(); private final AtomicBoolean addOnce = new AtomicBoolean(false); diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/FunctionSet.java b/fe/fe-core/src/main/java/org/apache/doris/catalog/FunctionSet.java index dc0a43c6265..99ab159f25d 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/catalog/FunctionSet.java +++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/FunctionSet.java @@ -501,6 +501,12 @@ public class FunctionSet<T> { return false; } } + if (FunctionCallExpr.STRING_SEARCH_FUNCTION_SET.contains(desc.functionName())) { + if (descArgTypes[1].isStringType() && candicateArgTypes[1].isArrayType()) { + // The needles arg of search functions should not be allowed to cast from string. + return false; + } + } // If set `roundPreciseDecimalV2Value`, only use decimalv3 as target type to execute round function if (ConnectContext.get() != null && ConnectContext.get().getSessionVariable().roundPreciseDecimalV2Value diff --git a/regression-test/suites/query_p0/sql_functions/search_functions/test_multi_string_position.groovy b/regression-test/suites/query_p0/sql_functions/search_functions/test_multi_string_position.groovy index f6a8aa110e9..1c82fc7c6e9 100644 --- a/regression-test/suites/query_p0/sql_functions/search_functions/test_multi_string_position.groovy +++ b/regression-test/suites/query_p0/sql_functions/search_functions/test_multi_string_position.groovy @@ -54,4 +54,28 @@ suite("test_multi_string_position") { qt_select3 "select multi_search_all_positions('mpswgtljbbrmivkcglamemayfn', ['', 'm', 'saejhpnfgfq', 'rzanrkdssmmkanqjpfi', 'oputeneprgoowg', 'mp', '', '', 'wgtljbbrmivkcglamemay', 'cbpthtrgrmgfypizi', 'tl', 'tlj', 'xuhs', 'brmivkcglamemayfn', '', 'gtljb'])" qt_select4 "select multi_search_all_positions('arbphzbbecypbzsqsljurtddve', ['arbphzb', 'mnrboimjfijnti', 'cikcrd', 'becypbz', 'z', 'uocmqgnczhdcrvtqrnaxdxjjlhakoszuwc', 'bbe', '', 'bp', 'yhltnexlpdijkdzt', 'jkwjmrckvgmccmmrolqvy', 'vdxmicjmfbtsbqqmqcgtnrvdgaucsgspwg', 'witlfqwvhmmyjrnrzttrikhhsrd', 'pbzsqsljurt'])" qt_select5 "select multi_search_all_positions('aizovxqpzcbbxuhwtiaaqhdqjdei', ['qpzcbbxuhw', 'jugrpglqbm', 'dspwhzpyjohhtizegrnswhjfpdz', 'pzcbbxuh', 'vayzeszlycke', 'i', 'gvrontcpqavsjxtjwzgwxugiyhkhmhq', 'gyzmeroxztgaurmrqwtmsxcqnxaezuoapatvu', 'xqpzc', 'mjiswsvlvlpqrhhptqq', 'iz', 'hmzjxxfjsvcvdpqwtrdrp', 'zovxqpzcbbxuhwtia', 'ai'])" + + try { + sql "select multi_search_all_positions(content, 'hello') from ${table_name} order by col1" + } catch (Exception ex) { + assert("${ex}".contains("errCode = 2, detailMessage = No matching function with signature: multi_search_all_positions")) + } + + try { + sql "select multi_search_all_positions(content, 'hello, !, world, Hello, World') from ${table_name} order by col1" + } catch (Exception ex) { + assert("${ex}".contains("errCode = 2, detailMessage = No matching function with signature: multi_search_all_positions")) + } + + try { + sql "select multi_search_all_positions(content, '[hello]') from ${table_name} order by col1" + } catch (Exception ex) { + assert("${ex}".contains("errCode = 2, detailMessage = No matching function with signature: multi_search_all_positions")) + } + + try { + sql "select multi_search_all_positions(content, '[hello, !, world, Hello, World]') from ${table_name} order by col1" + } catch (Exception ex) { + assert("${ex}".contains("errCode = 2, detailMessage = No matching function with signature: multi_search_all_positions")) + } } diff --git a/regression-test/suites/query_p0/sql_functions/search_functions/test_multi_string_search.groovy b/regression-test/suites/query_p0/sql_functions/search_functions/test_multi_string_search.groovy index 5a3229ce361..3a0a9b061fe 100644 --- a/regression-test/suites/query_p0/sql_functions/search_functions/test_multi_string_search.groovy +++ b/regression-test/suites/query_p0/sql_functions/search_functions/test_multi_string_search.groovy @@ -71,4 +71,28 @@ suite("test_multi_string_search") { qt_select "select multi_match_any('ldrzgttlqaphekkkdukgngl', ['gttlqaphekkkdukgn', 'ekkkd', 'gttlqaphe', 'qaphek', 'h', 'kdu', 'he', 'phek', '', 'drzgttlqaphekkkd'])" qt_select "select multi_match_any('ololo', ['ololo', 'ololo', 'ololo'])" qt_select "select multi_match_any('khljxzxlpcrxpkrfybbfk', ['k'])" -} \ No newline at end of file + + try { + sql "select multi_match_any(content, 'hello') from ${table_name} order by col1" + } catch (Exception ex) { + assert("${ex}".contains("errCode = 2, detailMessage = No matching function with signature: multi_match_any")) + } + + try { + sql "select multi_match_any(content, 'hello, !, world, Hello, World') from ${table_name} order by col1" + } catch (Exception ex) { + assert("${ex}".contains("errCode = 2, detailMessage = No matching function with signature: multi_match_any")) + } + + try { + sql "select multi_match_any(content, '[hello]') from ${table_name} order by col1" + } catch (Exception ex) { + assert("${ex}".contains("errCode = 2, detailMessage = No matching function with signature: multi_match_any")) + } + + try { + sql "select multi_match_any(content, '[hello, !, world, Hello, World]') from ${table_name} order by col1" + } catch (Exception ex) { + assert("${ex}".contains("errCode = 2, detailMessage = No matching function with signature: multi_match_any")) + } +} --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org