Skip to content

Commit

Permalink
remove ComparisonMapper (elastic#107896)
Browse files Browse the repository at this point in the history
More follow-up work from elastic#105217. Since the binary comparison operators now implement EvaluatorMapper, there is no need for ComparisonMapper going forward.
  • Loading branch information
not-napoleon authored Apr 29, 2024
1 parent ee26295 commit 0a9ab8e
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 192 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import org.elasticsearch.core.Releasables;
import org.elasticsearch.xpack.esql.evaluator.mapper.EvaluatorMapper;
import org.elasticsearch.xpack.esql.evaluator.mapper.ExpressionMapper;
import org.elasticsearch.xpack.esql.evaluator.predicate.operator.comparison.ComparisonMapper;
import org.elasticsearch.xpack.esql.evaluator.predicate.operator.comparison.InMapper;
import org.elasticsearch.xpack.esql.evaluator.predicate.operator.comparison.InsensitiveEqualsMapper;
import org.elasticsearch.xpack.esql.planner.Layout;
Expand All @@ -40,12 +39,6 @@
public final class EvalMapper {

private static final List<ExpressionMapper<?>> MAPPERS = List.of(
ComparisonMapper.EQUALS,
ComparisonMapper.NOT_EQUALS,
ComparisonMapper.GREATER_THAN,
ComparisonMapper.GREATER_THAN_OR_EQUAL,
ComparisonMapper.LESS_THAN,
ComparisonMapper.LESS_THAN_OR_EQUAL,
InMapper.IN_MAPPER,
new InsensitiveEqualsMapper(),
new BooleanLogic(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.elasticsearch.compute.data.Page;
import org.elasticsearch.compute.operator.DriverContext;
import org.elasticsearch.compute.operator.EvalOperator.ExpressionEvaluator;
import org.elasticsearch.xpack.esql.planner.Layout;
import org.elasticsearch.xpack.ql.expression.Expression;

import java.util.function.Function;
Expand All @@ -27,6 +28,22 @@
*/
public interface EvaluatorMapper {
/**
* <p>
* Note for implementors:
* If you are implementing this function, you should call the passed-in
* lambda on your children, after doing any other manipulation (casting,
* etc.) necessary.
* </p>
* <p>
* Note for Callers:
* If you are attempting to call this method, and you have an
* {@link Expression} and a {@link org.elasticsearch.xpack.esql.planner.Layout},
* you likely want to call {@link org.elasticsearch.xpack.esql.evaluator.EvalMapper#toEvaluator(Expression, Layout)}
* instead. On the other hand, if you already have something that
* looks like the parameter for this method, you should call this method
* with that function.
* </p>
* <p>
* Build an {@link ExpressionEvaluator.Factory} for the tree of
* expressions rooted at this node. This is only guaranteed to return
* a sensible evaluator if this node has a valid type. If this node
Expand All @@ -35,6 +52,7 @@ public interface EvaluatorMapper {
* If {@linkplain Expression#typeResolved} returns an error then
* this method may throw. Or return an evaluator that produces
* garbage. Or return an evaluator that throws when run.
* </p>
*/
ExpressionEvaluator.Factory toEvaluator(Function<Expression, ExpressionEvaluator.Factory> toEvaluator);

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.elasticsearch.compute.operator.EvalOperator;
import org.elasticsearch.compute.operator.EvalOperator.ExpressionEvaluator;
import org.elasticsearch.core.Releasables;
import org.elasticsearch.xpack.esql.evaluator.EvalMapper;
import org.elasticsearch.xpack.esql.evaluator.mapper.ExpressionMapper;
import org.elasticsearch.xpack.esql.expression.predicate.operator.comparison.In;
import org.elasticsearch.xpack.esql.planner.Layout;
Expand All @@ -24,8 +25,6 @@
import java.util.BitSet;
import java.util.List;

import static org.elasticsearch.xpack.esql.evaluator.predicate.operator.comparison.ComparisonMapper.EQUALS;

public class InMapper extends ExpressionMapper<In> {

public static final InMapper IN_MAPPER = new InMapper();
Expand All @@ -38,7 +37,7 @@ public ExpressionEvaluator.Factory map(In in, Layout layout) {
List<ExpressionEvaluator.Factory> listEvaluators = new ArrayList<>(in.list().size());
in.list().forEach(e -> {
Equals eq = new Equals(in.source(), in.value(), e);
ExpressionEvaluator.Factory eqEvaluator = ((ExpressionMapper) EQUALS).map(eq, layout);
ExpressionEvaluator.Factory eqEvaluator = EvalMapper.toEvaluator(eq, layout);
listEvaluators.add(eqEvaluator);
});
return dvrCtx -> new InExpressionEvaluator(dvrCtx, listEvaluators.stream().map(fac -> fac.get(dvrCtx)).toList());
Expand Down

0 comments on commit 0a9ab8e

Please sign in to comment.