From 5f92aced8b52f982c0d4cc3cffb6501e2e4a7a89 Mon Sep 17 00:00:00 2001 From: "ievgen.degtiarenko" Date: Wed, 2 Apr 2025 09:03:12 +0200 Subject: [PATCH 1/4] Remove TableInfo --- .../xpack/esql/analysis/PreAnalyzer.java | 19 +++++++-------- .../xpack/esql/analysis/TableInfo.java | 23 ------------------- .../xpack/esql/session/EsqlCCSUtils.java | 8 +++---- .../xpack/esql/session/EsqlSession.java | 17 ++++++-------- .../xpack/esql/session/EsqlCCSUtilsTests.java | 14 +++++------ 5 files changed, 27 insertions(+), 54 deletions(-) delete mode 100644 x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/analysis/TableInfo.java diff --git a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/analysis/PreAnalyzer.java b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/analysis/PreAnalyzer.java index 9aa8afac45c54..9dfb0dec5e140 100644 --- a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/analysis/PreAnalyzer.java +++ b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/analysis/PreAnalyzer.java @@ -8,6 +8,7 @@ package org.elasticsearch.xpack.esql.analysis; import org.elasticsearch.index.IndexMode; +import org.elasticsearch.xpack.esql.plan.IndexPattern; import org.elasticsearch.xpack.esql.plan.logical.Enrich; import org.elasticsearch.xpack.esql.plan.logical.LogicalPlan; import org.elasticsearch.xpack.esql.plan.logical.UnresolvedRelation; @@ -25,11 +26,11 @@ public class PreAnalyzer { public static class PreAnalysis { public static final PreAnalysis EMPTY = new PreAnalysis(emptyList(), emptyList(), emptyList()); - public final List indices; + public final List indices; public final List enriches; - public final List lookupIndices; + public final List lookupIndices; - public PreAnalysis(List indices, List enriches, List lookupIndices) { + public PreAnalysis(List indices, List enriches, List lookupIndices) { this.indices = indices; this.enriches = enriches; this.lookupIndices = lookupIndices; @@ -45,14 +46,14 @@ public PreAnalysis preAnalyze(LogicalPlan plan) { } protected PreAnalysis doPreAnalyze(LogicalPlan plan) { - List indices = new ArrayList<>(); + List indices = new ArrayList<>(); List unresolvedEnriches = new ArrayList<>(); - List lookupIndices = new ArrayList<>(); + List lookupIndices = new ArrayList<>(); - plan.forEachUp(UnresolvedRelation.class, p -> { - List list = p.indexMode() == IndexMode.LOOKUP ? lookupIndices : indices; - list.add(new TableInfo(p.indexPattern())); - }); + plan.forEachUp( + UnresolvedRelation.class, + p -> { (p.indexMode() == IndexMode.LOOKUP ? lookupIndices : indices).add(p.indexPattern()); } + ); plan.forEachUp(Enrich.class, unresolvedEnriches::add); // mark plan as preAnalyzed (if it were marked, there would be no analysis) diff --git a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/analysis/TableInfo.java b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/analysis/TableInfo.java deleted file mode 100644 index 38d368bd2bfad..0000000000000 --- a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/analysis/TableInfo.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -package org.elasticsearch.xpack.esql.analysis; - -import org.elasticsearch.xpack.esql.plan.IndexPattern; - -public class TableInfo { - - private final IndexPattern id; - - public TableInfo(IndexPattern id) { - this.id = id; - } - - public IndexPattern id() { - return id; - } -} diff --git a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/session/EsqlCCSUtils.java b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/session/EsqlCCSUtils.java index 3a2db609d6c8a..a806cb59ad4a8 100644 --- a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/session/EsqlCCSUtils.java +++ b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/session/EsqlCCSUtils.java @@ -27,8 +27,8 @@ import org.elasticsearch.xpack.esql.action.EsqlExecutionInfo; import org.elasticsearch.xpack.esql.action.EsqlExecutionInfo.Cluster; import org.elasticsearch.xpack.esql.analysis.Analyzer; -import org.elasticsearch.xpack.esql.analysis.TableInfo; import org.elasticsearch.xpack.esql.index.IndexResolution; +import org.elasticsearch.xpack.esql.plan.IndexPattern; import org.elasticsearch.xpack.esql.plan.logical.LogicalPlan; import java.util.Collections; @@ -276,14 +276,14 @@ static void updateExecutionInfoAtEndOfPlanning(EsqlExecutionInfo execInfo) { */ public static void checkForCcsLicense( EsqlExecutionInfo executionInfo, - List indices, + List indices, IndicesExpressionGrouper indicesGrouper, XPackLicenseState licenseState ) { - for (TableInfo tableInfo : indices) { + for (IndexPattern index : indices) { Map groupedIndices; try { - groupedIndices = indicesGrouper.groupIndices(IndicesOptions.DEFAULT, tableInfo.id().indexPattern()); + groupedIndices = indicesGrouper.groupIndices(IndicesOptions.DEFAULT, index.indexPattern()); } catch (NoSuchRemoteClusterException e) { if (EsqlLicenseChecker.isCcsAllowed(licenseState)) { throw e; diff --git a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/session/EsqlSession.java b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/session/EsqlSession.java index 2efed443c9aa9..016fbb23d0c12 100644 --- a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/session/EsqlSession.java +++ b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/session/EsqlSession.java @@ -32,7 +32,6 @@ import org.elasticsearch.xpack.esql.analysis.AnalyzerContext; import org.elasticsearch.xpack.esql.analysis.EnrichResolution; import org.elasticsearch.xpack.esql.analysis.PreAnalyzer; -import org.elasticsearch.xpack.esql.analysis.TableInfo; import org.elasticsearch.xpack.esql.analysis.Verifier; import org.elasticsearch.xpack.esql.core.expression.Alias; import org.elasticsearch.xpack.esql.core.expression.Attribute; @@ -353,13 +352,13 @@ public void analyzedPlan( ) ) .collect(Collectors.toSet()); - final List indices = preAnalysis.indices; + final List indices = preAnalysis.indices; EsqlCCSUtils.checkForCcsLicense(executionInfo, indices, indicesExpressionGrouper, verifier.licenseState()); final Set targetClusters = enrichPolicyResolver.groupIndicesPerCluster( indices.stream() - .flatMap(t -> Arrays.stream(Strings.commaDelimitedListToStringArray(t.id().indexPattern()))) + .flatMap(index -> Arrays.stream(Strings.commaDelimitedListToStringArray(index.indexPattern()))) .toArray(String[]::new) ).keySet(); @@ -367,8 +366,8 @@ public void analyzedPlan( l -> enrichPolicyResolver.resolvePolicies(targetClusters, unresolvedPolicies, l) ).andThen((l, enrichResolution) -> resolveFieldNames(parsed, enrichResolution, l)); // first resolve the lookup indices, then the main indices - for (TableInfo lookupIndex : preAnalysis.lookupIndices) { - listener = listener.andThen((l, preAnalysisResult) -> { preAnalyzeLookupIndex(lookupIndex, preAnalysisResult, l); }); + for (var index : preAnalysis.lookupIndices) { + listener = listener.andThen((l, preAnalysisResult) -> { preAnalyzeLookupIndex(index, preAnalysisResult, l); }); } listener.andThen((l, result) -> { // resolve the main indices @@ -411,8 +410,7 @@ public void analyzedPlan( }).addListener(logicalPlanListener); } - private void preAnalyzeLookupIndex(TableInfo tableInfo, PreAnalysisResult result, ActionListener listener) { - IndexPattern table = tableInfo.id(); + private void preAnalyzeLookupIndex(IndexPattern table, PreAnalysisResult result, ActionListener listener) { Set fieldNames = result.wildcardJoinIndices().contains(table.indexPattern()) ? IndexResolver.ALL_FIELDS : result.fieldNames; // call the EsqlResolveFieldsAction (field-caps) to resolve indices and get field types indexResolver.resolveAsMergedMapping( @@ -425,7 +423,7 @@ private void preAnalyzeLookupIndex(TableInfo tableInfo, PreAnalysisResult result } private void preAnalyzeIndices( - List indices, + List indices, EsqlExecutionInfo executionInfo, PreAnalysisResult result, QueryBuilder requestFilter, @@ -438,8 +436,7 @@ private void preAnalyzeIndices( } else if (indices.size() == 1) { // known to be unavailable from the enrich policy API call Map unavailableClusters = result.enrichResolution.getUnavailableClusters(); - TableInfo tableInfo = indices.get(0); - IndexPattern table = tableInfo.id(); + IndexPattern table = indices.getFirst(); Map clusterIndices = indicesExpressionGrouper.groupIndices( IndicesOptions.DEFAULT, diff --git a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/session/EsqlCCSUtilsTests.java b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/session/EsqlCCSUtilsTests.java index e151e4c8f3a9b..e846780dc6e30 100644 --- a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/session/EsqlCCSUtilsTests.java +++ b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/session/EsqlCCSUtilsTests.java @@ -30,7 +30,6 @@ import org.elasticsearch.transport.RemoteTransportException; import org.elasticsearch.xpack.esql.VerificationException; import org.elasticsearch.xpack.esql.action.EsqlExecutionInfo; -import org.elasticsearch.xpack.esql.analysis.TableInfo; import org.elasticsearch.xpack.esql.core.type.EsField; import org.elasticsearch.xpack.esql.index.EsIndex; import org.elasticsearch.xpack.esql.index.IndexResolution; @@ -709,8 +708,7 @@ public void testCheckForCcsLicense() { // local only search does not require an enterprise license { - List indices = new ArrayList<>(); - indices.add(new TableInfo(new IndexPattern(EMPTY, randomFrom("idx", "idx1,idx2*")))); + List indices = List.of(new IndexPattern(EMPTY, randomFrom("idx", "idx1,idx2*"))); checkForCcsLicense(executionInfo, indices, indicesGrouper, enterpriseLicenseValid); checkForCcsLicense(executionInfo, indices, indicesGrouper, platinumLicenseValid); @@ -732,13 +730,13 @@ public void testCheckForCcsLicense() { // cross-cluster search requires a valid (active, non-expired) enterprise license OR a valid trial license { - List indices = new ArrayList<>(); + List indices = new ArrayList<>(); final String indexExprWithRemotes = randomFrom("remote:idx", "idx1,remote:idx2*,remote:logs,c*:idx4"); if (randomBoolean()) { - indices.add(new TableInfo(new IndexPattern(EMPTY, indexExprWithRemotes))); + indices.add(new IndexPattern(EMPTY, indexExprWithRemotes)); } else { - indices.add(new TableInfo(new IndexPattern(EMPTY, randomFrom("idx", "idx1,idx2*")))); - indices.add(new TableInfo(new IndexPattern(EMPTY, indexExprWithRemotes))); + indices.add(new IndexPattern(EMPTY, randomFrom("idx", "idx1,idx2*"))); + indices.add(new IndexPattern(EMPTY, indexExprWithRemotes)); } // licenses that work @@ -804,7 +802,7 @@ private XPackLicenseStatus inactiveLicenseStatus(License.OperationMode operation } private void assertLicenseCheckFails( - List indices, + List indices, TestIndicesExpressionGrouper indicesGrouper, XPackLicenseState licenseState, String expectedErrorMessageSuffix From 3ecdf5bd7024c6771ddb55972988ebf4d1903685 Mon Sep 17 00:00:00 2001 From: "ievgen.degtiarenko" Date: Wed, 2 Apr 2025 09:06:58 +0200 Subject: [PATCH 2/4] upd --- .../java/org/elasticsearch/xpack/esql/analysis/PreAnalyzer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/analysis/PreAnalyzer.java b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/analysis/PreAnalyzer.java index 9dfb0dec5e140..e05b4ba3a05dc 100644 --- a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/analysis/PreAnalyzer.java +++ b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/analysis/PreAnalyzer.java @@ -52,7 +52,7 @@ protected PreAnalysis doPreAnalyze(LogicalPlan plan) { plan.forEachUp( UnresolvedRelation.class, - p -> { (p.indexMode() == IndexMode.LOOKUP ? lookupIndices : indices).add(p.indexPattern()); } + p -> (p.indexMode() == IndexMode.LOOKUP ? lookupIndices : indices).add(p.indexPattern()) ); plan.forEachUp(Enrich.class, unresolvedEnriches::add); From c77f3fdb5000e93668cf4f503e22220bcfdd9360 Mon Sep 17 00:00:00 2001 From: elasticsearchmachine Date: Wed, 2 Apr 2025 07:13:56 +0000 Subject: [PATCH 3/4] [CI] Auto commit changes from spotless --- .../org/elasticsearch/xpack/esql/analysis/PreAnalyzer.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/analysis/PreAnalyzer.java b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/analysis/PreAnalyzer.java index e05b4ba3a05dc..72effd06bfb5b 100644 --- a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/analysis/PreAnalyzer.java +++ b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/analysis/PreAnalyzer.java @@ -50,10 +50,7 @@ protected PreAnalysis doPreAnalyze(LogicalPlan plan) { List unresolvedEnriches = new ArrayList<>(); List lookupIndices = new ArrayList<>(); - plan.forEachUp( - UnresolvedRelation.class, - p -> (p.indexMode() == IndexMode.LOOKUP ? lookupIndices : indices).add(p.indexPattern()) - ); + plan.forEachUp(UnresolvedRelation.class, p -> (p.indexMode() == IndexMode.LOOKUP ? lookupIndices : indices).add(p.indexPattern())); plan.forEachUp(Enrich.class, unresolvedEnriches::add); // mark plan as preAnalyzed (if it were marked, there would be no analysis) From 48a27158748446c1c0639870b9aa764aab7f4e06 Mon Sep 17 00:00:00 2001 From: "ievgen.degtiarenko" Date: Wed, 2 Apr 2025 10:26:43 +0200 Subject: [PATCH 4/4] fix build --- .../src/test/java/org/elasticsearch/xpack/esql/CsvTests.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/CsvTests.java b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/CsvTests.java index 90d171bd9796a..be93fcc561c0c 100644 --- a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/CsvTests.java +++ b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/CsvTests.java @@ -498,7 +498,7 @@ private static CsvTestsDataLoader.MultiIndexTestDataset testDatasets(LogicalPlan throw new IllegalArgumentException("unexpected index resolution to multiple entries [" + preAnalysis.indices.size() + "]"); } - String indexName = indices.get(0).id().indexPattern(); + String indexName = indices.getFirst().indexPattern(); List datasets = new ArrayList<>(); if (indexName.endsWith("*")) { String indexPrefix = indexName.substring(0, indexName.length() - 1);