Skip to content

Commit 52a178b

Browse files
authored
[8.x] ESQL: Properly skip datasets with lookup indices (#118682)
Do not rely on specific naming, read the actual settings.
1 parent fd20e28 commit 52a178b

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;
@@ -258,11 +257,22 @@ public static void main(String[] args) throws IOException {
258257
public static Set<TestsDataset> availableDatasetsForEs(RestClient client, boolean supportsIndexModeLookup) throws IOException {
259258
boolean inferenceEnabled = clusterHasInferenceEndpoint(client);
260259

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

268278
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)