Skip to content

Commit 155acc7

Browse files
committed
Reintroduce a light premapping layer
1 parent e08fd4d commit 155acc7

File tree

3 files changed

+46
-19
lines changed

3 files changed

+46
-19
lines changed

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/fulltext/QueryBuilderResolver.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
/**
2727
* Some {@link FullTextFunction} implementations such as {@link org.elasticsearch.xpack.esql.expression.function.fulltext.Match}
2828
* will be translated to a {@link QueryBuilder} that require a rewrite phase on the coordinator.
29-
* {@link QueryBuilderResolver#preprocess(LogicalPlan, TransportActionServices, ActionListener)} will rewrite the plan by
29+
* {@link QueryBuilderResolver#resolveQueryBuilders(LogicalPlan, TransportActionServices, ActionListener)} will rewrite the plan by
3030
* replacing {@link FullTextFunction} expression with new ones that hold rewritten {@link QueryBuilder}s.
3131
*/
3232
public final class QueryBuilderResolver {
@@ -35,7 +35,7 @@ public final class QueryBuilderResolver {
3535

3636
private QueryBuilderResolver() {}
3737

38-
public void preprocess(LogicalPlan plan, TransportActionServices services, ActionListener<LogicalPlan> listener) {
38+
public void resolveQueryBuilders(LogicalPlan plan, TransportActionServices services, ActionListener<LogicalPlan> listener) {
3939
var hasFullTextFunctions = plan.anyMatch(p -> {
4040
Holder<Boolean> hasFullTextFunction = new Holder<>(false);
4141
p.forEachExpression(FullTextFunction.class, unused -> hasFullTextFunction.set(true));
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
package org.elasticsearch.xpack.esql.planner.premapper;
9+
10+
import org.elasticsearch.action.ActionListener;
11+
import org.elasticsearch.xpack.esql.expression.function.fulltext.QueryBuilderResolver;
12+
import org.elasticsearch.xpack.esql.plan.logical.LogicalPlan;
13+
import org.elasticsearch.xpack.esql.plugin.TransportActionServices;
14+
15+
/**
16+
* The class is responsible for invoking any premapping steps that need to be applied to the logical plan,
17+
* before this is being mapped to a physical one.
18+
*/
19+
public class PreMapper {
20+
21+
private final TransportActionServices services;
22+
23+
public PreMapper(TransportActionServices services) {
24+
this.services = services;
25+
}
26+
27+
/**
28+
* Invokes any premapping steps that need to be applied to the logical plan, before this is being mapped to a physical one.
29+
*/
30+
public void preMapper(LogicalPlan plan, ActionListener<LogicalPlan> listener) {
31+
queryRewrite(plan, listener);
32+
}
33+
34+
private void queryRewrite(LogicalPlan plan, ActionListener<LogicalPlan> listener) {
35+
QueryBuilderResolver.INSTANCE.resolveQueryBuilders(plan, services, listener);
36+
}
37+
}

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

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848
import org.elasticsearch.xpack.esql.enrich.ResolvedEnrichPolicy;
4949
import org.elasticsearch.xpack.esql.expression.UnresolvedNamePattern;
5050
import org.elasticsearch.xpack.esql.expression.function.EsqlFunctionRegistry;
51-
import org.elasticsearch.xpack.esql.expression.function.fulltext.QueryBuilderResolver;
5251
import org.elasticsearch.xpack.esql.index.EsIndex;
5352
import org.elasticsearch.xpack.esql.index.IndexResolution;
5453
import org.elasticsearch.xpack.esql.index.MappingException;
@@ -74,6 +73,7 @@
7473
import org.elasticsearch.xpack.esql.plan.physical.FragmentExec;
7574
import org.elasticsearch.xpack.esql.plan.physical.PhysicalPlan;
7675
import org.elasticsearch.xpack.esql.planner.mapper.Mapper;
76+
import org.elasticsearch.xpack.esql.planner.premapper.PreMapper;
7777
import org.elasticsearch.xpack.esql.plugin.TransportActionServices;
7878
import org.elasticsearch.xpack.esql.telemetry.PlanTelemetry;
7979

@@ -111,12 +111,12 @@ public interface PlanRunner {
111111
private final Verifier verifier;
112112
private final EsqlFunctionRegistry functionRegistry;
113113
private final LogicalPlanOptimizer logicalPlanOptimizer;
114+
private final PreMapper preMapper;
114115

115116
private final Mapper mapper;
116117
private final PhysicalPlanOptimizer physicalPlanOptimizer;
117118
private final PlanTelemetry planTelemetry;
118119
private final IndicesExpressionGrouper indicesExpressionGrouper;
119-
private final TransportActionServices services;
120120

121121
public EsqlSession(
122122
String sessionId,
@@ -144,7 +144,7 @@ public EsqlSession(
144144
this.physicalPlanOptimizer = new PhysicalPlanOptimizer(new PhysicalOptimizerContext(configuration));
145145
this.planTelemetry = planTelemetry;
146146
this.indicesExpressionGrouper = indicesExpressionGrouper;
147-
this.services = services;
147+
this.preMapper = new PreMapper(services);
148148
}
149149

150150
public String sessionId() {
@@ -164,25 +164,15 @@ public void execute(EsqlQueryRequest request, EsqlExecutionInfo executionInfo, P
164164
new EsqlSessionCCSUtils.CssPartialErrorsActionListener(executionInfo, listener) {
165165
@Override
166166
public void onResponse(LogicalPlan analyzedPlan) {
167-
preMapping(request, executionInfo, planRunner, optimizedPlan(analyzedPlan), listener);
167+
preMapper.preMapper(analyzedPlan, listener.delegateFailureAndWrap((l, p) -> {
168+
p.setOptimized(); // might have been updated by the preprocessor
169+
executeOptimizedPlan(request, executionInfo, planRunner, optimizedPlan(p), l);
170+
}));
168171
}
169172
}
170173
);
171174
}
172175

173-
public void preMapping(
174-
EsqlQueryRequest request,
175-
EsqlExecutionInfo executionInfo,
176-
PlanRunner planRunner,
177-
LogicalPlan optimizedPlan,
178-
ActionListener<Result> listener
179-
) {
180-
QueryBuilderResolver.INSTANCE.preprocess(optimizedPlan, services, listener.delegateFailureAndWrap((l, p) -> {
181-
p.setOptimized(); // might have been updated by the preprocessor
182-
executeOptimizedPlan(request, executionInfo, planRunner, p, listener);
183-
}));
184-
}
185-
186176
/**
187177
* Execute an analyzed plan. Most code should prefer calling {@link #execute} but
188178
* this is public for testing.

0 commit comments

Comments
 (0)