Skip to content

Commit

Permalink
Add query string parsing errors tests
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosdelest committed Sep 16, 2024
1 parent 8a840ec commit e3427f0
Showing 1 changed file with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 \"<EOF>\" 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: <EOF> (in lexical state 2)")
);
}

private void createAndPopulateIndex() {
var indexName = "test";
var client = client().admin().indices();
Expand Down

0 comments on commit e3427f0

Please sign in to comment.