Skip to content

Commit fd5d656

Browse files
committed
Restore removed code.
1 parent 606a130 commit fd5d656

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@
115115
import org.elasticsearch.xpack.esql.plan.physical.ShowExec;
116116
import org.elasticsearch.xpack.esql.plan.physical.TimeSeriesSourceExec;
117117
import org.elasticsearch.xpack.esql.plan.physical.TopNExec;
118+
import org.elasticsearch.xpack.esql.plan.physical.inference.CompletionExec;
118119
import org.elasticsearch.xpack.esql.plan.physical.inference.RerankExec;
119120
import org.elasticsearch.xpack.esql.planner.EsPhysicalOperationProviders.ShardContext;
120121
import org.elasticsearch.xpack.esql.plugin.QueryPragmas;
@@ -259,9 +260,12 @@ private PhysicalOperation plan(PhysicalPlan node, LocalExecutionPlannerContext c
259260
return planRerank(rerank, context);
260261
} else if (node instanceof ChangePointExec changePoint) {
261262
return planChangePoint(changePoint, context);
263+
} else if (node instanceof CompletionExec completion) {
264+
return planCompletion(completion, context);
262265
} else if (node instanceof SampleExec Sample) {
263266
return planSample(Sample, context);
264267
}
268+
265269
// source nodes
266270
else if (node instanceof EsQueryExec esQuery) {
267271
return planEsQueryNode(esQuery, context);
@@ -296,6 +300,19 @@ else if (node instanceof OutputExec outputExec) {
296300
throw new EsqlIllegalArgumentException("unknown physical plan node [" + node.nodeName() + "]");
297301
}
298302

303+
private PhysicalOperation planCompletion(CompletionExec completion, LocalExecutionPlannerContext context) {
304+
PhysicalOperation source = plan(completion.child(), context);
305+
String inferenceId = BytesRefs.toString(completion.inferenceId().fold(context.foldCtx()));
306+
Layout outputLayout = source.layout.builder().append(completion.targetField()).build();
307+
EvalOperator.ExpressionEvaluator.Factory promptEvaluatorFactory = EvalMapper.toEvaluator(
308+
context.foldCtx(),
309+
completion.prompt(),
310+
source.layout
311+
);
312+
313+
return source.with(new CompletionOperator.Factory(inferenceRunner, inferenceId, promptEvaluatorFactory), outputLayout);
314+
}
315+
299316
private PhysicalOperation planRrfScoreEvalExec(RrfScoreEvalExec rrf, LocalExecutionPlannerContext context) {
300317
PhysicalOperation source = plan(rrf.child(), context);
301318

0 commit comments

Comments
 (0)