Skip to content

Commit cf7edbb

Browse files
authored
Properly skip datasets with lookup indices (#118753)
Forward-port of #118682 to main This mostly just minimizes the diff; LOOKUP JOIN is enabled on main, so we don't need to skip the datasets here.
1 parent df01f81 commit cf7edbb

File tree

1 file changed

+30
-13
lines changed

1 file changed

+30
-13
lines changed

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

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
import java.util.List;
4242
import java.util.Map;
4343
import java.util.Set;
44-
import java.util.stream.Collectors;
4544

4645
import static org.elasticsearch.common.logging.LoggerMessageFormat.format;
4746
import static org.elasticsearch.xpack.esql.CsvTestUtils.COMMA_ESCAPING_REGEX;
@@ -260,11 +259,22 @@ public static void main(String[] args) throws IOException {
260259
public static Set<TestsDataset> availableDatasetsForEs(RestClient client, boolean supportsIndexModeLookup) throws IOException {
261260
boolean inferenceEnabled = clusterHasInferenceEndpoint(client);
262261

263-
return CSV_DATASET_MAP.values()
264-
.stream()
265-
.filter(d -> d.requiresInferenceEndpoint == false || inferenceEnabled)
266-
.filter(d -> supportsIndexModeLookup || d.indexName.endsWith("_lookup") == false) // TODO: use actual index settings
267-
.collect(Collectors.toCollection(HashSet::new));
262+
Set<TestsDataset> testDataSets = new HashSet<>();
263+
264+
for (TestsDataset dataset : CSV_DATASET_MAP.values()) {
265+
if ((inferenceEnabled || dataset.requiresInferenceEndpoint == false)
266+
&& (supportsIndexModeLookup || isLookupDataset(dataset) == false)) {
267+
testDataSets.add(dataset);
268+
}
269+
}
270+
271+
return testDataSets;
272+
}
273+
274+
public static boolean isLookupDataset(TestsDataset dataset) throws IOException {
275+
Settings settings = dataset.readSettingsFile();
276+
String mode = settings.get("index.mode");
277+
return (mode != null && mode.equalsIgnoreCase("lookup"));
268278
}
269279

270280
public static void loadDataSetIntoEs(RestClient client, boolean supportsIndexModeLookup) throws IOException {
@@ -354,13 +364,8 @@ private static void load(RestClient client, TestsDataset dataset, Logger logger,
354364
if (data == null) {
355365
throw new IllegalArgumentException("Cannot find resource " + dataName);
356366
}
357-
Settings indexSettings = Settings.EMPTY;
358-
final String settingName = dataset.settingFileName != null ? "/" + dataset.settingFileName : null;
359-
if (settingName != null) {
360-
indexSettings = Settings.builder()
361-
.loadFromStream(settingName, CsvTestsDataLoader.class.getResourceAsStream(settingName), false)
362-
.build();
363-
}
367+
368+
Settings indexSettings = dataset.readSettingsFile();
364369
indexCreator.createIndex(client, dataset.indexName, readMappingFile(mapping, dataset.typeMapping), indexSettings);
365370
loadCsvData(client, dataset.indexName, data, dataset.allowSubFields, logger);
366371
}
@@ -669,6 +674,18 @@ public TestsDataset withTypeMapping(Map<String, String> typeMapping) {
669674
public TestsDataset withInferenceEndpoint(boolean needsInference) {
670675
return new TestsDataset(indexName, mappingFileName, dataFileName, settingFileName, allowSubFields, typeMapping, needsInference);
671676
}
677+
678+
private Settings readSettingsFile() throws IOException {
679+
Settings indexSettings = Settings.EMPTY;
680+
final String settingName = settingFileName != null ? "/" + settingFileName : null;
681+
if (settingName != null) {
682+
indexSettings = Settings.builder()
683+
.loadFromStream(settingName, CsvTestsDataLoader.class.getResourceAsStream(settingName), false)
684+
.build();
685+
}
686+
687+
return indexSettings;
688+
}
672689
}
673690

674691
public record EnrichConfig(String policyName, String policyFileName) {}

0 commit comments

Comments
 (0)