Skip to content

Commit e1ca189

Browse files
committed
Include shard contexts in ToEvaluator, so no need to differentiate interfaces
1 parent e2e996d commit e1ca189

File tree

4 files changed

+31
-17
lines changed

4 files changed

+31
-17
lines changed

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/evaluator/EvalMapper.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
import org.elasticsearch.xpack.esql.core.expression.predicate.nulls.IsNull;
3232
import org.elasticsearch.xpack.esql.evaluator.mapper.EvaluatorMapper;
3333
import org.elasticsearch.xpack.esql.evaluator.mapper.ExpressionMapper;
34-
import org.elasticsearch.xpack.esql.expression.function.fulltext.Match;
3534
import org.elasticsearch.xpack.esql.expression.predicate.operator.comparison.InsensitiveEqualsMapper;
3635
import org.elasticsearch.xpack.esql.planner.EsPhysicalOperationProviders.ShardContext;
3736
import org.elasticsearch.xpack.esql.planner.Layout;
@@ -63,9 +62,7 @@ public static ExpressionEvaluator.Factory toEvaluator(
6362
Layout layout,
6463
List<ShardContext> shardContexts
6564
) {
66-
if (exp instanceof Match m) {
67-
return m.toEvaluator(shardContexts);
68-
} else if (exp instanceof EvaluatorMapper m) {
65+
if (exp instanceof EvaluatorMapper m) {
6966
return m.toEvaluator(new EvaluatorMapper.ToEvaluator() {
7067
@Override
7168
public ExpressionEvaluator.Factory apply(Expression expression) {
@@ -76,6 +73,11 @@ public ExpressionEvaluator.Factory apply(Expression expression) {
7673
public FoldContext foldCtx() {
7774
return foldCtx;
7875
}
76+
77+
@Override
78+
public List<ShardContext> shardContexts() {
79+
return shardContexts;
80+
}
7981
});
8082
}
8183
for (ExpressionMapper em : MAPPERS) {

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/evaluator/mapper/EvaluatorMapper.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,11 @@
2121
import org.elasticsearch.xpack.esql.core.expression.FoldContext;
2222
import org.elasticsearch.xpack.esql.core.tree.Source;
2323
import org.elasticsearch.xpack.esql.evaluator.EvalMapper;
24+
import org.elasticsearch.xpack.esql.planner.EsPhysicalOperationProviders;
2425
import org.elasticsearch.xpack.esql.planner.Layout;
2526

27+
import java.util.List;
28+
2629
import static org.elasticsearch.compute.data.BlockUtils.fromArrayRow;
2730
import static org.elasticsearch.compute.data.BlockUtils.toJavaObject;
2831

@@ -34,6 +37,10 @@ interface ToEvaluator {
3437
ExpressionEvaluator.Factory apply(Expression expression);
3538

3639
FoldContext foldCtx();
40+
41+
default List<EsPhysicalOperationProviders.ShardContext> shardContexts() {
42+
throw new UnsupportedOperationException("Shard contexts should only be needed for evaluation operations");
43+
}
3744
}
3845

3946
/**

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/fulltext/FullTextFunction.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
package org.elasticsearch.xpack.esql.expression.function.fulltext;
99

1010
import org.apache.lucene.util.BytesRef;
11+
import org.elasticsearch.compute.lucene.LuceneQueryExpressionEvaluator;
12+
import org.elasticsearch.compute.lucene.LuceneQueryExpressionEvaluator.ShardConfig;
13+
import org.elasticsearch.compute.operator.EvalOperator;
1114
import org.elasticsearch.index.query.QueryBuilder;
1215
import org.elasticsearch.xpack.esql.capabilities.PostAnalysisPlanVerificationAware;
1316
import org.elasticsearch.xpack.esql.common.Failures;
@@ -27,12 +30,14 @@
2730
import org.elasticsearch.xpack.esql.core.tree.Source;
2831
import org.elasticsearch.xpack.esql.core.type.DataType;
2932
import org.elasticsearch.xpack.esql.core.util.Holder;
33+
import org.elasticsearch.xpack.esql.evaluator.mapper.EvaluatorMapper;
3034
import org.elasticsearch.xpack.esql.plan.logical.Aggregate;
3135
import org.elasticsearch.xpack.esql.plan.logical.EsRelation;
3236
import org.elasticsearch.xpack.esql.plan.logical.Filter;
3337
import org.elasticsearch.xpack.esql.plan.logical.Limit;
3438
import org.elasticsearch.xpack.esql.plan.logical.LogicalPlan;
3539
import org.elasticsearch.xpack.esql.plan.logical.OrderBy;
40+
import org.elasticsearch.xpack.esql.planner.EsPhysicalOperationProviders;
3641

3742
import java.util.List;
3843
import java.util.Locale;
@@ -50,7 +55,7 @@
5055
* These functions needs to be pushed down to Lucene queries to be executed - there's no Evaluator for them, but depend on
5156
* {@link org.elasticsearch.xpack.esql.optimizer.LocalPhysicalPlanOptimizer} to rewrite them into Lucene queries.
5257
*/
53-
public abstract class FullTextFunction extends Function implements TranslationAware, PostAnalysisPlanVerificationAware {
58+
public abstract class FullTextFunction extends Function implements TranslationAware, PostAnalysisPlanVerificationAware, EvaluatorMapper {
5459

5560
private final Expression query;
5661
private final QueryBuilder queryBuilder;
@@ -381,4 +386,16 @@ private static FullTextFunction forEachFullTextFunctionParent(Expression conditi
381386
}
382387
return null;
383388
}
389+
390+
391+
@Override
392+
public EvalOperator.ExpressionEvaluator.Factory toEvaluator(ToEvaluator toEvaluator) {
393+
List<EsPhysicalOperationProviders.ShardContext> shardContexts = toEvaluator.shardContexts();
394+
ShardConfig[] shardConfigs = new ShardConfig[shardContexts.size()];
395+
int i = 0;
396+
for (EsPhysicalOperationProviders.ShardContext shardContext : shardContexts) {
397+
shardConfigs[i++] = new ShardConfig(shardContext.toQuery(queryBuilder()), shardContext.searcher());
398+
}
399+
return new LuceneQueryExpressionEvaluator.Factory(shardConfigs);
400+
}
384401
}

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/fulltext/Match.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
1313
import org.elasticsearch.common.io.stream.StreamInput;
1414
import org.elasticsearch.common.io.stream.StreamOutput;
15-
import org.elasticsearch.compute.lucene.LuceneQueryExpressionEvaluator;
16-
import org.elasticsearch.compute.lucene.LuceneQueryExpressionEvaluator.ShardConfig;
1715
import org.elasticsearch.index.query.QueryBuilder;
1816
import org.elasticsearch.xpack.esql.capabilities.PostOptimizationVerificationAware;
1917
import org.elasticsearch.xpack.esql.common.Failure;
@@ -33,7 +31,6 @@
3331
import org.elasticsearch.xpack.esql.expression.function.Param;
3432
import org.elasticsearch.xpack.esql.expression.function.scalar.convert.AbstractConvertFunction;
3533
import org.elasticsearch.xpack.esql.io.stream.PlanStreamInput;
36-
import org.elasticsearch.xpack.esql.planner.EsPhysicalOperationProviders.ShardContext;
3734
import org.elasticsearch.xpack.esql.planner.EsqlExpressionTranslators;
3835
import org.elasticsearch.xpack.esql.type.EsqlDataTypeConverter;
3936

@@ -295,13 +292,4 @@ private boolean isOperator() {
295292
}
296293
return isOperator;
297294
}
298-
299-
public LuceneQueryExpressionEvaluator.Factory toEvaluator(List<ShardContext> shardContexts) {
300-
ShardConfig[] shardConfigs = new ShardConfig[shardContexts.size()];
301-
int i = 0;
302-
for (ShardContext shardContext : shardContexts) {
303-
shardConfigs[i++] = new ShardConfig(shardContext.toQuery(queryBuilder()), shardContext.searcher());
304-
}
305-
return new LuceneQueryExpressionEvaluator.Factory(shardConfigs);
306-
}
307295
}

0 commit comments

Comments
 (0)