forked from elastic/elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
68dcc09
commit eb20d9e
Showing
1 changed file
with
101 additions
and
0 deletions.
There are no files selected for viewing
101 changes: 101 additions & 0 deletions
101
...search/xpack/esql/expression/predicate/operator/arithmetic/SubUnsignedLongsEvaluator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 + "]"; | ||
} | ||
} |