Skip to content

Commit edc3592

Browse files
author
elasticsearchmachine
committed
Refactor
1 parent 482dfec commit edc3592

File tree

1 file changed

+2
-10
lines changed

1 file changed

+2
-10
lines changed

x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/lucene/LuceneTopNSourceOperator.java

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -278,14 +278,11 @@ private Page emit() {
278278
for(int i = 0; i < sortValuesBlockBuilders.length; i++) {
279279
sortValuesBlockBuilders[i] = blockFactory.newDoubleBlockBuilder(size);
280280
}
281-
DoubleBlock[] sortValuesBlocks = null;
282-
283281
try (
284282
IntVector.Builder currentSegmentBuilder = blockFactory.newIntVectorFixedBuilder(size);
285283
IntVector.Builder currentDocsBuilder = blockFactory.newIntVectorFixedBuilder(size);
286284
DoubleVector.Builder currentScoresBuilder = scoreVectorOrNull(size);
287285
) {
288-
289286
int start = offset;
290287
offset += size;
291288
List<LeafReaderContext> leafContexts = perShardCollector.shardContext.searcher().getLeafContexts();
@@ -298,15 +295,12 @@ private Page emit() {
298295
float score = getScore(topDocs[i]);
299296
currentScoresBuilder.appendDouble(score);
300297
}
301-
// TODO Get the blocks according to the sort types for the sorts to extract - could be different types
302-
// Should we do the script field type materialization later? So it's part of loading the field via a script?
303-
// We don't reuse the order, but it's similar to how fetching source works.
304298
if ((extractSortCount > 0) && topDocs[i] instanceof FieldDoc fieldDoc) {
305299
int sortIndex = 0;
306300
int extractedSortIndex = 0;
307301
for (SortBuilder<?> sortBuilder : sorts) {
308302
if (sortBuilder instanceof ScriptSortBuilder) {
309-
Object sortValue = ((FieldDoc) topDocs[i]).fields[sortIndex];
303+
Object sortValue = fieldDoc.fields[sortIndex];
310304
if (sortValue == null) {
311305
sortValuesBlockBuilders[extractedSortIndex].appendNull();
312306
} else if (sortValue instanceof Number numberSort) {
@@ -337,11 +331,9 @@ private Page emit() {
337331
scores = currentScoresBuilder.build().asBlock();
338332
page = new Page(size, docBlock, scores);
339333
}
340-
sortValuesBlocks = new DoubleBlock[extractSortCount];
341334
for(int i = 0; i < extractSortCount; i++) {
342-
sortValuesBlocks[i] = sortValuesBlockBuilders[i].build();
335+
page = page.appendBlock(sortValuesBlockBuilders[i].build());
343336
}
344-
page = page.appendBlocks(sortValuesBlocks);
345337
} finally {
346338
if (page == null) {
347339
Releasables.closeExpectNoException(shard, segments, docs, docBlock, scores);

0 commit comments

Comments
 (0)