Skip to content

Commit 7b8fb01

Browse files
author
elasticsearchmachine
committed
[CI] Auto commit changes from spotless
1 parent 47e9f1d commit 7b8fb01

File tree

10 files changed

+71
-56
lines changed

10 files changed

+71
-56
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,6 @@ private LogicalPlan resolveCompletion(Completion p, List<Attribute> childrenOutp
672672
changed.set(true);
673673
}
674674

675-
676675
if (changed.get() == false) {
677676
return p;
678677
}

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

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,12 @@ public Operator get(DriverContext driverContext) {
5454
private final String inferenceId;
5555
private final EvalOperator.ExpressionEvaluator promptEvaluator;
5656

57-
public CompletionOperator(DriverContext driverContext, InferenceService inferenceService, String inferenceId, EvalOperator.ExpressionEvaluator promptEvaluator) {
57+
public CompletionOperator(
58+
DriverContext driverContext,
59+
InferenceService inferenceService,
60+
String inferenceId,
61+
EvalOperator.ExpressionEvaluator promptEvaluator
62+
) {
5863
super(driverContext, MAX_INFERENCE_WORKER);
5964
this.blockFactory = driverContext.blockFactory();
6065
this.inferenceService = inferenceService;
@@ -76,25 +81,22 @@ protected void performAsync(Page inputPage, ActionListener<Page> listener) {
7681
CountDownLatch countDownLatch = new CountDownLatch(inputPage.getPositionCount());
7782
BytesRef[] inferredValues = new BytesRef[inputPage.getPositionCount()];
7883

79-
ActionListener<Tuple<Integer, BytesRef>> inferenceResponseListener = ActionListener.wrap(
80-
response -> {
81-
countDownLatch.countDown();
82-
inferredValues[response.v1()] = response.v2();
83-
if (countDownLatch.getCount() == 0) {
84-
BytesRefBlock.Builder inferenceBlock = blockFactory.newBytesRefBlockBuilder(inputPage.getPositionCount());
85-
86-
for (BytesRef inferredValue : inferredValues) {
87-
if (inferredValue == null) {
88-
inferenceBlock.appendNull();
89-
} else {
90-
inferenceBlock.appendBytesRef(inferredValue);
91-
}
84+
ActionListener<Tuple<Integer, BytesRef>> inferenceResponseListener = ActionListener.wrap(response -> {
85+
countDownLatch.countDown();
86+
inferredValues[response.v1()] = response.v2();
87+
if (countDownLatch.getCount() == 0) {
88+
BytesRefBlock.Builder inferenceBlock = blockFactory.newBytesRefBlockBuilder(inputPage.getPositionCount());
89+
90+
for (BytesRef inferredValue : inferredValues) {
91+
if (inferredValue == null) {
92+
inferenceBlock.appendNull();
93+
} else {
94+
inferenceBlock.appendBytesRef(inferredValue);
9295
}
93-
listener.onResponse(inputPage.appendBlock(inferenceBlock.build()));
9496
}
95-
},
96-
listener::onFailure
97-
);
97+
listener.onResponse(inputPage.appendBlock(inferenceBlock.build()));
98+
}
99+
}, listener::onFailure);
98100

99101
for (int position = 0; position < inputPage.getPositionCount(); position++) {
100102
final int currentPosition = position;
@@ -103,10 +105,13 @@ protected void performAsync(Page inputPage, ActionListener<Page> listener) {
103105
continue;
104106
}
105107

106-
doCompletion(promptBlock.getBytesRef(promptBlock.getFirstValueIndex(position), promptValue).utf8ToString(), ActionListener.wrap(
107-
completionResponse -> inferenceResponseListener.onResponse(Tuple.tuple(currentPosition, completionResponse)),
108-
listener::onFailure
109-
));
108+
doCompletion(
109+
promptBlock.getBytesRef(promptBlock.getFirstValueIndex(position), promptValue).utf8ToString(),
110+
ActionListener.wrap(
111+
completionResponse -> inferenceResponseListener.onResponse(Tuple.tuple(currentPosition, completionResponse)),
112+
listener::onFailure
113+
)
114+
);
110115
}
111116
}
112117

@@ -116,21 +121,16 @@ protected void doClose() {
116121
}
117122

118123
private void doCompletion(String prompt, ActionListener<BytesRef> listener) {
119-
inferenceService.infer(createInferenceRequest(prompt), ActionListener.wrap(
120-
inferenceResponse -> {
121-
if (inferenceResponse.getResults() instanceof ChatCompletionResults completionResults) {
122-
listener.onResponse(new BytesRef(completionResults.getResults().getFirst().predictedValue().toString()));
123-
return;
124-
}
125-
listener.onFailure(new Exception("WTF???"));
126-
},
127-
listener::onFailure
128-
));
124+
inferenceService.infer(createInferenceRequest(prompt), ActionListener.wrap(inferenceResponse -> {
125+
if (inferenceResponse.getResults() instanceof ChatCompletionResults completionResults) {
126+
listener.onResponse(new BytesRef(completionResults.getResults().getFirst().predictedValue().toString()));
127+
return;
128+
}
129+
listener.onFailure(new Exception("WTF???"));
130+
}, listener::onFailure));
129131
}
130132

131133
private InferenceAction.Request createInferenceRequest(String prompt) {
132-
return InferenceAction.Request.builder(inferenceId, TaskType.COMPLETION)
133-
.setInput(List.of(prompt))
134-
.build();
134+
return InferenceAction.Request.builder(inferenceId, TaskType.COMPLETION).setInput(List.of(prompt)).build();
135135
}
136136
}

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

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ public record Factory(
4747
@Override
4848
public RerankOperator get(DriverContext driverContext) {
4949

50-
5150
return new RerankOperator(
5251
inferenceService,
5352
inferenceId,
@@ -59,14 +58,13 @@ public RerankOperator get(DriverContext driverContext) {
5958
);
6059
}
6160

62-
6361
private Map<String, EvalOperator.ExpressionEvaluator> buildRerankFieldEvaluator(
6462
Map<String, EvalOperator.ExpressionEvaluator.Factory> rerankFieldsEvaluatorSuppliers,
6563
DriverContext driverContext
6664
) {
6765
Map<String, EvalOperator.ExpressionEvaluator> rerankFieldsEvaluators = new HashMap<>();
6866

69-
for (var entry: rerankFieldsEvaluatorSuppliers.entrySet()) {
67+
for (var entry : rerankFieldsEvaluatorSuppliers.entrySet()) {
7068
rerankFieldsEvaluators.put(entry.getKey(), entry.getValue().get(driverContext));
7169
}
7270

@@ -181,14 +179,14 @@ private InferenceAction.Request buildInferenceRequest(Page inputPage) throws IOE
181179
String[] inputs = new String[inputPage.getPositionCount()];
182180
Map<String, Block> inputBlocks = new HashMap<>();
183181

184-
185-
for (var entry :rerankFieldsEvaluator.entrySet()) {
182+
for (var entry : rerankFieldsEvaluator.entrySet()) {
186183
inputBlocks.put(entry.getKey(), entry.getValue().eval(inputPage));
187-
};
184+
}
185+
;
188186

189187
for (int pos = 0; pos < inputPage.getPositionCount(); pos++) {
190188
try (XContentBuilder yamlBuilder = XContentFactory.yamlBuilder().startObject()) {
191-
for (var blockEntry: inputBlocks.entrySet()) {
189+
for (var blockEntry : inputBlocks.entrySet()) {
192190
String fieldName = blockEntry.getKey();
193191
Block currentBlock = blockEntry.getValue();
194192
if (currentBlock.isNull(pos)) {
@@ -202,7 +200,6 @@ private InferenceAction.Request buildInferenceRequest(Page inputPage) throws IOE
202200
}
203201
}
204202

205-
206203
return InferenceAction.Request.builder(inferenceId, TaskType.RERANK).setInput(List.of(inputs)).setQuery(queryText).build();
207204
}
208205

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/optimizer/rules/logical/PushDownAndCombineLimits.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,11 @@ public LogicalPlan rule(Limit limit, LogicalOptimizerContext ctx) {
3737
var l2 = (int) childLimit.limit().fold(ctx.foldCtx());
3838
return new Limit(limit.source(), Literal.of(limitSource, Math.min(l1, l2)), childLimit.child());
3939
} else if (limit.child() instanceof UnaryPlan unary) {
40-
if (unary instanceof Eval || unary instanceof Project || unary instanceof RegexExtract || unary instanceof Enrich || unary instanceof Completion) {
40+
if (unary instanceof Eval
41+
|| unary instanceof Project
42+
|| unary instanceof RegexExtract
43+
|| unary instanceof Enrich
44+
|| unary instanceof Completion) {
4145
return unary.replaceChild(limit.replaceChild(unary.child()));
4246
} else if (unary instanceof MvExpand mvx) {
4347
// MV_EXPAND can increase the number of rows, so we cannot just push the limit down

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -605,8 +605,6 @@ public PlanFactory visitRerankCommand(EsqlBaseParser.RerankCommandContext ctx) {
605605
);
606606
}
607607

608-
609-
610608
@Override
611609
public PlanFactory visitCompletionCommand(EsqlBaseParser.CompletionCommandContext ctx) {
612610
Source source = source(ctx);

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/plan/logical/inference/Completion.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@
3030

3131
public class Completion extends InferencePlan implements GeneratingPlan<Completion> {
3232

33-
public static final NamedWriteableRegistry.Entry ENTRY = new NamedWriteableRegistry.Entry(LogicalPlan.class, "Completion", Completion::new);
33+
public static final NamedWriteableRegistry.Entry ENTRY = new NamedWriteableRegistry.Entry(
34+
LogicalPlan.class,
35+
"Completion",
36+
Completion::new
37+
);
3438

3539
private final Expression prompt;
3640
private final ReferenceAttribute target;
@@ -58,14 +62,18 @@ public void writeTo(StreamOutput out) throws IOException {
5862
out.writeNamedWriteable(target);
5963
}
6064

61-
6265
@Override
6366
public Completion withGeneratedNames(List<String> newNames) {
6467
checkNumberOfNewNames(newNames);
65-
return new Completion(source(), child(), inferenceId(), prompt, new ReferenceAttribute(Source.EMPTY, newNames.getFirst(), DataType.KEYWORD));
68+
return new Completion(
69+
source(),
70+
child(),
71+
inferenceId(),
72+
prompt,
73+
new ReferenceAttribute(Source.EMPTY, newNames.getFirst(), DataType.KEYWORD)
74+
);
6675
}
6776

68-
6977
public ReferenceAttribute target() {
7078
return target;
7179
}

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/plan/logical/inference/Rerank.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ public UnaryPlan replaceChild(LogicalPlan newChild) {
7979
return new Rerank(source(), newChild, inferenceId(), queryText, rerankFields);
8080
}
8181

82-
8382
@Override
8483
protected AttributeSet computeReferences() {
8584
return computeReferences(rerankFields);

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/plan/physical/inference/CompletionExec.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,9 @@ public boolean equals(Object obj) {
112112
return false;
113113
}
114114
CompletionExec other = ((CompletionExec) obj);
115-
return Objects.equals(target, other.target) && Objects.equals(prompt, other.prompt) && Objects.equals(inferenceId, other.inferenceId);
115+
return Objects.equals(target, other.target)
116+
&& Objects.equals(prompt, other.prompt)
117+
&& Objects.equals(inferenceId, other.inferenceId);
116118
}
117119

118120
@Override

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -701,8 +701,11 @@ private PhysicalOperation planRerank(RerankExec rerank, LocalExecutionPlannerCon
701701

702702
Map<String, EvalOperator.ExpressionEvaluator.Factory> rerankFieldsEvaluatorSuppliers = new HashMap<>();
703703

704-
for (var rerankField: rerank.rerankFields()) {
705-
rerankFieldsEvaluatorSuppliers.put(rerankField.name(), EvalMapper.toEvaluator(context.foldCtx(), rerankField.child(), source.layout));
704+
for (var rerankField : rerank.rerankFields()) {
705+
rerankFieldsEvaluatorSuppliers.put(
706+
rerankField.name(),
707+
EvalMapper.toEvaluator(context.foldCtx(), rerankField.child(), source.layout)
708+
);
706709
}
707710

708711
String inferenceId = rerank.inferenceId();

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,12 @@ private PhysicalPlan mapBinary(BinaryPlan bp) {
229229
}
230230

231231
public static boolean isPipelineBreaker(LogicalPlan p) {
232-
return p instanceof Aggregate || p instanceof TopN || p instanceof Limit || p instanceof OrderBy || p instanceof Rerank || p instanceof Completion;
232+
return p instanceof Aggregate
233+
|| p instanceof TopN
234+
|| p instanceof Limit
235+
|| p instanceof OrderBy
236+
|| p instanceof Rerank
237+
|| p instanceof Completion;
233238
}
234239

235240
private PhysicalPlan addExchangeForFragment(LogicalPlan logical, PhysicalPlan child) {

0 commit comments

Comments
 (0)