Skip to content

Commit ff95fe7

Browse files
More verifier tests
1 parent 98ad8b0 commit ff95fe7

File tree

2 files changed

+85
-0
lines changed

2 files changed

+85
-0
lines changed

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/fulltext/FullTextFunction.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,14 @@ private static void checkFullTextQueryFunctions(LogicalPlan plan, Failures failu
200200
m -> "[" + m.functionName() + "] " + m.functionType(),
201201
failures
202202
);
203+
checkCommandsBeforeExpression(
204+
plan,
205+
condition,
206+
MultiMatch.class,
207+
lp -> (lp instanceof Limit == false) && (lp instanceof Aggregate == false),
208+
m -> "[" + m.functionName() + "] " + m.functionType(),
209+
failures
210+
);
203211
checkCommandsBeforeExpression(
204212
plan,
205213
condition,

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/analysis/VerifierTests.java

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1463,6 +1463,7 @@ private void checkWithDisjunctions(String functionName, String functionInvocatio
14631463

14641464
public void testFullTextFunctionsDisjunctions() {
14651465
checkWithFullTextFunctionsDisjunctions("match(last_name, \"Smith\")");
1466+
checkWithFullTextFunctionsDisjunctions("multi_match(\"Smith\", first_name, last_name)");
14661467
checkWithFullTextFunctionsDisjunctions("last_name : \"Smith\"");
14671468
checkWithFullTextFunctionsDisjunctions("qstr(\"last_name: Smith\")");
14681469
checkWithFullTextFunctionsDisjunctions("kql(\"last_name: Smith\")");
@@ -2404,6 +2405,82 @@ public void testMultiMatchOptions() {
24042405
);
24052406
}
24062407

2408+
public void testMultiMatchFunctionIsNotNullable() {
2409+
assertEquals(
2410+
"1:62: [MultiMatch] function cannot operate on [text::keyword], which is not a field from an index mapping",
2411+
error("row n = null | eval text = n + 5 | where multi_match(\"Anna\", text::keyword)")
2412+
);
2413+
}
2414+
2415+
public void testMultiMatchWithNonIndexedColumnCurrentlyUnsupported() {
2416+
assertEquals(
2417+
"1:78: [MultiMatch] function cannot operate on [initial], which is not a field from an index mapping",
2418+
error("from test | eval initial = substring(first_name, 1) | where multi_match(\"A\", initial)")
2419+
);
2420+
assertEquals(
2421+
"1:80: [MultiMatch] function cannot operate on [text], which is not a field from an index mapping",
2422+
error("from test | eval text=concat(first_name, last_name) | where multi_match(\"cat\", text)")
2423+
);
2424+
}
2425+
2426+
public void testMultiMatchFunctionNotAllowedAfterCommands() throws Exception {
2427+
assertEquals(
2428+
"1:24: [MultiMatch] function cannot be used after LIMIT",
2429+
error("from test | limit 10 | where multi_match(\"Anna\", first_name)")
2430+
);
2431+
assertEquals(
2432+
"1:47: [MultiMatch] function cannot be used after STATS",
2433+
error("from test | STATS c = AVG(salary) BY gender | where multi_match(\"F\", gender)")
2434+
);
2435+
}
2436+
2437+
public void testMultiMatchFunctionWithDisjunctions() {
2438+
checkWithDisjunctions("MultiMatch", "multi_match(\"Anna\", first_name, last_name)", "function");
2439+
}
2440+
2441+
public void testMultiMatchFunctionWithNonBooleanFunctions() {
2442+
checkFullTextFunctionsWithNonBooleanFunctions("MultiMatch", "multi_match(\"Anna\", first_name, last_name)", "function");
2443+
}
2444+
2445+
2446+
public void testMultiMatchFunctionArgNotConstant() throws Exception {
2447+
assertEquals(
2448+
"1:19: second argument of [match(first_name, first_name)] must be a constant, received [first_name]",
2449+
error("from test | where match(first_name, first_name)")
2450+
);
2451+
assertEquals(
2452+
"1:59: second argument of [match(first_name, query)] must be a constant, received [query]",
2453+
error("from test | eval query = concat(\"first\", \" name\") | where match(first_name, query)")
2454+
);
2455+
// Other value types are tested in QueryStringFunctionTests
2456+
}
2457+
2458+
// Should pass eventually once we lift some restrictions on the multi-match function.
2459+
public void testMultiMatchFunctionCurrentlyUnsupportedBehaviour() throws Exception {
2460+
assertEquals(
2461+
"1:82: Unknown column [first_name]\nline 1:94: Unknown column [last_name]",
2462+
error("from test | stats max_salary = max(salary) by emp_no | where multi_match(\"Anna\", first_name, last_name)")
2463+
);
2464+
}
2465+
2466+
public void testMultiMatchFunctionNullArgs() throws Exception {
2467+
assertEquals(
2468+
"1:19: first argument of [multi_match(\"query\", null)] cannot be null, received [null]",
2469+
error("from test | where multi_match(\"query\", null)")
2470+
);
2471+
assertEquals(
2472+
"1:19: first argument of [multi_match(null, first_name)] cannot be null, received [null]",
2473+
error("from test | where multi_match(null, first_name)")
2474+
);
2475+
}
2476+
2477+
public void testMultiMatchTargetsExistingField() throws Exception {
2478+
assertEquals(
2479+
"1:53: Unknown column [first_name]\nline 1:65: Unknown column [last_name]",
2480+
error("from test | keep emp_no | where multi_match(\"Anna\", first_name, last_name)")
2481+
);
2482+
}
2483+
24072484
public void testInsistNotOnTopOfFrom() {
24082485
assumeTrue("requires snapshot builds", Build.current().isSnapshot());
24092486

0 commit comments

Comments
 (0)