Skip to content

Commit ce05d27

Browse files
authored
ES|QL: Fix error messages for non-snapshot tests (#112824) (#112894)
* Fix error messages * Fix something unrelated to this PR * Fix also TelemetryIT
1 parent 0279c0a commit ce05d27

File tree

10 files changed

+167
-82
lines changed

10 files changed

+167
-82
lines changed

x-pack/plugin/esql/src/internalClusterTest/java/org/elasticsearch/xpack/esql/action/TelemetryIT.java

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import com.carrotsearch.randomizedtesting.annotations.Name;
1111
import com.carrotsearch.randomizedtesting.annotations.ParametersFactory;
1212

13+
import org.elasticsearch.Build;
1314
import org.elasticsearch.action.ActionListener;
1415
import org.elasticsearch.cluster.metadata.IndexMetadata;
1516
import org.elasticsearch.cluster.node.DiscoveryNode;
@@ -23,6 +24,7 @@
2324
import org.junit.Before;
2425

2526
import java.util.Collection;
27+
import java.util.Collections;
2628
import java.util.List;
2729
import java.util.Map;
2830
import java.util.Set;
@@ -112,13 +114,20 @@ public static Iterable<Object[]> parameters() {
112114
true
113115
) },
114116
new Object[] {
115-
new Test("METRICS idx | LIMIT 10", Map.ofEntries(Map.entry("METRICS", 1), Map.entry("LIMIT", 1)), Map.ofEntries(), true) },
117+
new Test(
118+
"METRICS idx | LIMIT 10",
119+
Build.current().isSnapshot() ? Map.ofEntries(Map.entry("METRICS", 1), Map.entry("LIMIT", 1)) : Collections.emptyMap(),
120+
Map.ofEntries(),
121+
Build.current().isSnapshot()
122+
) },
116123
new Object[] {
117124
new Test(
118125
"METRICS idx max(id) BY host | LIMIT 10",
119-
Map.ofEntries(Map.entry("METRICS", 1), Map.entry("LIMIT", 1), Map.entry("FROM TS", 1)),
120-
Map.ofEntries(Map.entry("MAX", 1)),
121-
true
126+
Build.current().isSnapshot()
127+
? Map.ofEntries(Map.entry("METRICS", 1), Map.entry("LIMIT", 1), Map.entry("FROM TS", 1))
128+
: Collections.emptyMap(),
129+
Build.current().isSnapshot() ? Map.ofEntries(Map.entry("MAX", 1)) : Collections.emptyMap(),
130+
Build.current().isSnapshot()
122131
) },
123132
new Object[] {
124133
new Test(
@@ -127,9 +136,13 @@ public static Iterable<Object[]> parameters() {
127136
| EVAL ip = to_ip(host), x = to_string(host), y = to_string(host)
128137
| INLINESTATS max(id)
129138
""",
130-
Map.ofEntries(Map.entry("FROM", 1), Map.entry("EVAL", 1), Map.entry("INLINESTATS", 1)),
131-
Map.ofEntries(Map.entry("MAX", 1), Map.entry("TO_IP", 1), Map.entry("TO_STRING", 2)),
132-
true
139+
Build.current().isSnapshot()
140+
? Map.ofEntries(Map.entry("FROM", 1), Map.entry("EVAL", 1), Map.entry("INLINESTATS", 1))
141+
: Collections.emptyMap(),
142+
Build.current().isSnapshot()
143+
? Map.ofEntries(Map.entry("MAX", 1), Map.entry("TO_IP", 1), Map.entry("TO_STRING", 2))
144+
: Collections.emptyMap(),
145+
Build.current().isSnapshot()
133146
) }
134147
);
135148
}

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/analysis/AnalyzerTests.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1904,9 +1904,9 @@ public void testLookup() {
19041904
| RENAME languages AS int
19051905
| LOOKUP int_number_names ON int
19061906
""";
1907-
if (Build.current().isProductionRelease()) {
1907+
if (Build.current().isSnapshot() == false) {
19081908
var e = expectThrows(ParsingException.class, () -> analyze(query));
1909-
assertThat(e.getMessage(), containsString("line 3:4: LOOKUP is in preview and only available in SNAPSHOT build"));
1909+
assertThat(e.getMessage(), containsString("line 3:3: mismatched input 'LOOKUP' expecting {"));
19101910
return;
19111911
}
19121912
LogicalPlan plan = analyze(query);
@@ -1960,9 +1960,9 @@ public void testLookupMissingField() {
19601960
FROM test
19611961
| LOOKUP int_number_names ON garbage
19621962
""";
1963-
if (Build.current().isProductionRelease()) {
1963+
if (Build.current().isSnapshot() == false) {
19641964
var e = expectThrows(ParsingException.class, () -> analyze(query));
1965-
assertThat(e.getMessage(), containsString("line 2:4: LOOKUP is in preview and only available in SNAPSHOT build"));
1965+
assertThat(e.getMessage(), containsString("line 2:3: mismatched input 'LOOKUP' expecting {"));
19661966
return;
19671967
}
19681968
var e = expectThrows(VerificationException.class, () -> analyze(query));
@@ -1974,9 +1974,9 @@ public void testLookupMissingTable() {
19741974
FROM test
19751975
| LOOKUP garbage ON a
19761976
""";
1977-
if (Build.current().isProductionRelease()) {
1977+
if (Build.current().isSnapshot() == false) {
19781978
var e = expectThrows(ParsingException.class, () -> analyze(query));
1979-
assertThat(e.getMessage(), containsString("line 2:4: LOOKUP is in preview and only available in SNAPSHOT build"));
1979+
assertThat(e.getMessage(), containsString("line 2:3: mismatched input 'LOOKUP' expecting {"));
19801980
return;
19811981
}
19821982
var e = expectThrows(VerificationException.class, () -> analyze(query));
@@ -1989,9 +1989,9 @@ public void testLookupMatchTypeWrong() {
19891989
| RENAME last_name AS int
19901990
| LOOKUP int_number_names ON int
19911991
""";
1992-
if (Build.current().isProductionRelease()) {
1992+
if (Build.current().isSnapshot() == false) {
19931993
var e = expectThrows(ParsingException.class, () -> analyze(query));
1994-
assertThat(e.getMessage(), containsString("line 3:4: LOOKUP is in preview and only available in SNAPSHOT build"));
1994+
assertThat(e.getMessage(), containsString("line 3:3: mismatched input 'LOOKUP' expecting {"));
19951995
return;
19961996
}
19971997
var e = expectThrows(VerificationException.class, () -> analyze(query));

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/analysis/VerifierTests.java

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import org.elasticsearch.xpack.esql.index.EsIndex;
1919
import org.elasticsearch.xpack.esql.index.IndexResolution;
2020
import org.elasticsearch.xpack.esql.parser.EsqlParser;
21+
import org.elasticsearch.xpack.esql.parser.ParsingException;
2122
import org.elasticsearch.xpack.esql.parser.QueryParam;
2223
import org.elasticsearch.xpack.esql.parser.QueryParams;
2324

@@ -35,6 +36,7 @@
3536
import static org.elasticsearch.xpack.esql.core.type.DataType.UNSIGNED_LONG;
3637
import static org.hamcrest.Matchers.containsString;
3738
import static org.hamcrest.Matchers.equalTo;
39+
import static org.hamcrest.Matchers.instanceOf;
3840
import static org.hamcrest.Matchers.matchesRegex;
3941

4042
//@TestLogging(value = "org.elasticsearch.xpack.esql:TRACE,org.elasticsearch.compute:TRACE", reason = "debug")
@@ -1075,21 +1077,36 @@ public void testMatchFilter() throws Exception {
10751077
);
10761078
}
10771079

1078-
public void testMatchCommand() throws Exception {
1079-
assumeTrue("skipping because MATCH_COMMAND is not enabled", EsqlCapabilities.Cap.MATCH_COMMAND.isEnabled());
1080-
assertEquals("1:24: MATCH cannot be used after LIMIT", error("from test | limit 10 | match \"Anna\""));
1081-
assertEquals("1:13: MATCH cannot be used after SHOW", error("show info | match \"8.16.0\""));
1082-
assertEquals("1:17: MATCH cannot be used after ROW", error("row a= \"Anna\" | match \"Anna\""));
1083-
assertEquals("1:26: MATCH cannot be used after EVAL", error("from test | eval z = 2 | match \"Anna\""));
1084-
assertEquals("1:43: MATCH cannot be used after DISSECT", error("from test | dissect first_name \"%{foo}\" | match \"Connection\""));
1085-
assertEquals("1:27: MATCH cannot be used after DROP", error("from test | drop emp_no | match \"Anna\""));
1086-
assertEquals("1:35: MATCH cannot be used after EVAL", error("from test | eval n = emp_no * 3 | match \"Anna\""));
1087-
assertEquals("1:44: MATCH cannot be used after GROK", error("from test | grok last_name \"%{WORD:foo}\" | match \"Anna\""));
1088-
assertEquals("1:27: MATCH cannot be used after KEEP", error("from test | keep emp_no | match \"Anna\""));
1080+
public void testMatchCommand() {
1081+
assertMatchCommand("1:24:", "LIMIT", "from test | limit 10 | match \"Anna\"");
1082+
assertMatchCommand("1:13:", "SHOW", "show info | match \"8.16.0\"");
1083+
assertMatchCommand("1:17:", "ROW", "row a= \"Anna\" | match \"Anna\"");
1084+
assertMatchCommand("1:26:", "EVAL", "from test | eval z = 2 | match \"Anna\"");
1085+
assertMatchCommand("1:43:", "DISSECT", "from test | dissect first_name \"%{foo}\" | match \"Connection\"");
1086+
assertMatchCommand("1:27:", "DROP", "from test | drop emp_no | match \"Anna\"");
1087+
assertMatchCommand("1:35:", "EVAL", "from test | eval n = emp_no * 3 | match \"Anna\"");
1088+
assertMatchCommand("1:44:", "GROK", "from test | grok last_name \"%{WORD:foo}\" | match \"Anna\"");
1089+
assertMatchCommand("1:27:", "KEEP", "from test | keep emp_no | match \"Anna\"");
10891090

10901091
// TODO Keep adding tests for all unsupported commands
10911092
}
10921093

1094+
private void assertMatchCommand(String lineAndColumn, String command, String query) {
1095+
String message;
1096+
Class<? extends Exception> exception;
1097+
var isSnapshot = Build.current().isSnapshot();
1098+
if (isSnapshot) {
1099+
message = " MATCH cannot be used after ";
1100+
exception = VerificationException.class;
1101+
} else {
1102+
message = " mismatched input 'match' expecting ";
1103+
exception = ParsingException.class;
1104+
}
1105+
1106+
var expectedErrorMessage = lineAndColumn + message + (isSnapshot ? command : "");
1107+
assertThat(error(query, defaultAnalyzer, exception), containsString(expectedErrorMessage));
1108+
}
1109+
10931110
public void testCoalesceWithMixedNumericTypes() {
10941111
assertEquals(
10951112
"1:22: second argument of [coalesce(languages, height)] must be [integer], found value [height] type [double]",
@@ -1292,6 +1309,10 @@ private String error(String query, Object... params) {
12921309
}
12931310

12941311
private String error(String query, Analyzer analyzer, Object... params) {
1312+
return error(query, analyzer, VerificationException.class, params);
1313+
}
1314+
1315+
private String error(String query, Analyzer analyzer, Class<? extends Exception> exception, Object... params) {
12951316
List<QueryParam> parameters = new ArrayList<>();
12961317
for (Object param : params) {
12971318
if (param == null) {
@@ -1304,12 +1325,13 @@ private String error(String query, Analyzer analyzer, Object... params) {
13041325
throw new IllegalArgumentException("VerifierTests don't support params of type " + param.getClass());
13051326
}
13061327
}
1307-
VerificationException e = expectThrows(
1308-
VerificationException.class,
1309-
() -> analyzer.analyze(parser.createStatement(query, new QueryParams(parameters)))
1310-
);
1328+
Throwable e = expectThrows(exception, () -> analyzer.analyze(parser.createStatement(query, new QueryParams(parameters))));
1329+
assertThat(e, instanceOf(exception));
1330+
13111331
String message = e.getMessage();
1312-
assertTrue(message.startsWith("Found "));
1332+
if (e instanceof VerificationException) {
1333+
assertTrue(message.startsWith("Found "));
1334+
}
13131335
String pattern = "\nline ";
13141336
int index = message.indexOf(pattern);
13151337
return message.substring(index + pattern.length());

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/scalar/conditional/CaseTests.java

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import com.carrotsearch.randomizedtesting.annotations.Name;
1111
import com.carrotsearch.randomizedtesting.annotations.ParametersFactory;
1212

13+
import org.elasticsearch.Build;
1314
import org.elasticsearch.core.Nullable;
1415
import org.elasticsearch.test.ESTestCase;
1516
import org.elasticsearch.xpack.esql.core.expression.Expression;
@@ -27,31 +28,41 @@
2728
import java.util.Locale;
2829
import java.util.function.Function;
2930
import java.util.function.Supplier;
31+
import java.util.stream.Collectors;
32+
import java.util.stream.Stream;
3033

34+
import static java.util.Collections.unmodifiableList;
3135
import static org.elasticsearch.xpack.esql.EsqlTestUtils.randomLiteral;
3236
import static org.hamcrest.Matchers.equalTo;
3337
import static org.hamcrest.Matchers.sameInstance;
3438
import static org.hamcrest.Matchers.startsWith;
3539

3640
public class CaseTests extends AbstractScalarFunctionTestCase {
37-
private static final List<DataType> TYPES = List.of(
38-
DataType.KEYWORD,
39-
DataType.TEXT,
40-
DataType.BOOLEAN,
41-
DataType.DATETIME,
42-
DataType.DATE_NANOS,
43-
DataType.DOUBLE,
44-
DataType.INTEGER,
45-
DataType.LONG,
46-
DataType.UNSIGNED_LONG,
47-
DataType.IP,
48-
DataType.VERSION,
49-
DataType.CARTESIAN_POINT,
50-
DataType.GEO_POINT,
51-
DataType.CARTESIAN_SHAPE,
52-
DataType.GEO_SHAPE,
53-
DataType.NULL
54-
);
41+
42+
private static final List<DataType> TYPES;
43+
static {
44+
List<DataType> t = Stream.of(
45+
DataType.KEYWORD,
46+
DataType.TEXT,
47+
DataType.BOOLEAN,
48+
DataType.DATETIME,
49+
DataType.DOUBLE,
50+
DataType.INTEGER,
51+
DataType.LONG,
52+
DataType.UNSIGNED_LONG,
53+
DataType.IP,
54+
DataType.VERSION,
55+
DataType.CARTESIAN_POINT,
56+
DataType.GEO_POINT,
57+
DataType.CARTESIAN_SHAPE,
58+
DataType.GEO_SHAPE,
59+
DataType.NULL
60+
).collect(Collectors.toList());
61+
if (Build.current().isSnapshot()) {
62+
t.addAll(DataType.UNDER_CONSTRUCTION.keySet());
63+
}
64+
TYPES = unmodifiableList(t);
65+
}
5566

5667
public CaseTests(@Name("TestCase") Supplier<TestCaseSupplier.TestCase> testCaseSupplier) {
5768
this.testCase = testCaseSupplier.get();

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/optimizer/LogicalPlanOptimizerTests.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4431,11 +4431,16 @@ public void testReplaceSortByExpressionsWithStats() {
44314431
* \_EsRelation[test][_meta_field{f}#13, emp_no{f}#7, first_name{f}#8, ge..]
44324432
*/
44334433
public void testInlinestatsNestedExpressionsInGroups() {
4434-
var plan = optimizedPlan("""
4434+
var query = """
44354435
FROM test
44364436
| INLINESTATS c = COUNT(salary) by emp_no % 2
4437-
""");
4438-
4437+
""";
4438+
if (Build.current().isSnapshot() == false) {
4439+
var e = expectThrows(ParsingException.class, () -> analyze(query));
4440+
assertThat(e.getMessage(), containsString("line 2:3: mismatched input 'INLINESTATS' expecting {"));
4441+
return;
4442+
}
4443+
var plan = optimizedPlan(query);
44394444
var limit = as(plan, Limit.class);
44404445
var agg = as(limit.child(), InlineStats.class);
44414446
var groupings = agg.groupings();
@@ -4862,9 +4867,9 @@ public void testLookupSimple() {
48624867
FROM test
48634868
| RENAME languages AS int
48644869
| LOOKUP int_number_names ON int""";
4865-
if (Build.current().isProductionRelease()) {
4870+
if (Build.current().isSnapshot() == false) {
48664871
var e = expectThrows(ParsingException.class, () -> analyze(query));
4867-
assertThat(e.getMessage(), containsString("line 3:4: LOOKUP is in preview and only available in SNAPSHOT build"));
4872+
assertThat(e.getMessage(), containsString("line 3:3: mismatched input 'LOOKUP' expecting {"));
48684873
return;
48694874
}
48704875
var plan = optimizedPlan(query);
@@ -4941,9 +4946,9 @@ public void testLookupStats() {
49414946
| RENAME languages AS int
49424947
| LOOKUP int_number_names ON int
49434948
| STATS MIN(emp_no) BY name""";
4944-
if (Build.current().isProductionRelease()) {
4949+
if (Build.current().isSnapshot() == false) {
49454950
var e = expectThrows(ParsingException.class, () -> analyze(query));
4946-
assertThat(e.getMessage(), containsString("line 3:4: LOOKUP is in preview and only available in SNAPSHOT build"));
4951+
assertThat(e.getMessage(), containsString("line 3:3: mismatched input 'LOOKUP' expecting {"));
49474952
return;
49484953
}
49494954
var plan = optimizedPlan(query);

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/optimizer/PhysicalPlanOptimizerTests.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4484,9 +4484,9 @@ public void testLookupSimple() {
44844484
FROM test
44854485
| RENAME languages AS int
44864486
| LOOKUP int_number_names ON int""";
4487-
if (Build.current().isProductionRelease()) {
4487+
if (Build.current().isSnapshot() == false) {
44884488
var e = expectThrows(ParsingException.class, () -> analyze(query));
4489-
assertThat(e.getMessage(), containsString("line 3:4: LOOKUP is in preview and only available in SNAPSHOT build"));
4489+
assertThat(e.getMessage(), containsString("line 3:3: mismatched input 'LOOKUP' expecting {"));
44904490
return;
44914491
}
44924492
PhysicalPlan plan = physicalPlan(query);
@@ -4533,9 +4533,9 @@ public void testLookupThenProject() {
45334533
| LOOKUP int_number_names ON int
45344534
| RENAME int AS languages, name AS lang_name
45354535
| KEEP emp_no, languages, lang_name""";
4536-
if (Build.current().isProductionRelease()) {
4536+
if (Build.current().isSnapshot() == false) {
45374537
var e = expectThrows(ParsingException.class, () -> analyze(query));
4538-
assertThat(e.getMessage(), containsString("line 5:4: LOOKUP is in preview and only available in SNAPSHOT build"));
4538+
assertThat(e.getMessage(), containsString("line 5:3: mismatched input 'LOOKUP' expecting {"));
45394539
return;
45404540
}
45414541
PhysicalPlan plan = optimizedPlan(physicalPlan(query));
@@ -4590,9 +4590,9 @@ public void testLookupThenTopN() {
45904590
| RENAME name AS languages
45914591
| KEEP languages, emp_no
45924592
| SORT languages ASC, emp_no ASC""";
4593-
if (Build.current().isProductionRelease()) {
4593+
if (Build.current().isSnapshot() == false) {
45944594
var e = expectThrows(ParsingException.class, () -> analyze(query));
4595-
assertThat(e.getMessage(), containsString("line 3:4: LOOKUP is in preview and only available in SNAPSHOT build"));
4595+
assertThat(e.getMessage(), containsString("line 3:3: mismatched input 'LOOKUP' expecting {"));
45964596
return;
45974597
}
45984598
var plan = physicalPlan(query);

0 commit comments

Comments
 (0)