-
Notifications
You must be signed in to change notification settings - Fork 0
Mirror upstream elastic/elasticsearch#137446 for AI review (snapshot of HEAD tree) #287
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,6 +14,7 @@ | |
| import org.elasticsearch.action.fieldcaps.FieldCapabilitiesFailure; | ||
| import org.elasticsearch.action.search.ShardSearchFailure; | ||
| import org.elasticsearch.action.support.SubscribableListener; | ||
| import org.elasticsearch.common.TriConsumer; | ||
| import org.elasticsearch.common.collect.Iterators; | ||
| import org.elasticsearch.common.unit.ByteSizeValue; | ||
| import org.elasticsearch.compute.data.Block; | ||
|
|
@@ -33,6 +34,7 @@ | |
| import org.elasticsearch.logging.LogManager; | ||
| import org.elasticsearch.logging.Logger; | ||
| import org.elasticsearch.search.SearchShardTarget; | ||
| import org.elasticsearch.search.crossproject.CrossProjectModeDecider; | ||
| import org.elasticsearch.threadpool.ThreadPool; | ||
| import org.elasticsearch.transport.RemoteClusterAware; | ||
| import org.elasticsearch.transport.RemoteClusterService; | ||
|
|
@@ -134,6 +136,7 @@ public interface PlanRunner { | |
| private final RemoteClusterService remoteClusterService; | ||
| private final BlockFactory blockFactory; | ||
| private final ByteSizeValue intermediateLocalRelationMaxSize; | ||
| private final CrossProjectModeDecider crossProjectModeDecider; | ||
| private final String clusterName; | ||
|
|
||
| private boolean explainMode; | ||
|
|
@@ -168,6 +171,7 @@ public EsqlSession( | |
| this.remoteClusterService = services.transportService().getRemoteClusterService(); | ||
| this.blockFactory = services.blockFactoryProvider().blockFactory(); | ||
| this.intermediateLocalRelationMaxSize = services.plannerSettings().intermediateLocalRelationMaxSize(); | ||
| this.crossProjectModeDecider = services.crossProjectModeDecider(); | ||
| this.clusterName = services.clusterService().getClusterName().value(); | ||
| } | ||
|
|
||
|
|
@@ -544,27 +548,16 @@ private void resolveIndicesAndAnalyze( | |
| PreAnalysisResult result, | ||
| ActionListener<Versioned<LogicalPlan>> logicalPlanListener | ||
| ) { | ||
| EsqlCCSUtils.initCrossClusterState( | ||
| indicesExpressionGrouper, | ||
| verifier.licenseState(), | ||
| preAnalysis.indexes().keySet(), | ||
| executionInfo | ||
| ); | ||
|
|
||
| SubscribableListener.<PreAnalysisResult>newForked( | ||
| // The main index pattern dictates on which nodes the query can be executed, so we use the minimum transport version from this | ||
| // field | ||
| // caps request. | ||
| l -> preAnalyzeMainIndices(preAnalysis.indexes().entrySet().iterator(), preAnalysis, executionInfo, result, requestFilter, l) | ||
| ).andThenApply(r -> { | ||
| if (r.indexResolution.isEmpty() == false // Rule out ROW case with no FROM clauses | ||
| && executionInfo.isCrossClusterSearch() | ||
| && executionInfo.getRunningClusterAliases().findAny().isEmpty()) { | ||
| LOGGER.debug("No more clusters to search, ending analysis stage"); | ||
| throw new NoClustersToSearchException(); | ||
| } | ||
| return r; | ||
| }) | ||
| SubscribableListener.<PreAnalysisResult>newForked(l -> preAnalyzeMainIndices(preAnalysis, executionInfo, result, requestFilter, l)) | ||
| .andThenApply(r -> { | ||
| if (r.indexResolution.isEmpty() == false // Rule out ROW case with no FROM clauses | ||
| && executionInfo.isCrossClusterSearch() | ||
| && executionInfo.getRunningClusterAliases().findAny().isEmpty()) { | ||
| LOGGER.debug("No more clusters to search, ending analysis stage"); | ||
| throw new NoClustersToSearchException(); | ||
| } | ||
| return r; | ||
| }) | ||
| .<PreAnalysisResult>andThen((l, r) -> preAnalyzeLookupIndices(preAnalysis.lookupIndices().iterator(), r, executionInfo, l)) | ||
| .<PreAnalysisResult>andThen((l, r) -> { | ||
| enrichPolicyResolver.resolvePolicies(preAnalysis.enriches(), executionInfo, l.map(r::withEnrichResolution)); | ||
|
|
@@ -587,13 +580,7 @@ private void preAnalyzeLookupIndices( | |
| EsqlExecutionInfo executionInfo, | ||
| ActionListener<PreAnalysisResult> listener | ||
| ) { | ||
| if (lookupIndices.hasNext()) { | ||
| preAnalyzeLookupIndex(lookupIndices.next(), preAnalysisResult, executionInfo, listener.delegateFailureAndWrap((l, r) -> { | ||
| preAnalyzeLookupIndices(lookupIndices, r, executionInfo, l); | ||
| })); | ||
| } else { | ||
| listener.onResponse(preAnalysisResult); | ||
| } | ||
| forAll(lookupIndices, preAnalysisResult, (lookupIndex, r, l) -> preAnalyzeLookupIndex(lookupIndex, r, executionInfo, l), listener); | ||
| } | ||
|
|
||
| private void preAnalyzeLookupIndex( | ||
|
|
@@ -805,29 +792,26 @@ private void validateRemoteVersions(EsqlExecutionInfo executionInfo) { | |
| * indices. | ||
| */ | ||
| private void preAnalyzeMainIndices( | ||
| Iterator<Map.Entry<IndexPattern, IndexMode>> indexPatterns, | ||
| PreAnalyzer.PreAnalysis preAnalysis, | ||
| EsqlExecutionInfo executionInfo, | ||
| PreAnalysisResult result, | ||
| QueryBuilder requestFilter, | ||
| ActionListener<PreAnalysisResult> listener | ||
| ) { | ||
| if (indexPatterns.hasNext()) { | ||
| var index = indexPatterns.next(); | ||
| preAnalyzeMainIndices( | ||
| index.getKey(), | ||
| index.getValue(), | ||
| preAnalysis, | ||
| executionInfo, | ||
| result, | ||
| requestFilter, | ||
| listener.delegateFailureAndWrap((l, r) -> { | ||
| preAnalyzeMainIndices(indexPatterns, preAnalysis, executionInfo, r, requestFilter, l); | ||
| }) | ||
| ); | ||
| } else { | ||
| listener.onResponse(result); | ||
| } | ||
| EsqlCCSUtils.initCrossClusterState( | ||
| indicesExpressionGrouper, | ||
| verifier.licenseState(), | ||
| preAnalysis.indexes().keySet(), | ||
| executionInfo | ||
| ); | ||
| // The main index pattern dictates on which nodes the query can be executed, | ||
| // so we use the minimum transport version from this field caps request. | ||
| forAll( | ||
| preAnalysis.indexes().entrySet().iterator(), | ||
| result, | ||
| (entry, r, l) -> preAnalyzeMainIndices(entry.getKey(), entry.getValue(), preAnalysis, executionInfo, r, requestFilter, l), | ||
| listener | ||
| ); | ||
| } | ||
|
|
||
| private void preAnalyzeMainIndices( | ||
|
|
@@ -844,12 +828,9 @@ private void preAnalyzeMainIndices( | |
| ThreadPool.Names.SEARCH_COORDINATION, | ||
| ThreadPool.Names.SYSTEM_READ | ||
| ); | ||
| // TODO: This is not yet index specific, but that will not matter as soon as #136804 is dealt with | ||
| if (executionInfo.clusterAliases().isEmpty()) { | ||
| // return empty resolution if the expression is pure CCS and resolved no remote clusters (like no-such-cluster*:index) | ||
| listener.onResponse( | ||
| result.withIndices(indexPattern, IndexResolution.valid(new EsIndex(indexPattern.indexPattern(), Map.of(), Map.of()))) | ||
| ); | ||
| listener.onResponse(result.withIndices(indexPattern, IndexResolution.empty(indexPattern.indexPattern()))); | ||
| } else { | ||
| indexResolver.resolveAsMergedMappingAndRetrieveMinimumVersion( | ||
| indexPattern.indexPattern(), | ||
|
|
@@ -994,6 +975,19 @@ private PhysicalPlan optimizedPhysicalPlan(LogicalPlan optimizedPlan, PhysicalPl | |
| return plan; | ||
| } | ||
|
|
||
| private static <T> void forAll( | ||
| Iterator<T> iterator, | ||
| PreAnalysisResult result, | ||
| TriConsumer<T, PreAnalysisResult, ActionListener<PreAnalysisResult>> consumer, | ||
| ActionListener<PreAnalysisResult> listener | ||
| ) { | ||
| if (iterator.hasNext()) { | ||
| consumer.apply(iterator.next(), result, listener.delegateFailureAndWrap((l, r) -> forAll(iterator, r, consumer, l))); | ||
| } else { | ||
| listener.onResponse(result); | ||
| } | ||
| } | ||
|
Comment on lines
+978
to
+989
|
||
|
|
||
| public record PreAnalysisResult( | ||
| Set<String> fieldNames, | ||
| Set<String> wildcardJoinIndices, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
crossProjectModeDeciderfield is added and initialized but never used in this class. If this field is being added for future use, consider adding a TODO comment explaining the intended usage. Otherwise, if it's not needed yet, it should be removed to avoid dead code.