Skip to content

Commit 0095f29

Browse files
authored
Remove TableInfo (#126090)
1 parent 28a544e commit 0095f29

File tree

6 files changed

+25
-55
lines changed

6 files changed

+25
-55
lines changed

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

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
package org.elasticsearch.xpack.esql.analysis;
99

1010
import org.elasticsearch.index.IndexMode;
11+
import org.elasticsearch.xpack.esql.plan.IndexPattern;
1112
import org.elasticsearch.xpack.esql.plan.logical.Enrich;
1213
import org.elasticsearch.xpack.esql.plan.logical.LogicalPlan;
1314
import org.elasticsearch.xpack.esql.plan.logical.UnresolvedRelation;
@@ -25,11 +26,11 @@ public class PreAnalyzer {
2526
public static class PreAnalysis {
2627
public static final PreAnalysis EMPTY = new PreAnalysis(emptyList(), emptyList(), emptyList());
2728

28-
public final List<TableInfo> indices;
29+
public final List<IndexPattern> indices;
2930
public final List<Enrich> enriches;
30-
public final List<TableInfo> lookupIndices;
31+
public final List<IndexPattern> lookupIndices;
3132

32-
public PreAnalysis(List<TableInfo> indices, List<Enrich> enriches, List<TableInfo> lookupIndices) {
33+
public PreAnalysis(List<IndexPattern> indices, List<Enrich> enriches, List<IndexPattern> lookupIndices) {
3334
this.indices = indices;
3435
this.enriches = enriches;
3536
this.lookupIndices = lookupIndices;
@@ -45,14 +46,11 @@ public PreAnalysis preAnalyze(LogicalPlan plan) {
4546
}
4647

4748
protected PreAnalysis doPreAnalyze(LogicalPlan plan) {
48-
List<TableInfo> indices = new ArrayList<>();
49+
List<IndexPattern> indices = new ArrayList<>();
4950
List<Enrich> unresolvedEnriches = new ArrayList<>();
50-
List<TableInfo> lookupIndices = new ArrayList<>();
51+
List<IndexPattern> lookupIndices = new ArrayList<>();
5152

52-
plan.forEachUp(UnresolvedRelation.class, p -> {
53-
List<TableInfo> list = p.indexMode() == IndexMode.LOOKUP ? lookupIndices : indices;
54-
list.add(new TableInfo(p.indexPattern()));
55-
});
53+
plan.forEachUp(UnresolvedRelation.class, p -> (p.indexMode() == IndexMode.LOOKUP ? lookupIndices : indices).add(p.indexPattern()));
5654
plan.forEachUp(Enrich.class, unresolvedEnriches::add);
5755

5856
// mark plan as preAnalyzed (if it were marked, there would be no analysis)

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

Lines changed: 0 additions & 23 deletions
This file was deleted.

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
import org.elasticsearch.xpack.esql.action.EsqlExecutionInfo;
2828
import org.elasticsearch.xpack.esql.action.EsqlExecutionInfo.Cluster;
2929
import org.elasticsearch.xpack.esql.analysis.Analyzer;
30-
import org.elasticsearch.xpack.esql.analysis.TableInfo;
3130
import org.elasticsearch.xpack.esql.index.IndexResolution;
31+
import org.elasticsearch.xpack.esql.plan.IndexPattern;
3232
import org.elasticsearch.xpack.esql.plan.logical.LogicalPlan;
3333

3434
import java.util.Collections;
@@ -276,15 +276,15 @@ static void updateExecutionInfoAtEndOfPlanning(EsqlExecutionInfo execInfo) {
276276
*/
277277
public static void checkForCcsLicense(
278278
EsqlExecutionInfo executionInfo,
279-
List<TableInfo> indices,
279+
List<IndexPattern> indices,
280280
IndicesExpressionGrouper indicesGrouper,
281281
Set<String> configuredClusters,
282282
XPackLicenseState licenseState
283283
) {
284-
for (TableInfo tableInfo : indices) {
284+
for (IndexPattern index : indices) {
285285
Map<String, OriginalIndices> groupedIndices;
286286
try {
287-
groupedIndices = indicesGrouper.groupIndices(configuredClusters, IndicesOptions.DEFAULT, tableInfo.id().indexPattern());
287+
groupedIndices = indicesGrouper.groupIndices(configuredClusters, IndicesOptions.DEFAULT, index.indexPattern());
288288
} catch (NoSuchRemoteClusterException e) {
289289
if (EsqlLicenseChecker.isCcsAllowed(licenseState)) {
290290
throw e;

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

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
import org.elasticsearch.xpack.esql.analysis.AnalyzerContext;
3333
import org.elasticsearch.xpack.esql.analysis.EnrichResolution;
3434
import org.elasticsearch.xpack.esql.analysis.PreAnalyzer;
35-
import org.elasticsearch.xpack.esql.analysis.TableInfo;
3635
import org.elasticsearch.xpack.esql.analysis.Verifier;
3736
import org.elasticsearch.xpack.esql.core.expression.Alias;
3837
import org.elasticsearch.xpack.esql.core.expression.Attribute;
@@ -356,23 +355,23 @@ public void analyzedPlan(
356355
)
357356
)
358357
.collect(Collectors.toSet());
359-
final List<TableInfo> indices = preAnalysis.indices;
358+
final List<IndexPattern> indices = preAnalysis.indices;
360359

361360
EsqlCCSUtils.checkForCcsLicense(executionInfo, indices, indicesExpressionGrouper, configuredClusters, verifier.licenseState());
362361

363362
final Set<String> targetClusters = enrichPolicyResolver.groupIndicesPerCluster(
364363
configuredClusters,
365364
indices.stream()
366-
.flatMap(t -> Arrays.stream(Strings.commaDelimitedListToStringArray(t.id().indexPattern())))
365+
.flatMap(index -> Arrays.stream(Strings.commaDelimitedListToStringArray(index.indexPattern())))
367366
.toArray(String[]::new)
368367
).keySet();
369368

370369
var listener = SubscribableListener.<EnrichResolution>newForked(
371370
l -> enrichPolicyResolver.resolvePolicies(targetClusters, unresolvedPolicies, l)
372371
).<PreAnalysisResult>andThen((l, enrichResolution) -> resolveFieldNames(parsed, enrichResolution, l));
373372
// first resolve the lookup indices, then the main indices
374-
for (TableInfo lookupIndex : preAnalysis.lookupIndices) {
375-
listener = listener.andThen((l, preAnalysisResult) -> { preAnalyzeLookupIndex(lookupIndex, preAnalysisResult, l); });
373+
for (var index : preAnalysis.lookupIndices) {
374+
listener = listener.andThen((l, preAnalysisResult) -> { preAnalyzeLookupIndex(index, preAnalysisResult, l); });
376375
}
377376
listener.<PreAnalysisResult>andThen((l, result) -> {
378377
// resolve the main indices
@@ -415,8 +414,7 @@ public void analyzedPlan(
415414
}).addListener(logicalPlanListener);
416415
}
417416

418-
private void preAnalyzeLookupIndex(TableInfo tableInfo, PreAnalysisResult result, ActionListener<PreAnalysisResult> listener) {
419-
IndexPattern table = tableInfo.id();
417+
private void preAnalyzeLookupIndex(IndexPattern table, PreAnalysisResult result, ActionListener<PreAnalysisResult> listener) {
420418
Set<String> fieldNames = result.wildcardJoinIndices().contains(table.indexPattern()) ? IndexResolver.ALL_FIELDS : result.fieldNames;
421419
// call the EsqlResolveFieldsAction (field-caps) to resolve indices and get field types
422420
indexResolver.resolveAsMergedMapping(
@@ -429,7 +427,7 @@ private void preAnalyzeLookupIndex(TableInfo tableInfo, PreAnalysisResult result
429427
}
430428

431429
private void preAnalyzeIndices(
432-
List<TableInfo> indices,
430+
List<IndexPattern> indices,
433431
EsqlExecutionInfo executionInfo,
434432
PreAnalysisResult result,
435433
QueryBuilder requestFilter,
@@ -442,8 +440,7 @@ private void preAnalyzeIndices(
442440
} else if (indices.size() == 1) {
443441
// known to be unavailable from the enrich policy API call
444442
Map<String, Exception> unavailableClusters = result.enrichResolution.getUnavailableClusters();
445-
TableInfo tableInfo = indices.get(0);
446-
IndexPattern table = tableInfo.id();
443+
IndexPattern table = indices.getFirst();
447444

448445
Map<String, OriginalIndices> clusterIndices = indicesExpressionGrouper.groupIndices(
449446
configuredClusters,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ private static CsvTestsDataLoader.MultiIndexTestDataset testDatasets(LogicalPlan
498498
throw new IllegalArgumentException("unexpected index resolution to multiple entries [" + preAnalysis.indices.size() + "]");
499499
}
500500

501-
String indexName = indices.get(0).id().indexPattern();
501+
String indexName = indices.getFirst().indexPattern();
502502
List<CsvTestsDataLoader.TestDataset> datasets = new ArrayList<>();
503503
if (indexName.endsWith("*")) {
504504
String indexPrefix = indexName.substring(0, indexName.length() - 1);

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

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import org.elasticsearch.transport.RemoteTransportException;
3131
import org.elasticsearch.xpack.esql.VerificationException;
3232
import org.elasticsearch.xpack.esql.action.EsqlExecutionInfo;
33-
import org.elasticsearch.xpack.esql.analysis.TableInfo;
3433
import org.elasticsearch.xpack.esql.core.type.EsField;
3534
import org.elasticsearch.xpack.esql.index.EsIndex;
3635
import org.elasticsearch.xpack.esql.index.IndexResolution;
@@ -709,8 +708,7 @@ public void testCheckForCcsLicense() {
709708

710709
// local only search does not require an enterprise license
711710
{
712-
List<TableInfo> indices = new ArrayList<>();
713-
indices.add(new TableInfo(new IndexPattern(EMPTY, randomFrom("idx", "idx1,idx2*"))));
711+
List<IndexPattern> indices = List.of(new IndexPattern(EMPTY, randomFrom("idx", "idx1,idx2*")));
714712

715713
checkForCcsLicense(executionInfo, indices, indicesGrouper, Set.of(), enterpriseLicenseValid);
716714
checkForCcsLicense(executionInfo, indices, indicesGrouper, Set.of(), platinumLicenseValid);
@@ -732,13 +730,13 @@ public void testCheckForCcsLicense() {
732730

733731
// cross-cluster search requires a valid (active, non-expired) enterprise license OR a valid trial license
734732
{
735-
List<TableInfo> indices = new ArrayList<>();
733+
List<IndexPattern> indices = new ArrayList<>();
736734
final String indexExprWithRemotes = randomFrom("remote:idx", "idx1,remote:idx2*,remote:logs,c*:idx4");
737735
if (randomBoolean()) {
738-
indices.add(new TableInfo(new IndexPattern(EMPTY, indexExprWithRemotes)));
736+
indices.add(new IndexPattern(EMPTY, indexExprWithRemotes));
739737
} else {
740-
indices.add(new TableInfo(new IndexPattern(EMPTY, randomFrom("idx", "idx1,idx2*"))));
741-
indices.add(new TableInfo(new IndexPattern(EMPTY, indexExprWithRemotes)));
738+
indices.add(new IndexPattern(EMPTY, randomFrom("idx", "idx1,idx2*")));
739+
indices.add(new IndexPattern(EMPTY, indexExprWithRemotes));
742740
}
743741

744742
// licenses that work
@@ -804,7 +802,7 @@ private XPackLicenseStatus inactiveLicenseStatus(License.OperationMode operation
804802
}
805803

806804
private void assertLicenseCheckFails(
807-
List<TableInfo> indices,
805+
List<IndexPattern> indices,
808806
TestIndicesExpressionGrouper indicesGrouper,
809807
XPackLicenseState licenseState,
810808
String expectedErrorMessageSuffix

0 commit comments

Comments
 (0)