|
| 1 | +/* |
| 2 | + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one |
| 3 | + * or more contributor license agreements. Licensed under the Elastic License |
| 4 | + * 2.0; you may not use this file except in compliance with the Elastic License |
| 5 | + * 2.0. |
| 6 | + */ |
| 7 | +package org.elasticsearch.xpack.esql.evaluator.predicate.operator.logical; |
| 8 | + |
| 9 | +import org.elasticsearch.compute.data.Block; |
| 10 | +import org.elasticsearch.compute.data.DoubleBlock; |
| 11 | +import org.elasticsearch.compute.data.DoubleVector; |
| 12 | +import org.elasticsearch.compute.data.Page; |
| 13 | +import org.elasticsearch.compute.operator.DriverContext; |
| 14 | +import org.elasticsearch.compute.operator.EvalOperator; |
| 15 | +import org.elasticsearch.compute.operator.Warnings; |
| 16 | +import org.elasticsearch.core.Releasables; |
| 17 | +import org.elasticsearch.xpack.esql.core.tree.Source; |
| 18 | +import org.elasticsearch.xpack.esql.evaluator.mapper.BooleanToScoringExpressionEvaluator; |
| 19 | + |
| 20 | +import static org.elasticsearch.compute.lucene.LuceneQueryExpressionEvaluator.SCORE_FOR_FALSE; |
| 21 | + |
| 22 | +/** |
| 23 | + * {@link EvalOperator.ExpressionEvaluator} implementation for {@link Not}. |
| 24 | + * This class is generated. Do not edit it. |
| 25 | + */ |
| 26 | +public final class NotScoringEvaluator implements EvalOperator.ExpressionEvaluator { |
| 27 | + private final Source source; |
| 28 | + |
| 29 | + private final EvalOperator.ExpressionEvaluator v; |
| 30 | + |
| 31 | + private final DriverContext driverContext; |
| 32 | + |
| 33 | + private Warnings warnings; |
| 34 | + |
| 35 | + public NotScoringEvaluator(Source source, EvalOperator.ExpressionEvaluator v, DriverContext driverContext) { |
| 36 | + this.source = source; |
| 37 | + this.v = v; |
| 38 | + this.driverContext = driverContext; |
| 39 | + } |
| 40 | + |
| 41 | + @Override |
| 42 | + public Block eval(Page page) { |
| 43 | + try (DoubleBlock vBlock = (DoubleBlock) v.eval(page)) { |
| 44 | + DoubleVector vVector = vBlock.asVector(); |
| 45 | + if (vVector == null) { |
| 46 | + return eval(page.getPositionCount(), vBlock); |
| 47 | + } |
| 48 | + return eval(page.getPositionCount(), vVector).asBlock(); |
| 49 | + } |
| 50 | + } |
| 51 | + |
| 52 | + public DoubleBlock eval(int positionCount, DoubleBlock vBlock) { |
| 53 | + try (DoubleBlock.Builder result = driverContext.blockFactory().newDoubleBlockBuilder(positionCount)) { |
| 54 | + position: for (int p = 0; p < positionCount; p++) { |
| 55 | + if (vBlock.isNull(p)) { |
| 56 | + result.appendNull(); |
| 57 | + continue position; |
| 58 | + } |
| 59 | + if (vBlock.getValueCount(p) != 1) { |
| 60 | + if (vBlock.getValueCount(p) > 1) { |
| 61 | + warnings().registerException(new IllegalArgumentException("single-value function encountered multi-value")); |
| 62 | + } |
| 63 | + result.appendNull(); |
| 64 | + continue position; |
| 65 | + } |
| 66 | + result.appendDouble(evaluate(vBlock.getDouble(vBlock.getFirstValueIndex(p)))); |
| 67 | + } |
| 68 | + return result.build(); |
| 69 | + } |
| 70 | + } |
| 71 | + |
| 72 | + private static Double evaluate(Double v) { |
| 73 | + return v == SCORE_FOR_FALSE ? 0.0 : SCORE_FOR_FALSE; |
| 74 | + } |
| 75 | + |
| 76 | + public DoubleVector eval(int positionCount, DoubleVector vVector) { |
| 77 | + try (DoubleVector.FixedBuilder result = driverContext.blockFactory().newDoubleVectorFixedBuilder(positionCount)) { |
| 78 | + position: for (int p = 0; p < positionCount; p++) { |
| 79 | + result.appendDouble(evaluate(vVector.getDouble(p))); |
| 80 | + } |
| 81 | + return result.build(); |
| 82 | + } |
| 83 | + } |
| 84 | + |
| 85 | + @Override |
| 86 | + public String toString() { |
| 87 | + return "NotEvaluator[" + "v=" + v + "]"; |
| 88 | + } |
| 89 | + |
| 90 | + @Override |
| 91 | + public void close() { |
| 92 | + Releasables.closeExpectNoException(v); |
| 93 | + } |
| 94 | + |
| 95 | + private Warnings warnings() { |
| 96 | + if (warnings == null) { |
| 97 | + this.warnings = Warnings.createWarnings( |
| 98 | + driverContext.warningsMode(), |
| 99 | + source.source().getLineNumber(), |
| 100 | + source.source().getColumnNumber(), |
| 101 | + source.text() |
| 102 | + ); |
| 103 | + } |
| 104 | + return warnings; |
| 105 | + } |
| 106 | + |
| 107 | + public static class Factory implements EvalOperator.ExpressionEvaluator.Factory { |
| 108 | + private final Source source; |
| 109 | + |
| 110 | + private final EvalOperator.ExpressionEvaluator.Factory v; |
| 111 | + |
| 112 | + public Factory(Source source, EvalOperator.ExpressionEvaluator.Factory v) { |
| 113 | + this.source = source; |
| 114 | + this.v = v; |
| 115 | + } |
| 116 | + |
| 117 | + @Override |
| 118 | + public NotScoringEvaluator get(DriverContext context) { |
| 119 | + return new NotScoringEvaluator(source, new BooleanToScoringExpressionEvaluator(v.get(context), context), context); |
| 120 | + } |
| 121 | + |
| 122 | + @Override |
| 123 | + public String toString() { |
| 124 | + return "NotEvaluator[" + "v=" + v + "]"; |
| 125 | + } |
| 126 | + } |
| 127 | +} |
0 commit comments