Skip to content

Commit c417c01

Browse files
committed
Simplify tests
1 parent cd7a468 commit c417c01

File tree

2 files changed

+20
-43
lines changed

2 files changed

+20
-43
lines changed

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

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -204,23 +204,7 @@ private static void checkFullTextQueryFunctions(LogicalPlan plan, Failures failu
204204
checkCommandsBeforeExpression(
205205
plan,
206206
condition,
207-
Match.class,
208-
lp -> (lp instanceof Limit == false) && (lp instanceof Aggregate == false),
209-
m -> "[" + m.functionName() + "] " + m.functionType(),
210-
failures
211-
);
212-
checkCommandsBeforeExpression(
213-
plan,
214-
condition,
215-
MultiMatch.class,
216-
lp -> (lp instanceof Limit == false) && (lp instanceof Aggregate == false),
217-
m -> "[" + m.functionName() + "] " + m.functionType(),
218-
failures
219-
);
220-
checkCommandsBeforeExpression(
221-
plan,
222-
condition,
223-
Term.class,
207+
FullTextFunction.class,
224208
lp -> (lp instanceof Limit == false) && (lp instanceof Aggregate == false),
225209
m -> "[" + m.functionName() + "] " + m.functionType(),
226210
failures

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

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1215,44 +1215,37 @@ public void testMatchInsideEval() throws Exception {
12151215
);
12161216
}
12171217

1218-
public void testMatchFunctionNotAllowedAfterCommands() throws Exception {
1219-
assertEquals(
1220-
"1:24: [MATCH] function cannot be used after LIMIT",
1221-
error("from test | limit 10 | where match(first_name, \"Anna\")")
1222-
);
1223-
assertEquals(
1224-
"1:47: [MATCH] function cannot be used after STATS",
1225-
error("from test | STATS c = AVG(salary) BY gender | where match(gender, \"F\")")
1226-
);
1218+
public void testFieldBasedFullTextFunctions() throws Exception {
1219+
testFieldBasedWithNonIndexedColumn("MATCH", "match(text, \"cat\")", "function");
1220+
testFieldBasedWithNonIndexedColumn(":", "text : \"cat\"", "operator");
1221+
testFieldBasedWithNonIndexedColumn("MultiMatch", "multi_match(\"cat\", text)", "function");
1222+
1223+
testFieldBasedFunctionNotAllowedAfterCommands("MATCH", "function", "match(first_name, \"Anna\")");
1224+
testFieldBasedFunctionNotAllowedAfterCommands(":", "operator", "first_name : \"Anna\"");
1225+
testFieldBasedFunctionNotAllowedAfterCommands("MultiMatch", "function", "multi_match(\"Anna\", first_name)");
1226+
testFieldBasedFunctionNotAllowedAfterCommands("KNN", "function", "knn(vector, [1, 2, 3])");
12271227
}
12281228

1229-
public void testMatchFunctionAndOperatorHaveCorrectErrorMessages() throws Exception {
1230-
assertEquals(
1231-
"1:24: [MATCH] function cannot be used after LIMIT",
1232-
error("from test | limit 10 | where match(first_name, \"Anna\")")
1229+
public void testFieldBasedFunctionNotAllowedAfterCommands(String functionName, String functionType, String functionInvocation) throws Exception {
1230+
assertThat(
1231+
error("from test | limit 10 | where " + functionInvocation),
1232+
containsString("[" + functionName + "] " + functionType + " cannot be used after LIMIT")
12331233
);
1234-
assertEquals(
1235-
"1:24: [MATCH] function cannot be used after LIMIT",
1236-
error("from test | limit 10 | where match ( first_name, \"Anna\" ) ")
1234+
String fieldName = "KNN".equals(functionName) ? "vector" : "first_name";
1235+
assertThat(
1236+
error("from test | STATS c = COUNT(emp_no) BY " + fieldName + " | where " + functionInvocation),
1237+
containsString("[" + functionName + "] " + functionType + " cannot be used after STATS")
12371238
);
1238-
assertEquals("1:24: [:] operator cannot be used after LIMIT", error("from test | limit 10 | where first_name:\"Anna\""));
1239-
assertEquals("1:24: [:] operator cannot be used after LIMIT", error("from test | limit 10 | where first_name : \"Anna\""));
1240-
}
1241-
1242-
public void testFieldBasedFullTextFunctions() {
1243-
testFieldBasedWithNonIndexedColumn("MATCH", " match(text, \"cat\")", "function");
1244-
testFieldBasedWithNonIndexedColumn(":", " text : \"cat\"", "operator");
1245-
testFieldBasedWithNonIndexedColumn("MultiMatch", " multi_match(\"cat\", text)", "function");
12461239
}
12471240

12481241
// These should pass eventually once we lift some restrictions on match function
12491242
public void testFieldBasedWithNonIndexedColumn(String functionName, String functionInvocation, String functionType) {
12501243
assertThat(
1251-
error("from test | eval text = substring(first_name, 1) | where" + functionInvocation),
1244+
error("from test | eval text = substring(first_name, 1) | where " + functionInvocation),
12521245
containsString("[" + functionName + "] " + functionType + " cannot operate on [text], which is not a field from an index mapping")
12531246
);
12541247
assertThat(
1255-
error("from test | eval text=concat(first_name, last_name) | where" + functionInvocation),
1248+
error("from test | eval text=concat(first_name, last_name) | where " + functionInvocation),
12561249
containsString("[" + functionName + "] " + functionType + " cannot operate on [text], which is not a field from an index mapping")
12571250
);
12581251
var keywordInvocation = functionInvocation.replace("text", "text::keyword");

0 commit comments

Comments
 (0)