From e3427f00aea2470bf59489d32462e8b863d5501a Mon Sep 17 00:00:00 2001 From: carlosdelest Date: Mon, 16 Sep 2024 10:06:14 +0200 Subject: [PATCH] Add query string parsing errors tests --- .../esql/plugin/QueryStringFunctionIT.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/x-pack/plugin/esql/src/internalClusterTest/java/org/elasticsearch/xpack/esql/plugin/QueryStringFunctionIT.java b/x-pack/plugin/esql/src/internalClusterTest/java/org/elasticsearch/xpack/esql/plugin/QueryStringFunctionIT.java index 5b036654e80cf..e6f11ca1f44d2 100644 --- a/x-pack/plugin/esql/src/internalClusterTest/java/org/elasticsearch/xpack/esql/plugin/QueryStringFunctionIT.java +++ b/x-pack/plugin/esql/src/internalClusterTest/java/org/elasticsearch/xpack/esql/plugin/QueryStringFunctionIT.java @@ -10,6 +10,7 @@ import org.elasticsearch.action.index.IndexRequest; import org.elasticsearch.action.support.WriteRequest; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.index.query.QueryShardException; import org.elasticsearch.xpack.esql.VerificationException; import org.elasticsearch.xpack.esql.action.AbstractEsqlIntegTestCase; import org.elasticsearch.xpack.esql.action.ColumnInfoImpl; @@ -84,6 +85,31 @@ public void testQueryStringWithinEval() { assertThat(error.getMessage(), containsString("[QSTR] function is only supported in WHERE commands")); } + public void testInvalidQueryStringEof() { + var query = """ + FROM test + | WHERE qstr("content: ((((dog") + """; + + var error = expectThrows(QueryShardException.class, () -> run(query)); + assertThat(error.getMessage(), containsString("Failed to parse query [content: ((((dog]")); + assertThat(error.getRootCause().getMessage(), containsString("Encountered \"\" at line 1, column 16")); + } + + public void testInvalidQueryStringLexicalError() { + var query = """ + FROM test + | WHERE qstr("/") + """; + + var error = expectThrows(QueryShardException.class, () -> run(query)); + assertThat(error.getMessage(), containsString("Failed to parse query [/]")); + assertThat( + error.getRootCause().getMessage(), + containsString("Lexical error at line 1, column 2. Encountered: (in lexical state 2)") + ); + } + private void createAndPopulateIndex() { var indexName = "test"; var client = client().admin().indices();