|
14 | 14 | import org.elasticsearch.compute.data.BooleanBlock; |
15 | 15 | import org.elasticsearch.compute.data.BooleanVector; |
16 | 16 | import org.elasticsearch.compute.data.DoubleBlock; |
17 | | -import org.elasticsearch.compute.data.DoubleVector; |
18 | 17 | import org.elasticsearch.compute.data.ElementType; |
19 | 18 | import org.elasticsearch.compute.data.Page; |
20 | 19 | import org.elasticsearch.compute.data.Vector; |
|
27 | 26 | import org.elasticsearch.xpack.esql.core.expression.Expression; |
28 | 27 | import org.elasticsearch.xpack.esql.core.expression.FoldContext; |
29 | 28 | import org.elasticsearch.xpack.esql.core.expression.Literal; |
30 | | -import org.elasticsearch.xpack.esql.core.tree.Source; |
31 | 29 | import org.elasticsearch.xpack.esql.evaluator.mapper.EvaluatorMapper; |
32 | 30 | import org.elasticsearch.xpack.esql.evaluator.mapper.ExpressionMapper; |
33 | | -import org.elasticsearch.xpack.esql.evaluator.predicate.operator.logical.NotEvaluator; |
34 | 31 | import org.elasticsearch.xpack.esql.expression.predicate.logical.BinaryLogic; |
35 | 32 | import org.elasticsearch.xpack.esql.expression.predicate.logical.Not; |
36 | 33 | import org.elasticsearch.xpack.esql.expression.predicate.nulls.IsNotNull; |
@@ -215,43 +212,12 @@ public ExpressionEvaluator.Factory map( |
215 | 212 | List<ShardContext> shardContexts, |
216 | 213 | boolean usesScoring |
217 | 214 | ) { |
218 | | - record NotScoreEvaluator(Source source, NotEvaluator notEval, ExpressionEvaluator innerEval, DriverContext driverContext) |
219 | | - implements |
220 | | - ExpressionEvaluator { |
221 | | - @Override |
222 | | - public Block eval(Page page) { |
223 | | - return notEval.eval(page); |
224 | | - } |
225 | | - |
226 | | - @Override |
227 | | - // NotEvaluator is a final, generated class - create this record to override score method |
228 | | - public DoubleBlock score(Page page, BlockFactory blockFactory) { |
229 | | - try (DoubleBlock scoreBlock = innerEval.score(page, blockFactory)) { |
230 | | - DoubleVector scoreVector = scoreBlock.asVector(); |
231 | | - DoubleVector.Builder result = blockFactory.newDoubleVectorFixedBuilder(page.getPositionCount()); |
232 | | - // TODO We could optimize for constant vectors |
233 | | - for (int i = 0; i < scoreVector.getPositionCount(); i++) { |
234 | | - result.appendDouble(scoreVector.getDouble(i) == NO_MATCH_SCORE ? MATCH_SCORE : NO_MATCH_SCORE); |
235 | | - } |
236 | | - return result.build().asBlock(); |
237 | | - } |
238 | | - } |
239 | | - |
240 | | - @Override |
241 | | - public void close() { |
242 | | - Releasables.closeExpectNoException(notEval, innerEval); |
243 | | - } |
244 | | - } |
245 | | - |
246 | | - return driverContext -> { |
247 | | - var expEval = toEvaluator(foldCtx, not.field(), layout, shardContexts, usesScoring); |
248 | | - ExpressionEvaluator innerEval = expEval.get(driverContext); |
249 | | - NotEvaluator notEvaluator = new NotEvaluator(not.source(), innerEval, driverContext); |
250 | | - if (usesScoring) { |
251 | | - return new NotScoreEvaluator(not.source(), notEvaluator, innerEval, driverContext); |
252 | | - } |
253 | | - return notEvaluator; |
254 | | - }; |
| 215 | + var expEval = toEvaluator(foldCtx, not.field(), layout); |
| 216 | + return dvrCtx -> new org.elasticsearch.xpack.esql.evaluator.predicate.operator.logical.NotEvaluator( |
| 217 | + not.source(), |
| 218 | + expEval.get(dvrCtx), |
| 219 | + dvrCtx |
| 220 | + ); |
255 | 221 | } |
256 | 222 | } |
257 | 223 |
|
@@ -400,22 +366,6 @@ public Block eval(Page page) { |
400 | 366 | } |
401 | 367 | } |
402 | 368 |
|
403 | | - @Override |
404 | | - public DoubleBlock score(Page page, BlockFactory blockFactory) { |
405 | | - // TODO We could skip re-evaluating the field if we store the result of eval() |
406 | | - try (Block fieldBlock = field.eval(page)) { |
407 | | - if (fieldBlock.asVector() != null) { |
408 | | - return driverContext.blockFactory().newConstantDoubleBlockWith(NO_MATCH_SCORE, page.getPositionCount()); |
409 | | - } |
410 | | - try (var builder = driverContext.blockFactory().newDoubleVectorFixedBuilder(page.getPositionCount())) { |
411 | | - for (int p = 0; p < page.getPositionCount(); p++) { |
412 | | - builder.appendDouble(p, fieldBlock.isNull(p) ? MATCH_SCORE : NO_MATCH_SCORE); |
413 | | - } |
414 | | - return builder.build().asBlock(); |
415 | | - } |
416 | | - } |
417 | | - } |
418 | | - |
419 | 369 | @Override |
420 | 370 | public void close() { |
421 | 371 | Releasables.closeExpectNoException(field); |
@@ -471,22 +421,6 @@ public Block eval(Page page) { |
471 | 421 | } |
472 | 422 | } |
473 | 423 |
|
474 | | - @Override |
475 | | - public DoubleBlock score(Page page, BlockFactory blockFactory) { |
476 | | - // TODO We could skip re-evaluating the field if we store the result of eval() |
477 | | - try (Block fieldBlock = field.eval(page)) { |
478 | | - if (fieldBlock.asVector() != null) { |
479 | | - return driverContext.blockFactory().newConstantDoubleBlockWith(MATCH_SCORE, page.getPositionCount()); |
480 | | - } |
481 | | - try (var builder = driverContext.blockFactory().newDoubleVectorFixedBuilder(page.getPositionCount())) { |
482 | | - for (int p = 0; p < page.getPositionCount(); p++) { |
483 | | - builder.appendDouble(p, fieldBlock.isNull(p) ? NO_MATCH_SCORE : MATCH_SCORE); |
484 | | - } |
485 | | - return builder.build().asBlock(); |
486 | | - } |
487 | | - } |
488 | | - } |
489 | | - |
490 | 424 | @Override |
491 | 425 | public void close() { |
492 | 426 | Releasables.closeExpectNoException(field); |
|
0 commit comments