From 9ef72e7ce3e87e0e2e0c3dae5be0ffb5f2c6aa87 Mon Sep 17 00:00:00 2001 From: carlosdelest Date: Tue, 5 Nov 2024 10:53:45 +0100 Subject: [PATCH] Use a regex to detect correctly match function --- .../esql/expression/function/fulltext/Match.java | 2 +- .../xpack/esql/analysis/VerifierTests.java | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/fulltext/Match.java b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/fulltext/Match.java index b17fc74e4236e..522a5574c0053 100644 --- a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/fulltext/Match.java +++ b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/fulltext/Match.java @@ -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; } diff --git a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/analysis/VerifierTests.java b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/analysis/VerifierTests.java index 93feec922f887..97628863ed046 100644 --- a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/analysis/VerifierTests.java +++ b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/analysis/VerifierTests.java @@ -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\")"));