diff --git a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/parser/StatementParserTests.java b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/parser/StatementParserTests.java index 41508e26ceecf..b0f83672b5efb 100644 --- a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/parser/StatementParserTests.java +++ b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/parser/StatementParserTests.java @@ -961,14 +961,12 @@ public void testBasicSortCommand() { } public void testSubquery() { - assertEquals(new Explain(EMPTY, PROCESSING_CMD_INPUT), statement("explain ( row a = 1 )")); - } - - public void testSubqueryWithPipe() { + assumeTrue("Requires EXPLAIN capability", EsqlCapabilities.Cap.EXPLAIN.isEnabled()); assertEquals(new Explain(EMPTY, PROCESSING_CMD_INPUT), statement("explain ( row a = 1 )")); } public void testBlockComments() { + assumeTrue("Requires EXPLAIN capability", EsqlCapabilities.Cap.EXPLAIN.isEnabled()); String query = " explain ( from foo )"; LogicalPlan expected = statement(query); @@ -984,6 +982,7 @@ public void testBlockComments() { } public void testSingleLineComments() { + assumeTrue("Requires EXPLAIN capability", EsqlCapabilities.Cap.EXPLAIN.isEnabled()); String query = " explain ( from foo ) "; LogicalPlan expected = statement(query); @@ -1009,16 +1008,19 @@ public void testNewLines() { } public void testSuggestAvailableSourceCommandsOnParsingError() { - for (Tuple queryWithUnexpectedCmd : List.of( - Tuple.tuple("frm foo", "frm"), - Tuple.tuple("expln[from bar]", "expln"), - Tuple.tuple("not-a-thing logs", "not-a-thing"), - Tuple.tuple("high5 a", "high5"), - Tuple.tuple("a+b = c", "a+b"), - Tuple.tuple("a//hi", "a"), - Tuple.tuple("a/*hi*/", "a"), - Tuple.tuple("explain ( frm a )", "frm") - )) { + var cases = new ArrayList>(); + cases.add(Tuple.tuple("frm foo", "frm")); + cases.add(Tuple.tuple("expln[from bar]", "expln")); + cases.add(Tuple.tuple("not-a-thing logs", "not-a-thing")); + cases.add(Tuple.tuple("high5 a", "high5")); + cases.add(Tuple.tuple("a+b = c", "a+b")); + cases.add(Tuple.tuple("a//hi", "a")); + cases.add(Tuple.tuple("a/*hi*/", "a")); + if (EsqlCapabilities.Cap.EXPLAIN.isEnabled()) { + cases.add(Tuple.tuple("explain ( frm a )", "frm")); + } + + for (Tuple queryWithUnexpectedCmd : cases) { expectThrows( ParsingException.class, allOf( @@ -1084,7 +1086,12 @@ public void testDeprecatedIsNullFunction() { public void testMetadataFieldOnOtherSources() { expectError("row a = 1 metadata _index", "line 1:20: extraneous input '_index' expecting "); expectError("show info metadata _index", "line 1:11: token recognition error at: 'm'"); - expectError("explain ( from foo ) metadata _index", "line 1:22: mismatched input 'metadata' expecting {'|', ',', ')', 'metadata'}"); + if (EsqlCapabilities.Cap.EXPLAIN.isEnabled()) { + expectError( + "explain ( from foo ) metadata _index", + "line 1:22: mismatched input 'metadata' expecting {'|', ',', ')', 'metadata'}" + ); + } } public void testMetadataFieldMultipleDeclarations() { @@ -3473,8 +3480,8 @@ public void testFieldNamesAsCommands() throws Exception { } // [ and ( are used to trigger a double mode causing their symbol name (instead of text) to be used in error reporting - // this test checks that their are properly replaced in the error message - public void testPreserveParanthesis() { + // this test checks that they are properly replaced in the error message + public void testPreserveParentheses() { // test for ( expectError("row a = 1 not in", "line 1:17: mismatched input '' expecting '('"); expectError("row a = 1 | where a not in", "line 1:27: mismatched input '' expecting '('"); @@ -3482,9 +3489,11 @@ public void testPreserveParanthesis() { expectError("row a = 1 | where a not in [1", "line 1:28: missing '(' at '['"); expectError("row a = 1 | where a not in 123", "line 1:28: missing '(' at '123'"); // test for [ - expectError("explain", "line 1:8: mismatched input '' expecting '('"); - expectError("explain ]", "line 1:9: token recognition error at: ']'"); - expectError("explain ( row x = 1", "line 1:20: missing ')' at ''"); + if (EsqlCapabilities.Cap.EXPLAIN.isEnabled()) { + expectError("explain", "line 1:8: mismatched input '' expecting '('"); + expectError("explain ]", "line 1:9: token recognition error at: ']'"); + expectError("explain ( row x = 1", "line 1:20: missing ')' at ''"); + } } public void testRerankDefaultInferenceIdAndScoreAttribute() {