Skip to content

Commit b4e6293

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

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
@@ -39,6 +39,7 @@
3939
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
4040
import static org.hamcrest.Matchers.hasSize;
4141
import static org.hamcrest.Matchers.instanceOf;
42+
import static org.hamcrest.Matchers.is;
4243

4344
@ThreadLeakFilters(filters = TestClustersThreadFilter.class)
4445
public class RequestIndexFilteringIT extends RequestIndexFilteringTestCase {
@@ -97,14 +98,20 @@ protected String from(String... indexName) {
9798

9899
@Override
99100
public Map<String, Object> runEsql(RestEsqlTestCase.RequestObjectBuilder requestObject) throws IOException {
101+
return runEsql(requestObject, true);
102+
}
103+
104+
@Override
105+
public Map<String, Object> runEsql(RestEsqlTestCase.RequestObjectBuilder requestObject, boolean checkPartialResults)
106+
throws IOException {
100107
if (requestObject.allowPartialResults() != null) {
101108
assumeTrue(
102109
"require allow_partial_results on local cluster",
103110
clusterHasCapability("POST", "/_query", List.of(), List.of("support_partial_results")).orElse(false)
104111
);
105112
}
106113
requestObject.includeCCSMetadata(true);
107-
return super.runEsql(requestObject);
114+
return super.runEsql(requestObject, checkPartialResults);
108115
}
109116

110117
@After
@@ -160,7 +167,30 @@ public void testIndicesDontExistRemote() throws IOException {
160167
indexTimestampData(docsTest1, "test1", "2024-11-26", "id1");
161168

162169
Map<String, Object> result = runEsql(
163-
timestampFilter("gte", "2020-01-01").query("FROM *:foo,*:test1 METADATA _index | SORT id1 | KEEP _index, id*")
170+
timestampFilter("gte", "2020-01-01").query("FROM *:foo,*:test1 METADATA _index | SORT id1 | KEEP _index, id*"),
171+
false
172+
);
173+
174+
// `foo` index doesn't exist, so the request will currently be successful, but with partial results
175+
var isPartial = result.get("is_partial");
176+
assertThat(isPartial, is(true));
177+
assertThat(
178+
result,
179+
matchesMap().entry(
180+
"_clusters",
181+
matchesMap().entry(
182+
"details",
183+
matchesMap().entry(
184+
"remote_cluster",
185+
matchesMap().entry(
186+
"failures",
187+
matchesList().item(
188+
matchesMap().entry("reason", matchesMap().entry("reason", "no such index [foo]").extraOk()).extraOk()
189+
)
190+
).extraOk()
191+
).extraOk()
192+
).extraOk()
193+
).extraOk()
164194
);
165195
@SuppressWarnings("unchecked")
166196
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
@@ -268,9 +268,7 @@ protected final void doTest() throws Throwable {
268268

269269
Map<String, Object> answer = runEsql(builder.query(testCase.query), testCase.assertWarnings(deduplicateExactWarnings()));
270270

271-
var clusters = answer.get("_clusters");
272-
var reason = "unexpected partial results" + (clusters != null ? ": _clusters=" + clusters : "");
273-
assertThat(reason, answer.get("is_partial"), anyOf(nullValue(), is(false)));
271+
assertNotPartial(answer);
274272

275273
var expectedColumnsWithValues = loadCsvSpecValues(testCase.expectedResults);
276274

@@ -288,6 +286,14 @@ protected final void doTest() throws Throwable {
288286
assertResults(expectedColumnsWithValues, actualColumns, actualValues, testCase.ignoreOrder, logger);
289287
}
290288

289+
static Map<String, Object> assertNotPartial(Map<String, Object> answer) {
290+
var clusters = answer.get("_clusters");
291+
var reason = "unexpected partial results" + (clusters != null ? ": _clusters=" + clusters : "");
292+
assertThat(reason, answer.get("is_partial"), anyOf(nullValue(), is(false)));
293+
294+
return answer;
295+
}
296+
291297
/**
292298
* Should warnings be de-duplicated before checking for exact matches. Defaults
293299
* to {@code false}, but in some environments we emit duplicate warnings. We'd prefer

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
@@ -62,6 +62,7 @@
6262
import static org.elasticsearch.test.MapMatcher.assertMap;
6363
import static org.elasticsearch.test.MapMatcher.matchesMap;
6464
import static org.elasticsearch.xpack.esql.EsqlTestUtils.as;
65+
import static org.elasticsearch.xpack.esql.qa.rest.EsqlSpecTestCase.assertNotPartial;
6566
import static org.elasticsearch.xpack.esql.qa.rest.RestEsqlTestCase.Mode.ASYNC;
6667
import static org.elasticsearch.xpack.esql.qa.rest.RestEsqlTestCase.Mode.SYNC;
6768
import static org.elasticsearch.xpack.esql.type.EsqlDataTypeConverter.dateTimeToString;
@@ -1242,13 +1243,21 @@ public static Map<String, Object> runEsqlAsync(RequestObjectBuilder requestObjec
12421243
return runEsqlAsync(requestObject, randomBoolean(), new AssertWarnings.NoWarnings());
12431244
}
12441245

1246+
public static Map<String, Object> runEsql(
1247+
RequestObjectBuilder requestObject,
1248+
AssertWarnings assertWarnings,
1249+
Mode mode,
1250+
boolean checkPartialResults
1251+
) throws IOException {
1252+
var results = mode == ASYNC
1253+
? runEsqlAsync(requestObject, randomBoolean(), assertWarnings)
1254+
: runEsqlSync(requestObject, assertWarnings);
1255+
return checkPartialResults ? assertNotPartial(results) : results;
1256+
}
1257+
12451258
public static Map<String, Object> runEsql(RequestObjectBuilder requestObject, AssertWarnings assertWarnings, Mode mode)
12461259
throws IOException {
1247-
if (mode == ASYNC) {
1248-
return runEsqlAsync(requestObject, randomBoolean(), assertWarnings);
1249-
} else {
1250-
return runEsqlSync(requestObject, assertWarnings);
1251-
}
1260+
return runEsql(requestObject, assertWarnings, mode, true);
12521261
}
12531262

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

0 commit comments

Comments
 (0)