Skip to content

Commit

Permalink
ESQL: Constant branch
Browse files Browse the repository at this point in the history
  • Loading branch information
nik9000 committed Sep 24, 2024
1 parent e6c0863 commit 85c757e
Showing 1 changed file with 19 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -500,24 +500,31 @@ private record CaseEagerEvaluator(
) implements EvalOperator.ExpressionEvaluator {
@Override
public Block eval(Page page) {
try (
BooleanBlock lhsOrRhsBlock = (BooleanBlock) condition.condition.eval(page);
ToMask lhsOrRhs = lhsOrRhsBlock.toMask();
Block lhs = condition.value.eval(page);
Block rhs = elseVal.eval(page);
Block.Builder builder = resultType.newBlockBuilder(lhs.getTotalValueCount(), blockFactory)
) {
try (BooleanBlock lhsOrRhsBlock = (BooleanBlock) condition.condition.eval(page); ToMask lhsOrRhs = lhsOrRhsBlock.toMask()) {
if (lhsOrRhs.hadMultivaluedFields()) {
condition.registerMultivalue();
}
for (int p = 0; p < lhs.getPositionCount(); p++) {
if (lhsOrRhs.mask().getBoolean(p)) {
builder.copyFrom(lhs, p, p + 1);
if (lhsOrRhs.mask().isConstant()) {
if (lhsOrRhs.mask().getBoolean(0)) {
return condition.value.eval(page);
} else {
builder.copyFrom(rhs, p, p + 1);
return elseVal.eval(page);
}
}
return builder.build();
try (
Block lhs = condition.value.eval(page);
Block rhs = elseVal.eval(page);
Block.Builder builder = resultType.newBlockBuilder(lhs.getTotalValueCount(), blockFactory)
) {
for (int p = 0; p < lhs.getPositionCount(); p++) {
if (lhsOrRhs.mask().getBoolean(p)) {
builder.copyFrom(lhs, p, p + 1);
} else {
builder.copyFrom(rhs, p, p + 1);
}
}
return builder.build();
}
}
}

Expand Down

0 comments on commit 85c757e

Please sign in to comment.