Skip to content

Commit 4aecaea

Browse files
committed
Fix when to apply BooleanToScoringExpressionEvaluator
1 parent 2bd2361 commit 4aecaea

File tree

3 files changed

+21
-14
lines changed

3 files changed

+21
-14
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ protected Page process(Page page) {
5858
return null;
5959
}
6060
for (int p = 0; p < page.getPositionCount(); p++) {
61-
if (scoreBlock.isNull(p) || scoreBlock.getValueCount(p) != SCORE_BLOCK_INDEX) {
61+
if (scoreBlock.isNull(p) || scoreBlock.getValueCount(p) != 1) {
6262
// Null is like false
6363
// And, for now, multivalued results are like false too
6464
continue;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,12 +116,12 @@ public ExpressionEvaluator.Factory map(
116116
var rightEval = toEvaluator(foldCtx, bc.right(), layout, shardContexts, usesScoring);
117117
final ExpressionEvaluator.Factory leftEvalFactory;
118118
final ExpressionEvaluator.Factory rightEvalFactory;
119-
if (usesScoring && bc.left() instanceof FullTextFunction == false) {
119+
if (usesScoring) {
120120
leftEvalFactory = new BooleanToScoringExpressionEvaluator.Factory(leftEval);
121121
} else {
122122
leftEvalFactory = leftEval;
123123
}
124-
if (usesScoring && bc.right() instanceof FullTextFunction == false) {
124+
if (usesScoring) {
125125
rightEvalFactory = new BooleanToScoringExpressionEvaluator.Factory(rightEval);
126126
} else {
127127
rightEvalFactory = rightEval;

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/evaluator/mapper/BooleanToScoringExpressionEvaluator.java

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,23 +29,28 @@ public BooleanToScoringExpressionEvaluator(EvalOperator.ExpressionEvaluator inne
2929

3030
@Override
3131
public Block eval(Page page) {
32-
try (Block innerBlock = inner.eval(page)) {
33-
if ((innerBlock == null) || innerBlock.areAllValuesNull()) {
34-
return innerBlock;
35-
}
32+
Block innerBlock = inner.eval(page);
33+
if ((innerBlock == null) || innerBlock.areAllValuesNull()) {
34+
return innerBlock;
35+
}
3636

37-
if (innerBlock instanceof BooleanBlock == false) {
38-
throw new IllegalArgumentException("Unexpected block type: " + innerBlock.getClass());
39-
}
37+
if (innerBlock instanceof DoubleBlock) {
38+
// It's already a scoring block - no need to convert
39+
return innerBlock;
40+
}
4041

41-
return eval((BooleanBlock) innerBlock);
42+
if (innerBlock instanceof BooleanBlock == false) {
43+
throw new IllegalArgumentException("Unexpected block type: " + innerBlock.getClass());
4244
}
45+
46+
return eval((BooleanBlock) innerBlock);
4347
}
4448

4549
private DoubleBlock eval(BooleanBlock booleanBlock) {
46-
int positionCount = booleanBlock.getPositionCount();
47-
48-
try (DoubleBlock.Builder builder = driverContext.blockFactory().newDoubleBlockBuilder(positionCount)) {
50+
DoubleBlock.Builder builder = null;
51+
try {
52+
int positionCount = booleanBlock.getPositionCount();
53+
builder = driverContext.blockFactory().newDoubleBlockBuilder(positionCount);
4954
for (int i = 0; i < positionCount; i++) {
5055
boolean value = booleanBlock.getBoolean(i);
5156
if (value) {
@@ -56,6 +61,8 @@ private DoubleBlock eval(BooleanBlock booleanBlock) {
5661
}
5762

5863
return builder.build();
64+
} finally {
65+
Releasables.closeExpectNoException(builder, booleanBlock);
5966
}
6067
}
6168

0 commit comments

Comments
 (0)