Skip to content

Commit

Permalink
Update tests for new error message
Browse files Browse the repository at this point in the history
Signed-off-by: Simeon Widdis <[email protected]>
  • Loading branch information
Swiddis committed Jan 29, 2025
1 parent 6642475 commit b12a37d
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 16 deletions.
16 changes: 8 additions & 8 deletions docs/user/dql/troubleshooting.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,22 @@ Query:

.. code-block:: JSON
POST /_plugins/_sql
POST /_plugins/_ppl
{
"query" : "SELECT * FROM sample:data"
"query" : "SOURCE = test_index | where a > 0)"
}
Result:

.. code-block:: JSON
{
"reason": "Invalid SQL query",
"details": "Failed to parse query due to offending symbol [:] at: 'SELECT * FROM xxx WHERE xxx:' <--- HERE...
More details: Expecting tokens in {<EOF>, 'AND', 'BETWEEN', 'GROUP', 'HAVING', 'IN', 'IS', 'LIKE', 'LIMIT',
'NOT', 'OR', 'ORDER', 'REGEXP', '*', '/', '%', '+', '-', 'DIV', 'MOD', '=', '>', '<', '!',
'|', '&', '^', '.', DOT_ID}",
"type": "SyntaxAnalysisException"
"error": {
"reason": "Invalid Query",
"details": "[)] is not a valid term at this part of the query: '..._index | where a > 0)' <-- HERE. extraneous input ')' expecting <EOF>",
"type": "SyntaxCheckException"
},
"status": 400
}
**Workaround**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public void describeCommandWithoutIndexShouldFailToParse() throws IOException {
fail();
} catch (ResponseException e) {
assertTrue(e.getMessage().contains("RuntimeException"));
assertTrue(e.getMessage().contains("Failed to parse query due to offending symbol"));
assertTrue(e.getMessage().contains("is not a valid term at this part of the query"));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,25 +82,25 @@ public void queryShouldBeCaseInsensitiveInKeywords() {
@Test
public void queryNotStartingWithSearchCommandShouldFailSyntaxCheck() {
String query = "fields firstname";
queryShouldThrowSyntaxException(query, "Failed to parse query due to offending symbol");
queryShouldThrowSyntaxException(query, "is not a valid term at this part of the query");
}

@Test
public void queryWithIncorrectCommandShouldFailSyntaxCheck() {
String query = String.format("search source=%s | field firstname", TEST_INDEX_ACCOUNT);
queryShouldThrowSyntaxException(query, "Failed to parse query due to offending symbol");
queryShouldThrowSyntaxException(query, "is not a valid term at this part of the query");
}

@Test
public void queryWithIncorrectKeywordsShouldFailSyntaxCheck() {
String query = String.format("search sources=%s", TEST_INDEX_ACCOUNT);
queryShouldThrowSyntaxException(query, "Failed to parse query due to offending symbol");
queryShouldThrowSyntaxException(query, "is not a valid term at this part of the query");
}

@Test
public void unsupportedAggregationFunctionShouldFailSyntaxCheck() {
String query = String.format("search source=%s | stats range(age)", TEST_INDEX_ACCOUNT);
queryShouldThrowSyntaxException(query, "Failed to parse query due to offending symbol");
queryShouldThrowSyntaxException(query, "is not a valid term at this part of the query");
}

/** Commands that fail semantic analysis should throw {@link SemanticCheckException}. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void searchCommandWithoutSourceShouldFailToParse() throws IOException {
fail();
} catch (ResponseException e) {
assertTrue(e.getMessage().contains("RuntimeException"));
assertTrue(e.getMessage().contains("Failed to parse query due to offending symbol"));
assertTrue(e.getMessage().contains("is not a valid term at this part of the query"));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public void testSearchFieldsCommandCrossClusterShouldPass() {
@Test
public void testSearchCommandWithoutSourceShouldFail() {
exceptionRule.expect(RuntimeException.class);
exceptionRule.expectMessage("Failed to parse query due to offending symbol");
exceptionRule.expectMessage("is not a valid term at this part of the query");

new PPLSyntaxParser().parse("search a=1");
}
Expand Down Expand Up @@ -337,7 +337,7 @@ public void testDescribeFieldsCommandShouldPass() {
@Test
public void testDescribeCommandWithSourceShouldFail() {
exceptionRule.expect(RuntimeException.class);
exceptionRule.expectMessage("Failed to parse query due to offending symbol");
exceptionRule.expectMessage("is not a valid term at this part of the query");

new PPLSyntaxParser().parse("describe source=t");
}
Expand Down

0 comments on commit b12a37d

Please sign in to comment.