Skip to content

Commit f76ca18

Browse files
authored
ESQL: add a singleton LocalMapper (#138608)
LocalMapper can be instantiated just once.
1 parent 535ba6b commit f76ca18

File tree

4 files changed

+8
-10
lines changed

4 files changed

+8
-10
lines changed

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,11 +148,7 @@ protected LookupEnrichQueryGenerator queryList(
148148
* In those cases, it is safe to ignore the plan sent and return null
149149
*/
150150
private static PhysicalPlan localLookupNodePlanning(PhysicalPlan physicalPlan) {
151-
if (physicalPlan instanceof FragmentExec fragmentExec) {
152-
LocalMapper localMapper = new LocalMapper();
153-
return localMapper.map(fragmentExec.fragment());
154-
}
155-
return null;
151+
return physicalPlan instanceof FragmentExec fragmentExec ? LocalMapper.INSTANCE.map(fragmentExec.fragment()) : null;
156152
}
157153

158154
@Override

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/planner/PlannerUtils.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,8 @@ public static PlanReduction reductionPlan(PhysicalPlan plan) {
144144
return SimplePlanReduction.NO_REDUCTION;
145145
}
146146
final LogicalPlan pipelineBreaker = pipelineBreakers.getFirst();
147-
final LocalMapper mapper = new LocalMapper();
148147
int estimatedRowSize = fragment.estimatedRowSize();
149-
return switch (mapper.map(pipelineBreaker)) {
148+
return switch (LocalMapper.INSTANCE.map(pipelineBreaker)) {
150149
case TopNExec topN -> new TopNReduction(EstimatesRowSize.estimateRowSize(estimatedRowSize, topN));
151150
case AggregateExec aggExec -> getPhysicalPlanReduction(estimatedRowSize, aggExec.withMode(AggregatorMode.INTERMEDIATE));
152151
case PhysicalPlan p -> getPhysicalPlanReduction(estimatedRowSize, p);
@@ -218,7 +217,6 @@ public static PhysicalPlan localPlan(
218217
LocalLogicalPlanOptimizer logicalOptimizer,
219218
LocalPhysicalPlanOptimizer physicalOptimizer
220219
) {
221-
final LocalMapper localMapper = new LocalMapper();
222220
var isCoordPlan = new Holder<>(Boolean.TRUE);
223221
Set<PhysicalPlan> lookupJoinExecRightChildren = plan.collect(LookupJoinExec.class::isInstance)
224222
.stream()
@@ -234,7 +232,7 @@ public static PhysicalPlan localPlan(
234232
}
235233
isCoordPlan.set(Boolean.FALSE);
236234
LogicalPlan optimizedFragment = logicalOptimizer.localOptimize(f.fragment());
237-
PhysicalPlan physicalFragment = localMapper.map(optimizedFragment);
235+
PhysicalPlan physicalFragment = LocalMapper.INSTANCE.map(optimizedFragment);
238236
QueryBuilder filter = f.esFilter();
239237
if (filter != null) {
240238
physicalFragment = physicalFragment.transformUp(

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/planner/mapper/LocalMapper.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@
4141
*/
4242
public class LocalMapper {
4343

44+
public static LocalMapper INSTANCE = new LocalMapper();
45+
46+
private LocalMapper() {}
47+
4448
public PhysicalPlan map(LogicalPlan p) {
4549

4650
if (p instanceof LeafPlan leaf) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ public static Optional<ReductionPlan> planReduceDriverTopN(
133133
}
134134

135135
private static PhysicalPlan toPhysical(LogicalPlan plan, LocalPhysicalOptimizerContext context) {
136-
return new InsertFieldExtraction().apply(new ReplaceSourceAttributes().apply(new LocalMapper().map(plan)), context);
136+
return new InsertFieldExtraction().apply(new ReplaceSourceAttributes().apply(LocalMapper.INSTANCE.map(plan)), context);
137137
}
138138

139139
private LateMaterializationPlanner() { /* static class */ }

0 commit comments

Comments
 (0)