Skip to content

Commit 1755ea8

Browse files
committed
More refactoring
1 parent 6b795c1 commit 1755ea8

File tree

4 files changed

+11
-24
lines changed

4 files changed

+11
-24
lines changed

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/enrich/EnrichPolicyResolver.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,22 +99,22 @@ public record UnresolvedPolicy(String name, Enrich.Mode mode) {
9999
/**
100100
* Resolves a set of enrich policies
101101
*
102-
* @param targetClusters the target clusters
103102
* @param unresolvedPolicies the unresolved policies
103+
* @param executionInfo the execution info
104104
* @param listener notified with the enrich resolution
105105
*/
106106
public void resolvePolicies(
107-
Collection<String> targetClusters,
108107
Collection<UnresolvedPolicy> unresolvedPolicies,
109108
EsqlExecutionInfo executionInfo,
110109
ActionListener<EnrichResolution> listener
111110
) {
112-
if (unresolvedPolicies.isEmpty() || targetClusters.isEmpty()) {
111+
if (unresolvedPolicies.isEmpty()) {
113112
listener.onResponse(new EnrichResolution());
114113
return;
115114
}
116-
final Set<String> remoteClusters = new HashSet<>(targetClusters);
117-
final boolean includeLocal = remoteClusters.remove(RemoteClusterAware.LOCAL_CLUSTER_GROUP_KEY);
115+
116+
final Set<String> remoteClusters = new HashSet<>(executionInfo.getClusters().keySet());
117+
final boolean includeLocal = remoteClusters.isEmpty() || remoteClusters.remove(RemoteClusterAware.LOCAL_CLUSTER_GROUP_KEY);
118118
lookupPolicies(remoteClusters, includeLocal, unresolvedPolicies, listener.map(lookupResponses -> {
119119
final EnrichResolution enrichResolution = new EnrichResolution();
120120

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

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import org.elasticsearch.indices.IndicesExpressionGrouper;
2424
import org.elasticsearch.logging.LogManager;
2525
import org.elasticsearch.logging.Logger;
26-
import org.elasticsearch.transport.RemoteClusterAware;
2726
import org.elasticsearch.xpack.esql.VerificationException;
2827
import org.elasticsearch.xpack.esql.action.EsqlExecutionInfo;
2928
import org.elasticsearch.xpack.esql.action.EsqlQueryRequest;
@@ -363,7 +362,7 @@ public void analyzedPlan(
363362
initializeClusterData(indices, executionInfo);
364363

365364
var listener = SubscribableListener.<EnrichResolution>newForked(
366-
l -> enrichPolicyResolver.resolvePolicies(getEnrichTargets(executionInfo), unresolvedPolicies, executionInfo, l)
365+
l -> enrichPolicyResolver.resolvePolicies(unresolvedPolicies, executionInfo, l)
367366
)
368367
.<PreAnalysisResult>andThen((l, enrichResolution) -> resolveFieldNames(parsed, enrichResolution, l))
369368
.<PreAnalysisResult>andThen((l, preAnalysisResult) -> resolveInferences(preAnalysis.inferencePlans, preAnalysisResult, l));
@@ -389,12 +388,6 @@ public void analyzedPlan(
389388
}).<PreAnalysisResult>andThen((l, result) -> {
390389
assert requestFilter != null : "The second pre-analysis shouldn't take place when there is no index filter in the request";
391390

392-
// "reset" execution information for all ccs or non-ccs (local) clusters, since we are performing the indices
393-
// resolving one more time (the first attempt failed and the query had a filter)
394-
for (String clusterAlias : executionInfo.clusterAliases()) {
395-
executionInfo.swapCluster(clusterAlias, (k, v) -> null);
396-
}
397-
398391
// here the requestFilter is set to null, performing the pre-analysis after the first step failed
399392
preAnalyzeIndices(preAnalysis.indices, executionInfo, result, null, l);
400393
}).<LogicalPlan>andThen((l, result) -> {
@@ -412,15 +405,6 @@ public void analyzedPlan(
412405
}).addListener(logicalPlanListener);
413406
}
414407

415-
private static Set<String> getEnrichTargets(EsqlExecutionInfo executionInfo) {
416-
Set<String> targetClusters = executionInfo.getClusters().keySet();
417-
if (targetClusters.isEmpty()) {
418-
// Always include local cluster for enrich resolution
419-
return Set.of(RemoteClusterAware.LOCAL_CLUSTER_GROUP_KEY);
420-
}
421-
return targetClusters;
422-
}
423-
424408
private void preAnalyzeLookupIndex(IndexPattern table, PreAnalysisResult result, ActionListener<PreAnalysisResult> listener) {
425409
Set<String> fieldNames = result.wildcardJoinIndices().contains(table.indexPattern()) ? IndexResolver.ALL_FIELDS : result.fieldNames;
426410
// call the EsqlResolveFieldsAction (field-caps) to resolve indices and get field types

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,9 @@ class TestEnrichPolicyResolver extends EnrichPolicyResolver {
431431
EnrichResolution resolvePolicies(Collection<String> clusters, Collection<UnresolvedPolicy> unresolvedPolicies) {
432432
PlainActionFuture<EnrichResolution> future = new PlainActionFuture<>();
433433
EsqlExecutionInfo esqlExecutionInfo = new EsqlExecutionInfo(true);
434+
for (String cluster : clusters) {
435+
esqlExecutionInfo.swapCluster(cluster, (k, v) -> new EsqlExecutionInfo.Cluster(cluster, "*"));
436+
}
434437
if (randomBoolean()) {
435438
unresolvedPolicies = new ArrayList<>(unresolvedPolicies);
436439
for (Enrich.Mode mode : Enrich.Mode.values()) {
@@ -444,7 +447,7 @@ EnrichResolution resolvePolicies(Collection<String> clusters, Collection<Unresol
444447
unresolvedPolicies.add(new UnresolvedPolicy("legacy-policy-1", randomFrom(Enrich.Mode.values())));
445448
}
446449
}
447-
super.resolvePolicies(clusters, unresolvedPolicies, esqlExecutionInfo, future);
450+
super.resolvePolicies(unresolvedPolicies, esqlExecutionInfo, future);
448451
return future.actionGet(30, TimeUnit.SECONDS);
449452
}
450453

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ EnrichPolicyResolver mockEnrichResolver() {
8383
ActionListener<EnrichResolution> listener = (ActionListener<EnrichResolution>) arguments[arguments.length - 1];
8484
listener.onResponse(new EnrichResolution());
8585
return null;
86-
}).when(enrichResolver).resolvePolicies(any(), any(), any(), any());
86+
}).when(enrichResolver).resolvePolicies(any(), any(), any());
8787
return enrichResolver;
8888
}
8989

0 commit comments

Comments
 (0)