Skip to content

Commit 5f92ace

Browse files
committed
Remove TableInfo
1 parent 69f388c commit 5f92ace

File tree

5 files changed

+27
-54
lines changed

5 files changed

+27
-54
lines changed

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

Lines changed: 10 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,14 @@ 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(
54+
UnresolvedRelation.class,
55+
p -> { (p.indexMode() == IndexMode.LOOKUP ? lookupIndices : indices).add(p.indexPattern()); }
56+
);
5657
plan.forEachUp(Enrich.class, unresolvedEnriches::add);
5758

5859
// 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,14 +276,14 @@ 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
XPackLicenseState licenseState
282282
) {
283-
for (TableInfo tableInfo : indices) {
283+
for (IndexPattern index : indices) {
284284
Map<String, OriginalIndices> groupedIndices;
285285
try {
286-
groupedIndices = indicesGrouper.groupIndices(IndicesOptions.DEFAULT, tableInfo.id().indexPattern());
286+
groupedIndices = indicesGrouper.groupIndices(IndicesOptions.DEFAULT, index.indexPattern());
287287
} catch (NoSuchRemoteClusterException e) {
288288
if (EsqlLicenseChecker.isCcsAllowed(licenseState)) {
289289
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;
@@ -353,22 +352,22 @@ public void analyzedPlan(
353352
)
354353
)
355354
.collect(Collectors.toSet());
356-
final List<TableInfo> indices = preAnalysis.indices;
355+
final List<IndexPattern> indices = preAnalysis.indices;
357356

358357
EsqlCCSUtils.checkForCcsLicense(executionInfo, indices, indicesExpressionGrouper, verifier.licenseState());
359358

360359
final Set<String> targetClusters = enrichPolicyResolver.groupIndicesPerCluster(
361360
indices.stream()
362-
.flatMap(t -> Arrays.stream(Strings.commaDelimitedListToStringArray(t.id().indexPattern())))
361+
.flatMap(index -> Arrays.stream(Strings.commaDelimitedListToStringArray(index.indexPattern())))
363362
.toArray(String[]::new)
364363
).keySet();
365364

366365
var listener = SubscribableListener.<EnrichResolution>newForked(
367366
l -> enrichPolicyResolver.resolvePolicies(targetClusters, unresolvedPolicies, l)
368367
).<PreAnalysisResult>andThen((l, enrichResolution) -> resolveFieldNames(parsed, enrichResolution, l));
369368
// first resolve the lookup indices, then the main indices
370-
for (TableInfo lookupIndex : preAnalysis.lookupIndices) {
371-
listener = listener.andThen((l, preAnalysisResult) -> { preAnalyzeLookupIndex(lookupIndex, preAnalysisResult, l); });
369+
for (var index : preAnalysis.lookupIndices) {
370+
listener = listener.andThen((l, preAnalysisResult) -> { preAnalyzeLookupIndex(index, preAnalysisResult, l); });
372371
}
373372
listener.<PreAnalysisResult>andThen((l, result) -> {
374373
// resolve the main indices
@@ -411,8 +410,7 @@ public void analyzedPlan(
411410
}).addListener(logicalPlanListener);
412411
}
413412

414-
private void preAnalyzeLookupIndex(TableInfo tableInfo, PreAnalysisResult result, ActionListener<PreAnalysisResult> listener) {
415-
IndexPattern table = tableInfo.id();
413+
private void preAnalyzeLookupIndex(IndexPattern table, PreAnalysisResult result, ActionListener<PreAnalysisResult> listener) {
416414
Set<String> fieldNames = result.wildcardJoinIndices().contains(table.indexPattern()) ? IndexResolver.ALL_FIELDS : result.fieldNames;
417415
// call the EsqlResolveFieldsAction (field-caps) to resolve indices and get field types
418416
indexResolver.resolveAsMergedMapping(
@@ -425,7 +423,7 @@ private void preAnalyzeLookupIndex(TableInfo tableInfo, PreAnalysisResult result
425423
}
426424

427425
private void preAnalyzeIndices(
428-
List<TableInfo> indices,
426+
List<IndexPattern> indices,
429427
EsqlExecutionInfo executionInfo,
430428
PreAnalysisResult result,
431429
QueryBuilder requestFilter,
@@ -438,8 +436,7 @@ private void preAnalyzeIndices(
438436
} else if (indices.size() == 1) {
439437
// known to be unavailable from the enrich policy API call
440438
Map<String, Exception> unavailableClusters = result.enrichResolution.getUnavailableClusters();
441-
TableInfo tableInfo = indices.get(0);
442-
IndexPattern table = tableInfo.id();
439+
IndexPattern table = indices.getFirst();
443440

444441
Map<String, OriginalIndices> clusterIndices = indicesExpressionGrouper.groupIndices(
445442
IndicesOptions.DEFAULT,

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, enterpriseLicenseValid);
716714
checkForCcsLicense(executionInfo, indices, indicesGrouper, 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)