Skip to content

Commit ee3c806

Browse files
committed
Make ScoreOperator and LuceneQueryEvaluator more robust
1 parent 098140e commit ee3c806

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,16 @@ protected LuceneQueryEvaluator(BlockFactory blockFactory, ShardConfig[] shards)
6161
}
6262

6363
public Block executeQuery(Page page) {
64-
// Lucene based operators retrieve DocVectors as first block
65-
Block block = page.getBlock(0);
66-
assert block instanceof DocBlock : "LuceneQueryExpressionEvaluator expects DocBlock as input";
67-
DocVector docs = (DocVector) block.asVector();
64+
// Search for DocVector block
65+
Block docBlock = null;
66+
for (int i = 0; i < page.getBlockCount(); i++) {
67+
if (page.getBlock(i) instanceof DocBlock) {
68+
docBlock = page.getBlock(i);
69+
break;
70+
}
71+
}
72+
assert docBlock != null : "LuceneQueryExpressionEvaluator expects a DocBlock";
73+
DocVector docs = (DocVector) docBlock.asVector();
6874
try {
6975
if (docs.singleSegmentNonDecreasing()) {
7076
return evalSingleSegmentNonDecreasing(docs).asBlock();

x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/operator/ScoreOperator.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
import org.elasticsearch.compute.data.Block;
1111
import org.elasticsearch.compute.data.BlockFactory;
12-
import org.elasticsearch.compute.data.DocVector;
1312
import org.elasticsearch.compute.data.DoubleBlock;
1413
import org.elasticsearch.compute.data.DoubleVector;
1514
import org.elasticsearch.compute.data.Page;
@@ -46,9 +45,9 @@ public ScoreOperator(BlockFactory blockFactory, ExpressionScorer scorer, int sco
4645

4746
@Override
4847
protected Page process(Page page) {
49-
assert page.getBlockCount() >= 2 : "Expected at least 2 blocks, got " + page.getBlockCount();
50-
assert page.getBlock(0).asVector() instanceof DocVector : "Expected a DocVector, got " + page.getBlock(0).asVector();
51-
assert page.getBlock(1).asVector() instanceof DoubleVector : "Expected a DoubleVector, got " + page.getBlock(1).asVector();
48+
assert page.getBlockCount() > scoreBlockPosition : "Expected to get a score block in position " + scoreBlockPosition;
49+
assert page.getBlock(scoreBlockPosition).asVector() instanceof DoubleVector
50+
: "Expected a DoubleVector as a score block, got " + page.getBlock(scoreBlockPosition).asVector();
5251

5352
Block[] blocks = new Block[page.getBlockCount()];
5453
for (int i = 0; i < page.getBlockCount(); i++) {

0 commit comments

Comments
 (0)