Skip to content

Commit

Permalink
Use a regex to detect correctly match function
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosdelest committed Nov 5, 2024
1 parent a0bc3c6 commit 9ef72e7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public String functionName() {

private boolean isOperator() {
if (isOperator == null) {
isOperator = source().text().toUpperCase(Locale.ROOT).startsWith(super.functionName()) == false;
isOperator = source().text().toUpperCase(Locale.ROOT).matches("^" + super.functionName() + "\\s*\\(.*\\)") == false;
}
return isOperator;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1145,6 +1145,19 @@ public void testMatchFunctionNotAllowedAfterCommands() throws Exception {
);
}

public void testMatchFunctionAndOperatorHaveCorrectErrorMessages() throws Exception {
assertEquals(
"1:24: [MATCH] function cannot be used after LIMIT",
error("from test | limit 10 | where match(first_name, \"Anna\")")
);
assertEquals(
"1:24: [MATCH] function cannot be used after LIMIT",
error("from test | limit 10 | where match ( first_name, \"Anna\" ) ")
);
assertEquals("1:24: [:] operator cannot be used after LIMIT", error("from test | limit 10 | where first_name:\"Anna\""));
assertEquals("1:24: [:] operator cannot be used after LIMIT", error("from test | limit 10 | where first_name : \"Anna\""));
}

public void testQueryStringFunctionsNotAllowedAfterCommands() throws Exception {
// Source commands
assertEquals("1:13: [QSTR] function cannot be used after SHOW", error("show info | where qstr(\"8.16.0\")"));
Expand Down

0 comments on commit 9ef72e7

Please sign in to comment.