Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[branch-1.2](bug) fix unexpected be core in string search function #31411

Merged
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
15 changes: 8 additions & 7 deletions be/src/vec/functions/functions_multi_string_position.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,26 +55,22 @@ class FunctionMultiStringPosition : public IFunction {
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 =
Expand All @@ -85,6 +81,11 @@ class FunctionMultiStringPosition : public IFunction {
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 "
Expand Down
17 changes: 9 additions & 8 deletions be/src/vec/functions/functions_multi_string_search.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,26 +58,22 @@ class FunctionsMultiStringSearch : public IFunction {
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 =
Expand All @@ -88,6 +84,11 @@ class FunctionsMultiStringSearch : public IFunction {
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 "
Expand Down Expand Up @@ -323,4 +324,4 @@ void register_function_multi_string_search(SimpleFunctionFactory& factory) {
factory.register_function<FunctionMultiMatchAny>();
}

} // namespace doris::vectorized
} // namespace doris::vectorized
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ public class FunctionCallExpr extends Expr {
.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();

static {
java.util.function.BiFunction<ArrayList<Expr>, Type, Type> sumRule = (children, returnType) -> {
Preconditions.checkArgument(children != null && children.size() > 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1290,6 +1290,12 @@ public static boolean isCastMatchAllowed(Function desc, Function candicate) {
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,16 @@ suite("test_multi_string_position") {
qt_select "select multi_search_all_positions('jnckhtjqwycyihuejibqmddrdxe', ['tajzx', 'vuddoylclxatcjvinusdwt', 'spxkhxvzsljkmnzpeubszjnhqczavgtqopxn', 'ckhtjqwycyi', 'xlbfzdxspldoes', 'u', 'czosfebeznt', 'gzhabdsuyreisxvyfrfrkq', 'yihuejibqmd', 'jqwycyihuejibqm', 'cfbvprgzx', 'hxu', 'vxbhrfpzacgd', 'afoaij', 'htjqwycyihu', 'httzbskqd'])"
qt_select "select multi_search_all_positions('dzejajvpoojdkqbnayahygidyrjmb', ['khwxxvtnqhobbvwgwkpusjlhlzifiuclycml', 'nzvuhtwdaivo', 'dkqbnayahygidyr', 'jajvpoo', 'j', 'wdtbvwmeqgyvetu', 'kqbn', 'idyrjmb', 'tsnxuxevsxrxpgpfdgrkhwqpkse', '', 'efsdgzuefhdzkmquxu', 'zejajvpoojdkqbnayahyg', 'ugwfuighbygrxyctop', 'fcbxzbdugc', 'dxmzzrcplob', 'ejaj', 'wmmupyxrylvawsyfccluiiene', 'ohzmsqhpzbafvbzqwzftbvftei'])"
qt_select "select multi_search_all_positions('ffaujlverosspbzaqefjzql', ['lvero', 'erossp', 'f', 'ujlverosspbz', 'btfimgklzzxlbkbuqyrmnud', 'osspb', 'muqexvtjuaar', 'f', 'bzaq', 'lprihswhwkdhqciqhfaowarn', 'ffaujlve', 'uhbbjrqjb', 'jlver', 'umucyhbbu', 'pjthtzmgxhvpbdphesnnztuu', 'xfqhfdfsbbazactpastzvzqudgk', 'lvovjfoatc', 'z', 'givejzhoqsd', ''])"

try {
sql "select multi_search_all_positions('ffaujlverosspbzaqefjzql', 'lvero, erossp, f, ujlverosspbz, btfimgklzzxlbkbuqyrmnud, osspb, muqexvtjuaar, f, bzaq, lprihswhwkdhqciqhfaowarn, ffaujlve, uhbbjrqjb, jlver, umucyhbbu, pjthtzmgxhvpbdphesnnztuu, xfqhfdfsbbazactpastzvzqudgk, lvovjfoatc, z, givejzhoqsd')"
} 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('ffaujlverosspbzaqefjzql', '[lvero, erossp, f, ujlverosspbz, btfimgklzzxlbkbuqyrmnud, osspb, muqexvtjuaar, f, bzaq, lprihswhwkdhqciqhfaowarn, ffaujlve, uhbbjrqjb, jlver, umucyhbbu, pjthtzmgxhvpbdphesnnztuu, xfqhfdfsbbazactpastzvzqudgk, lvovjfoatc, z, givejzhoqsd]')"
} catch (Exception ex) {
assert("${ex}".contains("errCode = 2, detailMessage = No matching function with signature: multi_search_all_positions"))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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'])"
}

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"))
}
}
Loading