Skip to content

Commit

Permalink
[8.x] ESQL: Properly skip datasets with lookup indices (elastic#118682)
Browse files Browse the repository at this point in the history
Do not rely on specific naming, read the actual settings.
  • Loading branch information
alex-spies authored Dec 16, 2024
1 parent fd20e28 commit 52a178b
Showing 1 changed file with 30 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

import static org.elasticsearch.common.logging.LoggerMessageFormat.format;
import static org.elasticsearch.xpack.esql.CsvTestUtils.COMMA_ESCAPING_REGEX;
Expand Down Expand Up @@ -258,11 +257,22 @@ public static void main(String[] args) throws IOException {
public static Set<TestsDataset> availableDatasetsForEs(RestClient client, boolean supportsIndexModeLookup) throws IOException {
boolean inferenceEnabled = clusterHasInferenceEndpoint(client);

return CSV_DATASET_MAP.values()
.stream()
.filter(d -> d.requiresInferenceEndpoint == false || inferenceEnabled)
.filter(d -> supportsIndexModeLookup || d.indexName.endsWith("_lookup") == false) // TODO: use actual index settings
.collect(Collectors.toCollection(HashSet::new));
Set<TestsDataset> testDataSets = new HashSet<>();

for (TestsDataset dataset : CSV_DATASET_MAP.values()) {
if ((inferenceEnabled || dataset.requiresInferenceEndpoint == false)
&& (supportsIndexModeLookup || isLookupDataset(dataset) == false)) {
testDataSets.add(dataset);
}
}

return testDataSets;
}

public static boolean isLookupDataset(TestsDataset dataset) throws IOException {
Settings settings = dataset.readSettingsFile();
String mode = settings.get("index.mode");
return (mode != null && mode.equalsIgnoreCase("lookup"));
}

public static void loadDataSetIntoEs(RestClient client, boolean supportsIndexModeLookup) throws IOException {
Expand Down Expand Up @@ -354,13 +364,8 @@ private static void load(RestClient client, TestsDataset dataset, Logger logger,
if (data == null) {
throw new IllegalArgumentException("Cannot find resource " + dataName);
}
Settings indexSettings = Settings.EMPTY;
final String settingName = dataset.settingFileName != null ? "/" + dataset.settingFileName : null;
if (settingName != null) {
indexSettings = Settings.builder()
.loadFromStream(settingName, CsvTestsDataLoader.class.getResourceAsStream(settingName), false)
.build();
}

Settings indexSettings = dataset.readSettingsFile();
indexCreator.createIndex(client, dataset.indexName, readMappingFile(mapping, dataset.typeMapping), indexSettings);
loadCsvData(client, dataset.indexName, data, dataset.allowSubFields, logger);
}
Expand Down Expand Up @@ -669,6 +674,18 @@ public TestsDataset withTypeMapping(Map<String, String> typeMapping) {
public TestsDataset withInferenceEndpoint(boolean needsInference) {
return new TestsDataset(indexName, mappingFileName, dataFileName, settingFileName, allowSubFields, typeMapping, needsInference);
}

private Settings readSettingsFile() throws IOException {
Settings indexSettings = Settings.EMPTY;
final String settingName = settingFileName != null ? "/" + settingFileName : null;
if (settingName != null) {
indexSettings = Settings.builder()
.loadFromStream(settingName, CsvTestsDataLoader.class.getResourceAsStream(settingName), false)
.build();
}

return indexSettings;
}
}

public record EnrichConfig(String policyName, String policyFileName) {}
Expand Down

0 comments on commit 52a178b

Please sign in to comment.