Skip to content

Commit 9ef72e7

Browse files
committed
Use a regex to detect correctly match function
1 parent a0bc3c6 commit 9ef72e7

File tree

2 files changed

+14
-1
lines changed
  • x-pack/plugin/esql/src
    • main/java/org/elasticsearch/xpack/esql/expression/function/fulltext
    • test/java/org/elasticsearch/xpack/esql/analysis

2 files changed

+14
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public String functionName() {
132132

133133
private boolean isOperator() {
134134
if (isOperator == null) {
135-
isOperator = source().text().toUpperCase(Locale.ROOT).startsWith(super.functionName()) == false;
135+
isOperator = source().text().toUpperCase(Locale.ROOT).matches("^" + super.functionName() + "\\s*\\(.*\\)") == false;
136136
}
137137
return isOperator;
138138
}

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1145,6 +1145,19 @@ public void testMatchFunctionNotAllowedAfterCommands() throws Exception {
11451145
);
11461146
}
11471147

1148+
public void testMatchFunctionAndOperatorHaveCorrectErrorMessages() throws Exception {
1149+
assertEquals(
1150+
"1:24: [MATCH] function cannot be used after LIMIT",
1151+
error("from test | limit 10 | where match(first_name, \"Anna\")")
1152+
);
1153+
assertEquals(
1154+
"1:24: [MATCH] function cannot be used after LIMIT",
1155+
error("from test | limit 10 | where match ( first_name, \"Anna\" ) ")
1156+
);
1157+
assertEquals("1:24: [:] operator cannot be used after LIMIT", error("from test | limit 10 | where first_name:\"Anna\""));
1158+
assertEquals("1:24: [:] operator cannot be used after LIMIT", error("from test | limit 10 | where first_name : \"Anna\""));
1159+
}
1160+
11481161
public void testQueryStringFunctionsNotAllowedAfterCommands() throws Exception {
11491162
// Source commands
11501163
assertEquals("1:13: [QSTR] function cannot be used after SHOW", error("show info | where qstr(\"8.16.0\")"));

0 commit comments

Comments
 (0)