|
41 | 41 | import java.util.List; |
42 | 42 | import java.util.Map; |
43 | 43 | import java.util.Set; |
44 | | -import java.util.stream.Collectors; |
45 | 44 |
|
46 | 45 | import static org.elasticsearch.common.logging.LoggerMessageFormat.format; |
47 | 46 | import static org.elasticsearch.xpack.esql.CsvTestUtils.COMMA_ESCAPING_REGEX; |
@@ -258,11 +257,22 @@ public static void main(String[] args) throws IOException { |
258 | 257 | public static Set<TestsDataset> availableDatasetsForEs(RestClient client, boolean supportsIndexModeLookup) throws IOException { |
259 | 258 | boolean inferenceEnabled = clusterHasInferenceEndpoint(client); |
260 | 259 |
|
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")); |
266 | 276 | } |
267 | 277 |
|
268 | 278 | public static void loadDataSetIntoEs(RestClient client, boolean supportsIndexModeLookup) throws IOException { |
@@ -354,13 +364,8 @@ private static void load(RestClient client, TestsDataset dataset, Logger logger, |
354 | 364 | if (data == null) { |
355 | 365 | throw new IllegalArgumentException("Cannot find resource " + dataName); |
356 | 366 | } |
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(); |
364 | 369 | indexCreator.createIndex(client, dataset.indexName, readMappingFile(mapping, dataset.typeMapping), indexSettings); |
365 | 370 | loadCsvData(client, dataset.indexName, data, dataset.allowSubFields, logger); |
366 | 371 | } |
@@ -669,6 +674,18 @@ public TestsDataset withTypeMapping(Map<String, String> typeMapping) { |
669 | 674 | public TestsDataset withInferenceEndpoint(boolean needsInference) { |
670 | 675 | return new TestsDataset(indexName, mappingFileName, dataFileName, settingFileName, allowSubFields, typeMapping, needsInference); |
671 | 676 | } |
| 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 | + } |
672 | 689 | } |
673 | 690 |
|
674 | 691 | public record EnrichConfig(String policyName, String policyFileName) {} |
|
0 commit comments