Skip to content

Commit 3104c5b

Browse files
committed
Fix compile error
1 parent e8233fb commit 3104c5b

File tree

12 files changed

+173
-99
lines changed

12 files changed

+173
-99
lines changed

benchmarks/src/main/java/org/elasticsearch/benchmark/_nightly/esql/QueryPlanningBenchmark.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import org.elasticsearch.xpack.esql.analysis.EnrichResolution;
1919
import org.elasticsearch.xpack.esql.analysis.Verifier;
2020
import org.elasticsearch.xpack.esql.core.expression.FoldContext;
21+
import org.elasticsearch.xpack.esql.core.tree.Source;
2122
import org.elasticsearch.xpack.esql.core.type.EsField;
2223
import org.elasticsearch.xpack.esql.core.util.DateUtils;
2324
import org.elasticsearch.xpack.esql.expression.function.EsqlFunctionRegistry;
@@ -28,6 +29,7 @@
2829
import org.elasticsearch.xpack.esql.optimizer.LogicalPlanOptimizer;
2930
import org.elasticsearch.xpack.esql.parser.EsqlParser;
3031
import org.elasticsearch.xpack.esql.parser.QueryParams;
32+
import org.elasticsearch.xpack.esql.plan.IndexPattern;
3133
import org.elasticsearch.xpack.esql.plan.logical.LogicalPlan;
3234
import org.elasticsearch.xpack.esql.plugin.EsqlPlugin;
3335
import org.elasticsearch.xpack.esql.plugin.QueryPragmas;
@@ -108,7 +110,7 @@ public void setup() {
108110
new AnalyzerContext(
109111
config,
110112
functionRegistry,
111-
IndexResolution.valid(esIndex),
113+
Map.of(new IndexPattern(Source.EMPTY, esIndex.name()), IndexResolution.valid(esIndex)),
112114
Map.of(),
113115
new EnrichResolution(),
114116
InferenceResolution.EMPTY

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/analysis/AnalyzerContext.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
package org.elasticsearch.xpack.esql.analysis;
99

10+
import org.elasticsearch.xpack.esql.core.tree.Source;
1011
import org.elasticsearch.xpack.esql.expression.function.EsqlFunctionRegistry;
1112
import org.elasticsearch.xpack.esql.index.IndexResolution;
1213
import org.elasticsearch.xpack.esql.inference.InferenceResolution;
@@ -34,4 +35,21 @@ public AnalyzerContext(
3435
) {
3536
this(configuration, functionRegistry, indexResolution, Map.of(), enrichResolution, inferenceResolution);
3637
}
38+
39+
public AnalyzerContext(
40+
Configuration configuration,
41+
EsqlFunctionRegistry functionRegistry,
42+
IndexResolution indexResolution,
43+
EnrichResolution enrichResolution,
44+
InferenceResolution inferenceResolution
45+
) {
46+
this(
47+
configuration,
48+
functionRegistry,
49+
Map.of(new IndexPattern(Source.EMPTY, indexResolution.get().name()), indexResolution),
50+
Map.of(),
51+
enrichResolution,
52+
inferenceResolution
53+
);
54+
}
3755
}

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/session/EsqlCCSUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ static String createIndexExpressionFromAvailableClusters(String indexPattern, Es
162162
EsqlExecutionInfo.Cluster cluster = executionInfo.getCluster(clusterAlias);
163163
// Exclude clusters which are either skipped or have no indices matching wildcard, or filtered out.
164164
if (cluster.getStatus() != Cluster.Status.SKIPPED && cluster.getStatus() != Cluster.Status.SUCCESSFUL) {
165-
if (cluster.getIndexExpression().contains(indexPattern)) {
165+
if (indexPattern.equals("*") || cluster.getIndexExpression().contains(indexPattern)) {
166166
if (sb.isEmpty() == false) {
167167
sb.append(',');
168168
}

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/CsvTests.java

Lines changed: 57 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
import org.elasticsearch.xpack.esql.analysis.PreAnalyzer;
5959
import org.elasticsearch.xpack.esql.core.expression.Attribute;
6060
import org.elasticsearch.xpack.esql.core.expression.FoldContext;
61+
import org.elasticsearch.xpack.esql.core.tree.Source;
6162
import org.elasticsearch.xpack.esql.core.type.DataType;
6263
import org.elasticsearch.xpack.esql.core.type.EsField;
6364
import org.elasticsearch.xpack.esql.core.type.InvalidMappedField;
@@ -77,6 +78,7 @@
7778
import org.elasticsearch.xpack.esql.optimizer.LogicalPreOptimizerContext;
7879
import org.elasticsearch.xpack.esql.optimizer.TestLocalPhysicalPlanOptimizer;
7980
import org.elasticsearch.xpack.esql.parser.EsqlParser;
81+
import org.elasticsearch.xpack.esql.plan.IndexPattern;
8082
import org.elasticsearch.xpack.esql.plan.logical.Enrich;
8183
import org.elasticsearch.xpack.esql.plan.logical.LogicalPlan;
8284
import org.elasticsearch.xpack.esql.plan.physical.ChangePointExec;
@@ -418,6 +420,16 @@ protected void assertResults(ExpectedResults expected, ActualResults actual, boo
418420
CsvAssert.assertResults(expected, actual, ignoreOrder, logger);
419421
}
420422

423+
private static Map<IndexPattern, IndexResolution> loadIndexResolution(
424+
Map<IndexPattern, CsvTestsDataLoader.MultiIndexTestDataset> datasets
425+
) {
426+
Map<IndexPattern, IndexResolution> indexResolutions = new HashMap<>();
427+
for (var entry : datasets.entrySet()) {
428+
indexResolutions.put(entry.getKey(), loadIndexResolution(entry.getValue()));
429+
}
430+
return indexResolutions;
431+
}
432+
421433
private static IndexResolution loadIndexResolution(CsvTestsDataLoader.MultiIndexTestDataset datasets) {
422434
var indexNames = datasets.datasets().stream().map(CsvTestsDataLoader.TestDataset::indexName);
423435
Map<String, IndexMode> indexModes = indexNames.collect(Collectors.toMap(x -> x, x -> IndexMode.STANDARD));
@@ -537,7 +549,7 @@ private static EnrichPolicy loadEnrichPolicyMapping(String policyFileName) {
537549
}
538550
}
539551

540-
private LogicalPlan analyzedPlan(LogicalPlan parsed, CsvTestsDataLoader.MultiIndexTestDataset datasets) {
552+
private LogicalPlan analyzedPlan(LogicalPlan parsed, Map<IndexPattern, CsvTestsDataLoader.MultiIndexTestDataset> datasets) {
541553
var indexResolution = loadIndexResolution(datasets);
542554
var enrichPolicies = loadEnrichPolicies();
543555
var analyzer = new Analyzer(
@@ -564,46 +576,65 @@ private LogicalPlan resolveViews(LogicalPlan parsed) {
564576
return viewService.replaceViews(parsed, new PlanTelemetry(functionRegistry), configuration);
565577
}
566578

567-
private CsvTestsDataLoader.MultiIndexTestDataset testDatasets(LogicalPlan parsed) {
579+
private Map<IndexPattern, CsvTestsDataLoader.MultiIndexTestDataset> testDatasets(LogicalPlan parsed) {
568580
var preAnalysis = new PreAnalyzer().preAnalyze(parsed);
569-
if (preAnalysis.indexPattern() == null) {
581+
if (preAnalysis.indexes().isEmpty()) {
570582
// If the data set doesn't matter we'll just grab one we know works. Employees is fine.
571-
return CsvTestsDataLoader.MultiIndexTestDataset.of(CSV_DATASET_MAP.get("employees"));
583+
return Map.of(
584+
new IndexPattern(Source.EMPTY, "employees"),
585+
CsvTestsDataLoader.MultiIndexTestDataset.of(CSV_DATASET_MAP.get("employees"))
586+
);
572587
}
573588

574-
String indexName = preAnalysis.indexPattern().indexPattern();
575-
List<CsvTestsDataLoader.TestDataset> datasets = new ArrayList<>();
576-
if (indexName.endsWith("*")) {
577-
String indexPrefix = indexName.substring(0, indexName.length() - 1);
578-
for (var entry : CSV_DATASET_MAP.entrySet()) {
579-
if (entry.getKey().startsWith(indexPrefix)) {
580-
datasets.add(entry.getValue());
589+
List<String> missing = new ArrayList<>();
590+
Map<IndexPattern, CsvTestsDataLoader.MultiIndexTestDataset> all = new HashMap<>();
591+
for (IndexPattern indexPattern : preAnalysis.indexes().keySet()) {
592+
List<CsvTestsDataLoader.TestDataset> datasets = new ArrayList<>();
593+
String indexName = indexPattern.indexPattern();
594+
if (indexName.endsWith("*")) {
595+
String indexPrefix = indexName.substring(0, indexName.length() - 1);
596+
for (var entry : CSV_DATASET_MAP.entrySet()) {
597+
if (entry.getKey().startsWith(indexPrefix)) {
598+
datasets.add(entry.getValue());
599+
}
581600
}
582-
}
583-
} else {
584-
for (String index : indexName.split(",")) {
585-
var dataset = CSV_DATASET_MAP.get(index);
586-
if (dataset == null) {
587-
throw new IllegalArgumentException("unknown CSV dataset for table [" + index + "]");
601+
} else {
602+
for (String index : indexName.split(",")) {
603+
var dataset = CSV_DATASET_MAP.get(index);
604+
if (dataset == null) {
605+
throw new IllegalArgumentException("unknown CSV dataset for table [" + index + "]");
606+
}
607+
datasets.add(dataset);
588608
}
589-
datasets.add(dataset);
609+
}
610+
if (datasets.isEmpty() == false) {
611+
all.put(indexPattern, new CsvTestsDataLoader.MultiIndexTestDataset(indexName, datasets));
612+
} else {
613+
missing.add(indexName);
590614
}
591615
}
592-
if (datasets.isEmpty()) {
593-
throw new IllegalArgumentException("unknown CSV dataset for table [" + indexName + "]");
616+
if (all.isEmpty()) {
617+
throw new IllegalArgumentException("Found no CSV datasets for table [" + preAnalysis.indexes() + "]");
594618
}
595-
return new CsvTestsDataLoader.MultiIndexTestDataset(indexName, datasets);
619+
if (missing.isEmpty() == false) {
620+
throw new IllegalArgumentException("Did not find datasets for tables: " + missing);
621+
}
622+
return all;
596623
}
597624

598625
private static TestPhysicalOperationProviders testOperationProviders(
599626
FoldContext foldCtx,
600-
CsvTestsDataLoader.MultiIndexTestDataset datasets
627+
Map<IndexPattern, CsvTestsDataLoader.MultiIndexTestDataset> allDatasets
601628
) throws Exception {
602629
var indexPages = new ArrayList<TestPhysicalOperationProviders.IndexPage>();
603-
for (CsvTestsDataLoader.TestDataset dataset : datasets.datasets()) {
604-
var testData = loadPageFromCsv(CsvTests.class.getResource("/data/" + dataset.dataFileName()), dataset.typeMapping());
605-
Set<String> mappedFields = loadMapping(dataset.mappingFileName()).keySet();
606-
indexPages.add(new TestPhysicalOperationProviders.IndexPage(dataset.indexName(), testData.v1(), testData.v2(), mappedFields));
630+
for (CsvTestsDataLoader.MultiIndexTestDataset datasets : allDatasets.values()) {
631+
for (CsvTestsDataLoader.TestDataset dataset : datasets.datasets()) {
632+
var testData = loadPageFromCsv(CsvTests.class.getResource("/data/" + dataset.dataFileName()), dataset.typeMapping());
633+
Set<String> mappedFields = loadMapping(dataset.mappingFileName()).keySet();
634+
indexPages.add(
635+
new TestPhysicalOperationProviders.IndexPage(dataset.indexName(), testData.v1(), testData.v2(), mappedFields)
636+
);
637+
}
607638
}
608639
return TestPhysicalOperationProviders.create(foldCtx, indexPages);
609640
}

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/analysis/AnalyzerTestUtils.java

Lines changed: 45 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import org.elasticsearch.test.ESTestCase;
1313
import org.elasticsearch.xpack.core.enrich.EnrichPolicy;
1414
import org.elasticsearch.xpack.esql.EsqlTestUtils;
15+
import org.elasticsearch.xpack.esql.core.tree.Source;
1516
import org.elasticsearch.xpack.esql.core.type.EsField;
1617
import org.elasticsearch.xpack.esql.core.type.InvalidMappedField;
1718
import org.elasticsearch.xpack.esql.enrich.ResolvedEnrichPolicy;
@@ -22,12 +23,14 @@
2223
import org.elasticsearch.xpack.esql.inference.ResolvedInference;
2324
import org.elasticsearch.xpack.esql.parser.EsqlParser;
2425
import org.elasticsearch.xpack.esql.parser.QueryParams;
26+
import org.elasticsearch.xpack.esql.plan.IndexPattern;
2527
import org.elasticsearch.xpack.esql.plan.logical.Enrich;
2628
import org.elasticsearch.xpack.esql.plan.logical.LogicalPlan;
2729
import org.elasticsearch.xpack.esql.session.Configuration;
2830

2931
import java.util.ArrayList;
3032
import java.util.Arrays;
33+
import java.util.HashMap;
3134
import java.util.LinkedHashMap;
3235
import java.util.List;
3336
import java.util.Map;
@@ -47,7 +50,7 @@ public final class AnalyzerTestUtils {
4750
private AnalyzerTestUtils() {}
4851

4952
public static Analyzer defaultAnalyzer() {
50-
return analyzer(analyzerDefaultMapping());
53+
return analyzer(analyzerDefaultMapping().values().iterator().next());
5154
}
5255

5356
public static Analyzer expandedDefaultAnalyzer() {
@@ -76,11 +79,11 @@ public static Analyzer analyzer(
7679
EnrichResolution enrichResolution,
7780
Verifier verifier
7881
) {
79-
return analyzer(indexResolution, lookupResolution, enrichResolution, verifier, TEST_CFG);
82+
return analyzer(indexResolutions(indexResolution), lookupResolution, enrichResolution, verifier, TEST_CFG);
8083
}
8184

8285
public static Analyzer analyzer(
83-
IndexResolution indexResolution,
86+
Map<IndexPattern, IndexResolution> indexResolutions,
8487
Map<String, IndexResolution> lookupResolution,
8588
EnrichResolution enrichResolution,
8689
Verifier verifier,
@@ -90,18 +93,26 @@ public static Analyzer analyzer(
9093
new AnalyzerContext(
9194
config,
9295
new EsqlFunctionRegistry(),
93-
indexResolution,
96+
mergeIndexResolutions(indexResolutions, defaultSubqueryResolution()),
9497
lookupResolution,
9598
enrichResolution,
96-
defaultInferenceResolution(),
97-
defaultSubqueryResolution()
99+
defaultInferenceResolution()
98100
),
99101
verifier
100102
);
101103
}
102104

103-
public static Analyzer analyzer(IndexResolution indexResolution, Verifier verifier, Configuration config) {
104-
return analyzer(indexResolution, defaultLookupResolution(), defaultEnrichResolution(), verifier, config);
105+
private static Map<IndexPattern, IndexResolution> mergeIndexResolutions(
106+
Map<IndexPattern, IndexResolution> indexResolutions,
107+
Map<IndexPattern, IndexResolution> more
108+
) {
109+
Map<IndexPattern, IndexResolution> combined = new HashMap<>(indexResolutions);
110+
indexResolutions.putAll(more);
111+
return combined;
112+
}
113+
114+
public static Analyzer analyzer(Map<IndexPattern, IndexResolution> indexResolutions, Verifier verifier, Configuration config) {
115+
return analyzer(indexResolutions, defaultLookupResolution(), defaultEnrichResolution(), verifier, config);
105116
}
106117

107118
public static Analyzer analyzer(Verifier verifier) {
@@ -127,7 +138,8 @@ public static LogicalPlan analyze(String query, String mapping) {
127138
}
128139

129140
public static LogicalPlan analyze(String query, String index, String mapping) {
130-
return analyze(query, analyzer(loadMapping(mapping, index), TEST_VERIFIER, configuration(query)));
141+
var indexResolutions = Map.of(new IndexPattern(Source.EMPTY, index), loadMapping(mapping, index));
142+
return analyze(query, analyzer(indexResolutions, TEST_VERIFIER, configuration(query)));
131143
}
132144

133145
public static LogicalPlan analyze(String query, Analyzer analyzer) {
@@ -140,7 +152,8 @@ public static LogicalPlan analyze(String query, Analyzer analyzer) {
140152

141153
public static LogicalPlan analyze(String query, String mapping, QueryParams params) {
142154
var plan = new EsqlParser().createStatement(query, params, configuration(query));
143-
var analyzer = analyzer(loadMapping(mapping, "test"), TEST_VERIFIER, configuration(query));
155+
var indexResolutions = Map.of(new IndexPattern(Source.EMPTY, "test"), loadMapping(mapping, "test"));
156+
var analyzer = analyzer(indexResolutions, TEST_VERIFIER, configuration(query));
144157
return analyzer.analyze(plan);
145158
}
146159

@@ -154,8 +167,24 @@ public static IndexResolution loadMapping(String resource, String indexName) {
154167
return IndexResolution.valid(test);
155168
}
156169

157-
public static IndexResolution analyzerDefaultMapping() {
158-
return loadMapping("mapping-basic.json", "test");
170+
public static Map<IndexPattern, IndexResolution> analyzerDefaultMapping() {
171+
return Map.of(new IndexPattern(Source.EMPTY, "test"), loadMapping("mapping-basic.json", "test"));
172+
}
173+
174+
public static Map<IndexPattern, IndexResolution> indexResolutions(EsIndex... indexes) {
175+
Map<IndexPattern, IndexResolution> map = new HashMap<>();
176+
for (EsIndex index : indexes) {
177+
map.put(new IndexPattern(Source.EMPTY, index.name()), IndexResolution.valid(index));
178+
}
179+
return map;
180+
}
181+
182+
public static Map<IndexPattern, IndexResolution> indexResolutions(IndexResolution... indexes) {
183+
Map<IndexPattern, IndexResolution> map = new HashMap<>();
184+
for (IndexResolution index : indexes) {
185+
map.put(new IndexPattern(Source.EMPTY, index.get().name()), index);
186+
}
187+
return map;
159188
}
160189

161190
public static IndexResolution expandedDefaultIndexResolution() {
@@ -223,13 +252,13 @@ public static InferenceResolution defaultInferenceResolution() {
223252
.build();
224253
}
225254

226-
public static Map<String, IndexResolution> defaultSubqueryResolution() {
255+
public static Map<IndexPattern, IndexResolution> defaultSubqueryResolution() {
227256
return Map.of(
228-
"languages",
257+
new IndexPattern(Source.EMPTY, "languages"),
229258
loadMapping("mapping-languages.json", "languages"),
230-
"sample_data",
259+
new IndexPattern(Source.EMPTY, "sample_data"),
231260
loadMapping("mapping-sample_data.json", "sample_data"),
232-
"test_mixed_types",
261+
new IndexPattern(Source.EMPTY, "test_mixed_types"),
233262
loadMapping("mapping-default-incompatible.json", "test_mixed_types")
234263
);
235264
}

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/analysis/AnalyzerTests.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@
133133
import static org.elasticsearch.xpack.esql.analysis.AnalyzerTestUtils.analyzerDefaultMapping;
134134
import static org.elasticsearch.xpack.esql.analysis.AnalyzerTestUtils.defaultEnrichResolution;
135135
import static org.elasticsearch.xpack.esql.analysis.AnalyzerTestUtils.defaultInferenceResolution;
136+
import static org.elasticsearch.xpack.esql.analysis.AnalyzerTestUtils.indexResolutions;
136137
import static org.elasticsearch.xpack.esql.analysis.AnalyzerTestUtils.indexWithDateDateNanosUnionType;
137138
import static org.elasticsearch.xpack.esql.analysis.AnalyzerTestUtils.loadMapping;
138139
import static org.elasticsearch.xpack.esql.analysis.AnalyzerTestUtils.randomInferenceIdOtherThan;
@@ -1684,7 +1685,7 @@ public void testEnrichPolicyWithError() {
16841685
AnalyzerContext context = new AnalyzerContext(
16851686
configuration("from test"),
16861687
new EsqlFunctionRegistry(),
1687-
testIndex,
1688+
indexResolutions(testIndex),
16881689
enrichResolution,
16891690
emptyInferenceResolution()
16901691
);
@@ -1840,7 +1841,7 @@ public void testEnrichFieldsIncludeMatchField() {
18401841
AnalyzerContext context = new AnalyzerContext(
18411842
configuration(query),
18421843
new EsqlFunctionRegistry(),
1843-
testIndex,
1844+
indexResolutions(testIndex),
18441845
enrichResolution,
18451846
emptyInferenceResolution()
18461847
);
@@ -3169,7 +3170,7 @@ public void testResolveInsist_multiIndexFieldPartiallyMappedWithSingleKeywordTyp
31693170
);
31703171

31713172
String query = "FROM foo, bar | INSIST_🐔 message";
3172-
var plan = analyze(query, analyzer(resolution, TEST_VERIFIER, configuration(query)));
3173+
var plan = analyze(query, analyzer(indexResolutions(resolution), TEST_VERIFIER, configuration(query)));
31733174
var limit = as(plan, Limit.class);
31743175
var insist = as(limit.child(), Insist.class);
31753176
var attribute = (FieldAttribute) EsqlTestUtils.singleValue(insist.output());
@@ -3807,7 +3808,7 @@ private static LogicalPlan analyzeWithEmptyFieldCapsResponse(String query) throw
38073808
);
38083809
IndexResolver.FieldsInfo caps = new IndexResolver.FieldsInfo(new FieldCapabilitiesResponse(idxResponses, List.of()), true, true);
38093810
IndexResolution resolution = IndexResolver.mergedMappings("test*", caps);
3810-
var analyzer = analyzer(resolution, TEST_VERIFIER, configuration(query));
3811+
var analyzer = analyzer(indexResolutions(resolution), TEST_VERIFIER, configuration(query));
38113812
return analyze(query, analyzer);
38123813
}
38133814

@@ -5038,12 +5039,11 @@ public void testImplicitCastingForAggregateMetricDouble() {
50385039
Map.of("k8s", IndexMode.TIME_SERIES, "k8s-downsampled", IndexMode.TIME_SERIES),
50395040
Set.of()
50405041
);
5041-
var indexResolution = IndexResolution.valid(esIndex);
50425042
var analyzer = new Analyzer(
50435043
new AnalyzerContext(
50445044
EsqlTestUtils.TEST_CFG,
50455045
new EsqlFunctionRegistry(),
5046-
indexResolution,
5046+
indexResolutions(esIndex),
50475047
defaultEnrichResolution(),
50485048
defaultInferenceResolution()
50495049
),

0 commit comments

Comments
 (0)