Skip to content

Commit

Permalink
Remove legacy IndexResolver (elastic#109821)
Browse files Browse the repository at this point in the history
Currently, we are using the legacy IndexResolver alongside the updated 
version to compare their outputs. While this approach helps in bug
detection, it adds to the maintenance burden, particularly when adding
new features to the field-caps API or the index resolver. This change
removes the legacy IndexResolver from the ESQL codebase.
  • Loading branch information
dnhatn authored Jun 18, 2024
1 parent 429c970 commit 86b80b6
Show file tree
Hide file tree
Showing 14 changed files with 70 additions and 1,426 deletions.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,10 @@
import org.elasticsearch.xpack.core.enrich.EnrichPolicy;
import org.elasticsearch.xpack.esql.analysis.EnrichResolution;
import org.elasticsearch.xpack.esql.core.index.EsIndex;
import org.elasticsearch.xpack.esql.core.index.IndexResolver;
import org.elasticsearch.xpack.esql.core.type.EsField;
import org.elasticsearch.xpack.esql.core.util.StringUtils;
import org.elasticsearch.xpack.esql.plan.logical.Enrich;
import org.elasticsearch.xpack.esql.session.EsqlSession;
import org.elasticsearch.xpack.esql.session.IndexResolver;
import org.elasticsearch.xpack.esql.type.EsqlDataTypes;

import java.io.IOException;
Expand Down Expand Up @@ -359,29 +358,22 @@ public void messageReceived(LookupRequest request, TransportChannel channel, Tas
}
try (ThreadContext.StoredContext ignored = threadContext.stashWithOrigin(ClientHelper.ENRICH_ORIGIN)) {
String indexName = EnrichPolicy.getBaseName(policyName);
indexResolver.resolveAsMergedMapping(
indexName,
IndexResolver.ALL_FIELDS,
false,
Map.of(),
refs.acquire(indexResult -> {
if (indexResult.isValid() && indexResult.get().concreteIndices().size() == 1) {
EsIndex esIndex = indexResult.get();
var concreteIndices = Map.of(request.clusterAlias, Iterables.get(esIndex.concreteIndices(), 0));
var resolved = new ResolvedEnrichPolicy(
p.getMatchField(),
p.getType(),
p.getEnrichFields(),
concreteIndices,
esIndex.mapping()
);
resolvedPolices.put(policyName, resolved);
} else {
failures.put(policyName, indexResult.toString());
}
}),
EsqlSession::specificValidity
);
indexResolver.resolveAsMergedMapping(indexName, IndexResolver.ALL_FIELDS, refs.acquire(indexResult -> {
if (indexResult.isValid() && indexResult.get().concreteIndices().size() == 1) {
EsIndex esIndex = indexResult.get();
var concreteIndices = Map.of(request.clusterAlias, Iterables.get(esIndex.concreteIndices(), 0));
var resolved = new ResolvedEnrichPolicy(
p.getMatchField(),
p.getType(),
p.getEnrichFields(),
concreteIndices,
esIndex.mapping()
);
resolvedPolices.put(policyName, resolved);
} else {
failures.put(policyName, indexResult.toString());
}
}));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,15 @@
import org.elasticsearch.xpack.esql.analysis.PreAnalyzer;
import org.elasticsearch.xpack.esql.analysis.Verifier;
import org.elasticsearch.xpack.esql.core.expression.function.FunctionRegistry;
import org.elasticsearch.xpack.esql.core.index.IndexResolver;
import org.elasticsearch.xpack.esql.enrich.EnrichPolicyResolver;
import org.elasticsearch.xpack.esql.expression.function.EsqlFunctionRegistry;
import org.elasticsearch.xpack.esql.optimizer.LogicalOptimizerContext;
import org.elasticsearch.xpack.esql.optimizer.LogicalPlanOptimizer;
import org.elasticsearch.xpack.esql.plan.physical.PhysicalPlan;
import org.elasticsearch.xpack.esql.planner.Mapper;
import org.elasticsearch.xpack.esql.session.EsqlConfiguration;
import org.elasticsearch.xpack.esql.session.EsqlIndexResolver;
import org.elasticsearch.xpack.esql.session.EsqlSession;
import org.elasticsearch.xpack.esql.session.IndexResolver;
import org.elasticsearch.xpack.esql.stats.Metrics;
import org.elasticsearch.xpack.esql.stats.QueryMetric;

Expand All @@ -30,16 +29,14 @@
public class PlanExecutor {

private final IndexResolver indexResolver;
private final EsqlIndexResolver esqlIndexResolver;
private final PreAnalyzer preAnalyzer;
private final FunctionRegistry functionRegistry;
private final Mapper mapper;
private final Metrics metrics;
private final Verifier verifier;

public PlanExecutor(IndexResolver indexResolver, EsqlIndexResolver esqlIndexResolver) {
public PlanExecutor(IndexResolver indexResolver) {
this.indexResolver = indexResolver;
this.esqlIndexResolver = esqlIndexResolver;
this.preAnalyzer = new PreAnalyzer();
this.functionRegistry = new EsqlFunctionRegistry();
this.mapper = new Mapper(functionRegistry);
Expand All @@ -58,7 +55,6 @@ public void esql(
sessionId,
cfg,
indexResolver,
esqlIndexResolver,
enrichPolicyResolver,
preAnalyzer,
functionRegistry,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,19 @@
import org.elasticsearch.xpack.esql.action.RestEsqlQueryAction;
import org.elasticsearch.xpack.esql.core.expression.Attribute;
import org.elasticsearch.xpack.esql.core.expression.NamedExpression;
import org.elasticsearch.xpack.esql.core.index.IndexResolver;
import org.elasticsearch.xpack.esql.core.type.EsField;
import org.elasticsearch.xpack.esql.enrich.EnrichLookupOperator;
import org.elasticsearch.xpack.esql.execution.PlanExecutor;
import org.elasticsearch.xpack.esql.expression.function.UnsupportedAttribute;
import org.elasticsearch.xpack.esql.querydsl.query.SingleValueQuery;
import org.elasticsearch.xpack.esql.session.EsqlIndexResolver;
import org.elasticsearch.xpack.esql.session.IndexResolver;
import org.elasticsearch.xpack.esql.type.EsqlDataTypeRegistry;

import java.lang.invoke.MethodHandles;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.function.Predicate;
import java.util.function.Supplier;

Expand Down Expand Up @@ -110,15 +108,7 @@ public Collection<?> createComponents(PluginServices services) {
BlockFactory blockFactory = new BlockFactory(circuitBreaker, bigArrays, maxPrimitiveArrayBlockSize);
setupSharedSecrets();
return List.of(
new PlanExecutor(
new IndexResolver(
services.client(),
services.clusterService().getClusterName().value(),
EsqlDataTypeRegistry.INSTANCE,
Set::of
),
new EsqlIndexResolver(services.client(), EsqlDataTypeRegistry.INSTANCE)
),
new PlanExecutor(new IndexResolver(services.client(), EsqlDataTypeRegistry.INSTANCE)),
new ExchangeService(services.clusterService().getSettings(), services.threadPool(), ThreadPool.Names.SEARCH, blockFactory),
blockFactory
);
Expand Down
Loading

0 comments on commit 86b80b6

Please sign in to comment.