Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ESQL: Add DriverContext to the construction of Evaluators #99518

Merged
merged 8 commits into from
Sep 13, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
restore accidentally removed file
ChrisHegarty committed Sep 13, 2023
commit eb20d9edffd9f318d04042fd43ab3b90349aa068
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
// 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.predicate.operator.arithmetic;

import java.lang.ArithmeticException;
import java.lang.Override;
import java.lang.String;
import org.elasticsearch.compute.data.Block;
import org.elasticsearch.compute.data.LongBlock;
import org.elasticsearch.compute.data.LongVector;
import org.elasticsearch.compute.data.Page;
import org.elasticsearch.compute.operator.DriverContext;
import org.elasticsearch.compute.operator.EvalOperator;
import org.elasticsearch.xpack.esql.expression.function.Warnings;
import org.elasticsearch.xpack.ql.tree.Source;

/**
* {@link EvalOperator.ExpressionEvaluator} implementation for {@link Sub}.
* This class is generated. Do not edit it.
*/
public final class SubUnsignedLongsEvaluator implements EvalOperator.ExpressionEvaluator {
private final Warnings warnings;

private final EvalOperator.ExpressionEvaluator lhs;

private final EvalOperator.ExpressionEvaluator rhs;

private final DriverContext driverContext;

public SubUnsignedLongsEvaluator(Source source, EvalOperator.ExpressionEvaluator lhs,
EvalOperator.ExpressionEvaluator rhs, DriverContext driverContext) {
this.warnings = new Warnings(source);
this.lhs = lhs;
this.rhs = rhs;
this.driverContext = driverContext;
}

@Override
public Block eval(Page page) {
Block lhsUncastBlock = lhs.eval(page);
if (lhsUncastBlock.areAllValuesNull()) {
return Block.constantNullBlock(page.getPositionCount());
}
LongBlock lhsBlock = (LongBlock) lhsUncastBlock;
Block rhsUncastBlock = rhs.eval(page);
if (rhsUncastBlock.areAllValuesNull()) {
return Block.constantNullBlock(page.getPositionCount());
}
LongBlock rhsBlock = (LongBlock) rhsUncastBlock;
LongVector lhsVector = lhsBlock.asVector();
if (lhsVector == null) {
return eval(page.getPositionCount(), lhsBlock, rhsBlock);
}
LongVector rhsVector = rhsBlock.asVector();
if (rhsVector == null) {
return eval(page.getPositionCount(), lhsBlock, rhsBlock);
}
return eval(page.getPositionCount(), lhsVector, rhsVector);
}

public LongBlock eval(int positionCount, LongBlock lhsBlock, LongBlock rhsBlock) {
LongBlock.Builder result = LongBlock.newBlockBuilder(positionCount);
position: for (int p = 0; p < positionCount; p++) {
if (lhsBlock.isNull(p) || lhsBlock.getValueCount(p) != 1) {
result.appendNull();
continue position;
}
if (rhsBlock.isNull(p) || rhsBlock.getValueCount(p) != 1) {
result.appendNull();
continue position;
}
try {
result.appendLong(Sub.processUnsignedLongs(lhsBlock.getLong(lhsBlock.getFirstValueIndex(p)), rhsBlock.getLong(rhsBlock.getFirstValueIndex(p))));
} catch (ArithmeticException e) {
warnings.registerException(e);
result.appendNull();
}
}
return result.build();
}

public LongBlock eval(int positionCount, LongVector lhsVector, LongVector rhsVector) {
LongBlock.Builder result = LongBlock.newBlockBuilder(positionCount);
position: for (int p = 0; p < positionCount; p++) {
try {
result.appendLong(Sub.processUnsignedLongs(lhsVector.getLong(p), rhsVector.getLong(p)));
} catch (ArithmeticException e) {
warnings.registerException(e);
result.appendNull();
}
}
return result.build();
}

@Override
public String toString() {
return "SubUnsignedLongsEvaluator[" + "lhs=" + lhs + ", rhs=" + rhs + "]";
}
}