Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -25,11 +26,11 @@ public class PreAnalyzer {
public static class PreAnalysis {
public static final PreAnalysis EMPTY = new PreAnalysis(emptyList(), emptyList(), emptyList());

public final List<TableInfo> indices;
public final List<IndexPattern> indices;
public final List<Enrich> enriches;
public final List<TableInfo> lookupIndices;
public final List<IndexPattern> lookupIndices;

public PreAnalysis(List<TableInfo> indices, List<Enrich> enriches, List<TableInfo> lookupIndices) {
public PreAnalysis(List<IndexPattern> indices, List<Enrich> enriches, List<IndexPattern> lookupIndices) {
this.indices = indices;
this.enriches = enriches;
this.lookupIndices = lookupIndices;
Expand All @@ -45,14 +46,11 @@ public PreAnalysis preAnalyze(LogicalPlan plan) {
}

protected PreAnalysis doPreAnalyze(LogicalPlan plan) {
List<TableInfo> indices = new ArrayList<>();
List<IndexPattern> indices = new ArrayList<>();
List<Enrich> unresolvedEnriches = new ArrayList<>();
List<TableInfo> lookupIndices = new ArrayList<>();
List<IndexPattern> lookupIndices = new ArrayList<>();

plan.forEachUp(UnresolvedRelation.class, p -> {
List<TableInfo> 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)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -276,15 +276,15 @@ static void updateExecutionInfoAtEndOfPlanning(EsqlExecutionInfo execInfo) {
*/
public static void checkForCcsLicense(
EsqlExecutionInfo executionInfo,
List<TableInfo> indices,
List<IndexPattern> indices,
IndicesExpressionGrouper indicesGrouper,
Set<String> configuredClusters,
XPackLicenseState licenseState
) {
for (TableInfo tableInfo : indices) {
for (IndexPattern index : indices) {
Map<String, OriginalIndices> groupedIndices;
try {
groupedIndices = indicesGrouper.groupIndices(configuredClusters, IndicesOptions.DEFAULT, tableInfo.id().indexPattern());
groupedIndices = indicesGrouper.groupIndices(configuredClusters, IndicesOptions.DEFAULT, index.indexPattern());
} catch (NoSuchRemoteClusterException e) {
if (EsqlLicenseChecker.isCcsAllowed(licenseState)) {
throw e;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -356,23 +355,23 @@ public void analyzedPlan(
)
)
.collect(Collectors.toSet());
final List<TableInfo> indices = preAnalysis.indices;
final List<IndexPattern> indices = preAnalysis.indices;

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

final Set<String> targetClusters = enrichPolicyResolver.groupIndicesPerCluster(
configuredClusters,
indices.stream()
.flatMap(t -> Arrays.stream(Strings.commaDelimitedListToStringArray(t.id().indexPattern())))
.flatMap(index -> Arrays.stream(Strings.commaDelimitedListToStringArray(index.indexPattern())))
.toArray(String[]::new)
).keySet();

var listener = SubscribableListener.<EnrichResolution>newForked(
l -> enrichPolicyResolver.resolvePolicies(targetClusters, unresolvedPolicies, l)
).<PreAnalysisResult>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.<PreAnalysisResult>andThen((l, result) -> {
// resolve the main indices
Expand Down Expand Up @@ -415,8 +414,7 @@ public void analyzedPlan(
}).addListener(logicalPlanListener);
}

private void preAnalyzeLookupIndex(TableInfo tableInfo, PreAnalysisResult result, ActionListener<PreAnalysisResult> listener) {
IndexPattern table = tableInfo.id();
private void preAnalyzeLookupIndex(IndexPattern table, PreAnalysisResult result, ActionListener<PreAnalysisResult> listener) {
Set<String> 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(
Expand All @@ -429,7 +427,7 @@ private void preAnalyzeLookupIndex(TableInfo tableInfo, PreAnalysisResult result
}

private void preAnalyzeIndices(
List<TableInfo> indices,
List<IndexPattern> indices,
EsqlExecutionInfo executionInfo,
PreAnalysisResult result,
QueryBuilder requestFilter,
Expand All @@ -442,8 +440,7 @@ private void preAnalyzeIndices(
} else if (indices.size() == 1) {
// known to be unavailable from the enrich policy API call
Map<String, Exception> unavailableClusters = result.enrichResolution.getUnavailableClusters();
TableInfo tableInfo = indices.get(0);
IndexPattern table = tableInfo.id();
IndexPattern table = indices.getFirst();

Map<String, OriginalIndices> clusterIndices = indicesExpressionGrouper.groupIndices(
configuredClusters,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<CsvTestsDataLoader.TestDataset> datasets = new ArrayList<>();
if (indexName.endsWith("*")) {
String indexPrefix = indexName.substring(0, indexName.length() - 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -709,8 +708,7 @@ public void testCheckForCcsLicense() {

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

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

// cross-cluster search requires a valid (active, non-expired) enterprise license OR a valid trial license
{
List<TableInfo> indices = new ArrayList<>();
List<IndexPattern> 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
Expand Down Expand Up @@ -804,7 +802,7 @@ private XPackLicenseStatus inactiveLicenseStatus(License.OperationMode operation
}

private void assertLicenseCheckFails(
List<TableInfo> indices,
List<IndexPattern> indices,
TestIndicesExpressionGrouper indicesGrouper,
XPackLicenseState licenseState,
String expectedErrorMessageSuffix
Expand Down