|
@@ -0,0 +1,137 @@
|
|
|
+// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
|
|
+// or more contributor license agreements. Licensed under the Elastic License
|
|
|
+// 2.0; you may not use this file except in compliance with the Elastic License
|
|
|
+// 2.0.
|
|
|
+package org.elasticsearch.xpack.esql.expression.function.scalar.string;
|
|
|
+
|
|
|
+import java.lang.ArithmeticException;
|
|
|
+import java.lang.IllegalArgumentException;
|
|
|
+import java.lang.Override;
|
|
|
+import java.lang.String;
|
|
|
+import org.apache.lucene.util.BytesRef;
|
|
|
+import org.elasticsearch.compute.data.Block;
|
|
|
+import org.elasticsearch.compute.data.BytesRefBlock;
|
|
|
+import org.elasticsearch.compute.data.BytesRefVector;
|
|
|
+import org.elasticsearch.compute.data.IntBlock;
|
|
|
+import org.elasticsearch.compute.data.Page;
|
|
|
+import org.elasticsearch.compute.operator.DriverContext;
|
|
|
+import org.elasticsearch.compute.operator.EvalOperator;
|
|
|
+import org.elasticsearch.compute.operator.Warnings;
|
|
|
+import org.elasticsearch.core.Releasables;
|
|
|
+import org.elasticsearch.xpack.esql.core.tree.Source;
|
|
|
+
|
|
|
+/**
|
|
|
+ * {@link EvalOperator.ExpressionEvaluator} implementation for {@link BitLength}.
|
|
|
+ * This class is generated. Do not edit it.
|
|
|
+ */
|
|
|
+public final class BitLengthEvaluator implements EvalOperator.ExpressionEvaluator {
|
|
|
+ private final Source source;
|
|
|
+
|
|
|
+ private final EvalOperator.ExpressionEvaluator val;
|
|
|
+
|
|
|
+ private final DriverContext driverContext;
|
|
|
+
|
|
|
+ private Warnings warnings;
|
|
|
+
|
|
|
+ public BitLengthEvaluator(Source source, EvalOperator.ExpressionEvaluator val,
|
|
|
+ DriverContext driverContext) {
|
|
|
+ this.source = source;
|
|
|
+ this.val = val;
|
|
|
+ this.driverContext = driverContext;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Block eval(Page page) {
|
|
|
+ try (BytesRefBlock valBlock = (BytesRefBlock) val.eval(page)) {
|
|
|
+ BytesRefVector valVector = valBlock.asVector();
|
|
|
+ if (valVector == null) {
|
|
|
+ return eval(page.getPositionCount(), valBlock);
|
|
|
+ }
|
|
|
+ return eval(page.getPositionCount(), valVector);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public IntBlock eval(int positionCount, BytesRefBlock valBlock) {
|
|
|
+ try(IntBlock.Builder result = driverContext.blockFactory().newIntBlockBuilder(positionCount)) {
|
|
|
+ BytesRef valScratch = new BytesRef();
|
|
|
+ position: for (int p = 0; p < positionCount; p++) {
|
|
|
+ if (valBlock.isNull(p)) {
|
|
|
+ result.appendNull();
|
|
|
+ continue position;
|
|
|
+ }
|
|
|
+ if (valBlock.getValueCount(p) != 1) {
|
|
|
+ if (valBlock.getValueCount(p) > 1) {
|
|
|
+ warnings().registerException(new IllegalArgumentException("single-value function encountered multi-value"));
|
|
|
+ }
|
|
|
+ result.appendNull();
|
|
|
+ continue position;
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ result.appendInt(BitLength.process(valBlock.getBytesRef(valBlock.getFirstValueIndex(p), valScratch)));
|
|
|
+ } catch (ArithmeticException e) {
|
|
|
+ warnings().registerException(e);
|
|
|
+ result.appendNull();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return result.build();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public IntBlock eval(int positionCount, BytesRefVector valVector) {
|
|
|
+ try(IntBlock.Builder result = driverContext.blockFactory().newIntBlockBuilder(positionCount)) {
|
|
|
+ BytesRef valScratch = new BytesRef();
|
|
|
+ position: for (int p = 0; p < positionCount; p++) {
|
|
|
+ try {
|
|
|
+ result.appendInt(BitLength.process(valVector.getBytesRef(p, valScratch)));
|
|
|
+ } catch (ArithmeticException e) {
|
|
|
+ warnings().registerException(e);
|
|
|
+ result.appendNull();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return result.build();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String toString() {
|
|
|
+ return "BitLengthEvaluator[" + "val=" + val + "]";
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void close() {
|
|
|
+ Releasables.closeExpectNoException(val);
|
|
|
+ }
|
|
|
+
|
|
|
+ private Warnings warnings() {
|
|
|
+ if (warnings == null) {
|
|
|
+ this.warnings = Warnings.createWarnings(
|
|
|
+ driverContext.warningsMode(),
|
|
|
+ source.source().getLineNumber(),
|
|
|
+ source.source().getColumnNumber(),
|
|
|
+ source.text()
|
|
|
+ );
|
|
|
+ }
|
|
|
+ return warnings;
|
|
|
+ }
|
|
|
+
|
|
|
+ static class Factory implements EvalOperator.ExpressionEvaluator.Factory {
|
|
|
+ private final Source source;
|
|
|
+
|
|
|
+ private final EvalOperator.ExpressionEvaluator.Factory val;
|
|
|
+
|
|
|
+ public Factory(Source source, EvalOperator.ExpressionEvaluator.Factory val) {
|
|
|
+ this.source = source;
|
|
|
+ this.val = val;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public BitLengthEvaluator get(DriverContext context) {
|
|
|
+ return new BitLengthEvaluator(source, val.get(context), context);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String toString() {
|
|
|
+ return "BitLengthEvaluator[" + "val=" + val + "]";
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|