Skip to content

Commit 7836826

Browse files
authored
ESQL: Extend the check on partial results to all REST ITs (#130213)
This extends the check that no partial results are returned to the rest of the JSON-based REST ITs. Related: #129293
1 parent fe2d6df commit 7836826

File tree

4 files changed

+60
-10
lines changed

4 files changed

+60
-10
lines changed

x-pack/plugin/esql/qa/server/multi-clusters/src/javaRestTest/java/org/elasticsearch/xpack/esql/ccq/RequestIndexFilteringIT.java

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
3939
import static org.hamcrest.Matchers.hasSize;
4040
import static org.hamcrest.Matchers.instanceOf;
41+
import static org.hamcrest.Matchers.is;
4142

4243
@ThreadLeakFilters(filters = TestClustersThreadFilter.class)
4344
public class RequestIndexFilteringIT extends RequestIndexFilteringTestCase {
@@ -91,14 +92,20 @@ protected String from(String... indexName) {
9192

9293
@Override
9394
public Map<String, Object> runEsql(RestEsqlTestCase.RequestObjectBuilder requestObject) throws IOException {
95+
return runEsql(requestObject, true);
96+
}
97+
98+
@Override
99+
public Map<String, Object> runEsql(RestEsqlTestCase.RequestObjectBuilder requestObject, boolean checkPartialResults)
100+
throws IOException {
94101
if (requestObject.allowPartialResults() != null) {
95102
assumeTrue(
96103
"require allow_partial_results on local cluster",
97104
clusterHasCapability("POST", "/_query", List.of(), List.of("support_partial_results")).orElse(false)
98105
);
99106
}
100107
requestObject.includeCCSMetadata(true);
101-
return super.runEsql(requestObject);
108+
return super.runEsql(requestObject, checkPartialResults);
102109
}
103110

104111
@After
@@ -154,7 +161,30 @@ public void testIndicesDontExistRemote() throws IOException {
154161
indexTimestampData(docsTest1, "test1", "2024-11-26", "id1");
155162

156163
Map<String, Object> result = runEsql(
157-
timestampFilter("gte", "2020-01-01").query("FROM *:foo,*:test1 METADATA _index | SORT id1 | KEEP _index, id*")
164+
timestampFilter("gte", "2020-01-01").query("FROM *:foo,*:test1 METADATA _index | SORT id1 | KEEP _index, id*"),
165+
false
166+
);
167+
168+
// `foo` index doesn't exist, so the request will currently be successful, but with partial results
169+
var isPartial = result.get("is_partial");
170+
assertThat(isPartial, is(true));
171+
assertThat(
172+
result,
173+
matchesMap().entry(
174+
"_clusters",
175+
matchesMap().entry(
176+
"details",
177+
matchesMap().entry(
178+
"remote_cluster",
179+
matchesMap().entry(
180+
"failures",
181+
matchesList().item(
182+
matchesMap().entry("reason", matchesMap().entry("reason", "no such index [foo]").extraOk()).extraOk()
183+
)
184+
).extraOk()
185+
).extraOk()
186+
).extraOk()
187+
).extraOk()
158188
);
159189
@SuppressWarnings("unchecked")
160190
var columns = (List<List<Object>>) result.get("columns");

x-pack/plugin/esql/qa/server/src/main/java/org/elasticsearch/xpack/esql/qa/rest/EsqlSpecTestCase.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -276,9 +276,7 @@ protected final void doTest(String query) throws Throwable {
276276
Map<?, ?> prevTooks = supportsTook() ? tooks() : null;
277277
Map<String, Object> answer = runEsql(builder.query(query), testCase.assertWarnings(deduplicateExactWarnings()));
278278

279-
var clusters = answer.get("_clusters");
280-
var reason = "unexpected partial results" + (clusters != null ? ": _clusters=" + clusters : "");
281-
assertThat(reason, answer.get("is_partial"), anyOf(nullValue(), is(false)));
279+
assertNotPartial(answer);
282280

283281
var expectedColumnsWithValues = loadCsvSpecValues(testCase.expectedResults);
284282

@@ -303,6 +301,14 @@ protected final void doTest(String query) throws Throwable {
303301
}
304302
}
305303

304+
static Map<String, Object> assertNotPartial(Map<String, Object> answer) {
305+
var clusters = answer.get("_clusters");
306+
var reason = "unexpected partial results" + (clusters != null ? ": _clusters=" + clusters : "");
307+
assertThat(reason, answer.get("is_partial"), anyOf(nullValue(), is(false)));
308+
309+
return answer;
310+
}
311+
306312
private Map<?, ?> tooks() throws IOException {
307313
Request request = new Request("GET", "/_xpack/usage");
308314
HttpEntity entity = client().performRequest(request).getEntity();

x-pack/plugin/esql/qa/server/src/main/java/org/elasticsearch/xpack/esql/qa/rest/RequestIndexFilteringTestCase.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,11 @@ public Map<String, Object> runEsql(RestEsqlTestCase.RequestObjectBuilder request
249249
return RestEsqlTestCase.runEsql(requestObject, new AssertWarnings.NoWarnings(), RestEsqlTestCase.Mode.SYNC);
250250
}
251251

252+
public Map<String, Object> runEsql(RestEsqlTestCase.RequestObjectBuilder requestObject, boolean checkPartialResults)
253+
throws IOException {
254+
return RestEsqlTestCase.runEsql(requestObject, new AssertWarnings.NoWarnings(), RestEsqlTestCase.Mode.SYNC, checkPartialResults);
255+
}
256+
252257
protected void indexTimestampData(int docs, String indexName, String date, String differentiatorFieldName) throws IOException {
253258
indexTimestampDataForClient(client(), docs, indexName, date, differentiatorFieldName);
254259
}

x-pack/plugin/esql/qa/server/src/main/java/org/elasticsearch/xpack/esql/qa/rest/RestEsqlTestCase.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
import static org.elasticsearch.test.MapMatcher.assertMap;
6161
import static org.elasticsearch.test.MapMatcher.matchesMap;
6262
import static org.elasticsearch.xpack.esql.EsqlTestUtils.as;
63+
import static org.elasticsearch.xpack.esql.qa.rest.EsqlSpecTestCase.assertNotPartial;
6364
import static org.elasticsearch.xpack.esql.qa.rest.RestEsqlTestCase.Mode.ASYNC;
6465
import static org.elasticsearch.xpack.esql.qa.rest.RestEsqlTestCase.Mode.SYNC;
6566
import static org.elasticsearch.xpack.esql.type.EsqlDataTypeConverter.dateTimeToString;
@@ -1248,13 +1249,21 @@ public static Map<String, Object> runEsqlAsync(RequestObjectBuilder requestObjec
12481249
return runEsqlAsync(requestObject, randomBoolean(), new AssertWarnings.NoWarnings());
12491250
}
12501251

1252+
public static Map<String, Object> runEsql(
1253+
RequestObjectBuilder requestObject,
1254+
AssertWarnings assertWarnings,
1255+
Mode mode,
1256+
boolean checkPartialResults
1257+
) throws IOException {
1258+
var results = mode == ASYNC
1259+
? runEsqlAsync(requestObject, randomBoolean(), assertWarnings)
1260+
: runEsqlSync(requestObject, assertWarnings);
1261+
return checkPartialResults ? assertNotPartial(results) : results;
1262+
}
1263+
12511264
public static Map<String, Object> runEsql(RequestObjectBuilder requestObject, AssertWarnings assertWarnings, Mode mode)
12521265
throws IOException {
1253-
if (mode == ASYNC) {
1254-
return runEsqlAsync(requestObject, randomBoolean(), assertWarnings);
1255-
} else {
1256-
return runEsqlSync(requestObject, assertWarnings);
1257-
}
1266+
return runEsql(requestObject, assertWarnings, mode, true);
12581267
}
12591268

12601269
public static Map<String, Object> runEsqlSync(RequestObjectBuilder requestObject, AssertWarnings assertWarnings) throws IOException {

0 commit comments

Comments
 (0)