Skip to content

Commit d53ccaf

Browse files
Minimize code diff after Re-enable LOOKUP JOIN tests in 8.18 (#118373)
When we back-ported the LOOKUP JOIN PRs to 8.x (see #117967), we found it necessary to disable all csv-spec tests since they create indices with mode:lookup, which is illegal in the cluster state of mixed clusters where other nodes do not understand the new index mode. We need to re-enable the tests, and make sure the tests are only disabled in mixed clusters with node versions too old to handle the new mode.
1 parent 78488c7 commit d53ccaf

File tree

6 files changed

+52
-20
lines changed

6 files changed

+52
-20
lines changed

x-pack/plugin/esql/qa/server/mixed-cluster/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ restResources {
2727
dependencies {
2828
javaRestTestImplementation project(xpackModule('esql:qa:testFixtures'))
2929
javaRestTestImplementation project(xpackModule('esql:qa:server'))
30+
javaRestTestImplementation project(xpackModule('esql'))
3031
}
3132

3233
GradleUtils.extendSourceSet(project, "javaRestTest", "yamlRestTest")

x-pack/plugin/esql/qa/server/mixed-cluster/src/javaRestTest/java/org/elasticsearch/xpack/esql/qa/mixed/MixedClusterEsqlSpecIT.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@
1818
import org.junit.ClassRule;
1919

2020
import java.io.IOException;
21+
import java.util.List;
2122

2223
import static org.elasticsearch.xpack.esql.CsvTestUtils.isEnabled;
24+
import static org.elasticsearch.xpack.esql.action.EsqlCapabilities.Cap.JOIN_LOOKUP_V4;
2325
import static org.elasticsearch.xpack.esql.qa.rest.EsqlSpecTestCase.Mode.ASYNC;
2426

2527
public class MixedClusterEsqlSpecIT extends EsqlSpecTestCase {
@@ -92,6 +94,11 @@ protected boolean supportsInferenceTestService() {
9294
return false;
9395
}
9496

97+
@Override
98+
protected boolean supportsIndexModeLookup() throws IOException {
99+
return hasCapabilities(List.of(JOIN_LOOKUP_V4.capabilityName()));
100+
}
101+
95102
@Override
96103
protected boolean deduplicateExactWarnings() {
97104
/*

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,4 +280,11 @@ protected boolean enableRoundingDoubleValuesOnAsserting() {
280280
protected boolean supportsInferenceTestService() {
281281
return false;
282282
}
283+
284+
@Override
285+
protected boolean supportsIndexModeLookup() throws IOException {
286+
// CCS does not yet support JOIN_LOOKUP_V4 and clusters falsely report they have this capability
287+
// return hasCapabilities(List.of(JOIN_LOOKUP_V4.capabilityName()));
288+
return false;
289+
}
283290
}

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

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,8 @@ public void setup() throws IOException {
135135
createInferenceEndpoint(client());
136136
}
137137

138-
if (indexExists(availableDatasetsForEs(client()).iterator().next().indexName()) == false) {
139-
loadDataSetIntoEs(client());
138+
if (indexExists(availableDatasetsForEs(client(), supportsIndexModeLookup()).iterator().next().indexName()) == false) {
139+
loadDataSetIntoEs(client(), supportsIndexModeLookup());
140140
}
141141
}
142142

@@ -182,12 +182,30 @@ protected void shouldSkipTest(String testName) throws IOException {
182182

183183
protected static void checkCapabilities(RestClient client, TestFeatureService testFeatureService, String testName, CsvTestCase testCase)
184184
throws IOException {
185-
if (testCase.requiredCapabilities.isEmpty()) {
185+
if (hasCapabilities(client, testCase.requiredCapabilities)) {
186186
return;
187187
}
188+
189+
var features = new EsqlFeatures().getFeatures().stream().map(NodeFeature::id).collect(Collectors.toSet());
190+
191+
for (String feature : testCase.requiredCapabilities) {
192+
var esqlFeature = "esql." + feature;
193+
assumeTrue("Requested capability " + feature + " is an ESQL cluster feature", features.contains(esqlFeature));
194+
assumeTrue("Test " + testName + " requires " + feature, testFeatureService.clusterHasFeature(esqlFeature));
195+
}
196+
}
197+
198+
protected static boolean hasCapabilities(List<String> requiredCapabilities) throws IOException {
199+
return hasCapabilities(adminClient(), requiredCapabilities);
200+
}
201+
202+
protected static boolean hasCapabilities(RestClient client, List<String> requiredCapabilities) throws IOException {
203+
if (requiredCapabilities.isEmpty()) {
204+
return true;
205+
}
188206
try {
189-
if (clusterHasCapability(client, "POST", "/_query", List.of(), testCase.requiredCapabilities).orElse(false)) {
190-
return;
207+
if (clusterHasCapability(client, "POST", "/_query", List.of(), requiredCapabilities).orElse(false)) {
208+
return true;
191209
}
192210
LOGGER.info("capabilities API returned false, we might be in a mixed version cluster so falling back to cluster features");
193211
} catch (ResponseException e) {
@@ -206,20 +224,17 @@ protected static void checkCapabilities(RestClient client, TestFeatureService te
206224
throw e;
207225
}
208226
}
209-
210-
var features = new EsqlFeatures().getFeatures().stream().map(NodeFeature::id).collect(Collectors.toSet());
211-
212-
for (String feature : testCase.requiredCapabilities) {
213-
var esqlFeature = "esql." + feature;
214-
assumeTrue("Requested capability " + feature + " is an ESQL cluster feature", features.contains(esqlFeature));
215-
assumeTrue("Test " + testName + " requires " + feature, testFeatureService.clusterHasFeature(esqlFeature));
216-
}
227+
return false;
217228
}
218229

219230
protected boolean supportsInferenceTestService() {
220231
return true;
221232
}
222233

234+
protected boolean supportsIndexModeLookup() throws IOException {
235+
return true;
236+
}
237+
223238
protected final void doTest() throws Throwable {
224239
RequestObjectBuilder builder = new RequestObjectBuilder(randomFrom(XContentType.values()));
225240

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public abstract class GenerativeRestTest extends ESRestTestCase {
4646
@Before
4747
public void setup() throws IOException {
4848
if (indexExists(CSV_DATASET_MAP.keySet().iterator().next()) == false) {
49-
loadDataSetIntoEs(client());
49+
loadDataSetIntoEs(client(), true);
5050
}
5151
}
5252

x-pack/plugin/esql/qa/testFixtures/src/main/java/org/elasticsearch/xpack/esql/CsvTestsDataLoader.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ public static void main(String[] args) throws IOException {
235235
}
236236

237237
try (RestClient client = builder.build()) {
238-
loadDataSetIntoEs(client, (restClient, indexName, indexMapping, indexSettings) -> {
238+
loadDataSetIntoEs(client, true, (restClient, indexName, indexMapping, indexSettings) -> {
239239
// don't use ESRestTestCase methods here or, if you do, test running the main method before making the change
240240
StringBuilder jsonBody = new StringBuilder("{");
241241
if (indexSettings != null && indexSettings.isEmpty() == false) {
@@ -254,26 +254,28 @@ public static void main(String[] args) throws IOException {
254254
}
255255
}
256256

257-
public static Set<TestsDataset> availableDatasetsForEs(RestClient client) throws IOException {
257+
public static Set<TestsDataset> availableDatasetsForEs(RestClient client, boolean supportsIndexModeLookup) throws IOException {
258258
boolean inferenceEnabled = clusterHasInferenceEndpoint(client);
259259

260260
return CSV_DATASET_MAP.values()
261261
.stream()
262262
.filter(d -> d.requiresInferenceEndpoint == false || inferenceEnabled)
263+
.filter(d -> supportsIndexModeLookup || d.indexName.endsWith("_lookup") == false) // TODO: use actual index settings
263264
.collect(Collectors.toCollection(HashSet::new));
264265
}
265266

266-
public static void loadDataSetIntoEs(RestClient client) throws IOException {
267-
loadDataSetIntoEs(client, (restClient, indexName, indexMapping, indexSettings) -> {
267+
public static void loadDataSetIntoEs(RestClient client, boolean supportsIndexModeLookup) throws IOException {
268+
loadDataSetIntoEs(client, supportsIndexModeLookup, (restClient, indexName, indexMapping, indexSettings) -> {
268269
ESRestTestCase.createIndex(restClient, indexName, indexSettings, indexMapping, null);
269270
});
270271
}
271272

272-
private static void loadDataSetIntoEs(RestClient client, IndexCreator indexCreator) throws IOException {
273+
private static void loadDataSetIntoEs(RestClient client, boolean supportsIndexModeLookup, IndexCreator indexCreator)
274+
throws IOException {
273275
Logger logger = LogManager.getLogger(CsvTestsDataLoader.class);
274276

275277
Set<String> loadedDatasets = new HashSet<>();
276-
for (var dataset : availableDatasetsForEs(client)) {
278+
for (var dataset : availableDatasetsForEs(client, supportsIndexModeLookup)) {
277279
load(client, dataset, logger, indexCreator);
278280
loadedDatasets.add(dataset.indexName);
279281
}

0 commit comments

Comments
 (0)