Skip to content

Commit 68c9309

Browse files
authored
ESQL: Rename Validatable iface to PostLogicalOptimizationVerificationAware (#119985) (#120051)
Rename interface to align it with the similar post-analysis interfaces. Related #119798.
1 parent c17de01 commit 68c9309

File tree

10 files changed

+62
-45
lines changed

10 files changed

+62
-45
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
package org.elasticsearch.xpack.esql.capabilities;
9+
10+
import org.elasticsearch.xpack.esql.common.Failures;
11+
import org.elasticsearch.xpack.esql.expression.function.grouping.Bucket;
12+
13+
/**
14+
* Interface implemented by expressions that require validation post logical optimization,
15+
* when the plan and references have been not just resolved but also replaced.
16+
*/
17+
public interface PostOptimizationVerificationAware {
18+
19+
/**
20+
* Validates the implementing expression - discovered failures are reported to the given
21+
* {@link Failures} class.
22+
*
23+
* <p>
24+
* Example: the {@link Bucket} function, which produces buckets over a numerical or date field, based on a number of literal
25+
* arguments needs to check if its arguments are all indeed literals. This is how this verification is performed:
26+
* <pre>
27+
* {@code
28+
*
29+
* @Override
30+
* public void postLogicalOptimizationVerification(Failures failures) {
31+
* String operation = sourceText();
32+
*
33+
* failures.add(isFoldable(buckets, operation, SECOND))
34+
* .add(from != null ? isFoldable(from, operation, THIRD) : null)
35+
* .add(to != null ? isFoldable(to, operation, FOURTH) : null);
36+
* }
37+
* }
38+
* </pre>
39+
*
40+
*/
41+
void postLogicalOptimizationVerification(Failures failures);
42+
}

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/capabilities/Validatable.java

Lines changed: 0 additions & 23 deletions
This file was deleted.

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/aggregate/WeightedAvg.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
1212
import org.elasticsearch.common.io.stream.StreamInput;
1313
import org.elasticsearch.common.io.stream.StreamOutput;
14-
import org.elasticsearch.xpack.esql.capabilities.Validatable;
1514
import org.elasticsearch.xpack.esql.core.expression.Expression;
1615
import org.elasticsearch.xpack.esql.core.expression.Literal;
1716
import org.elasticsearch.xpack.esql.core.tree.NodeInfo;
@@ -34,7 +33,7 @@
3433
import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.ParamOrdinal.SECOND;
3534
import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.isType;
3635

37-
public class WeightedAvg extends AggregateFunction implements SurrogateExpression, Validatable {
36+
public class WeightedAvg extends AggregateFunction implements SurrogateExpression {
3837
public static final NamedWriteableRegistry.Entry ENTRY = new NamedWriteableRegistry.Entry(
3938
Expression.class,
4039
"WeightedAvg",

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import org.elasticsearch.common.io.stream.StreamInput;
1414
import org.elasticsearch.common.io.stream.StreamOutput;
1515
import org.elasticsearch.index.query.QueryBuilder;
16-
import org.elasticsearch.xpack.esql.capabilities.Validatable;
16+
import org.elasticsearch.xpack.esql.capabilities.PostOptimizationVerificationAware;
1717
import org.elasticsearch.xpack.esql.common.Failure;
1818
import org.elasticsearch.xpack.esql.common.Failures;
1919
import org.elasticsearch.xpack.esql.core.expression.Expression;
@@ -60,7 +60,7 @@
6060
/**
6161
* Full text function that performs a {@link QueryStringQuery} .
6262
*/
63-
public class Match extends FullTextFunction implements Validatable {
63+
public class Match extends FullTextFunction implements PostOptimizationVerificationAware {
6464

6565
public static final NamedWriteableRegistry.Entry ENTRY = new NamedWriteableRegistry.Entry(Expression.class, "Match", Match::readFrom);
6666

@@ -194,7 +194,7 @@ protected TypeResolution checkParamCompatibility() {
194194
}
195195

196196
@Override
197-
public void validate(Failures failures) {
197+
public void postLogicalOptimizationVerification(Failures failures) {
198198
Expression fieldExpression = field();
199199
// Field may be converted to other data type (field_name :: data_type), so we need to check the original field
200200
if (fieldExpression instanceof AbstractConvertFunction convertFunction) {

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import org.elasticsearch.common.io.stream.StreamInput;
1313
import org.elasticsearch.common.io.stream.StreamOutput;
1414
import org.elasticsearch.index.query.QueryBuilder;
15-
import org.elasticsearch.xpack.esql.capabilities.Validatable;
15+
import org.elasticsearch.xpack.esql.capabilities.PostOptimizationVerificationAware;
1616
import org.elasticsearch.xpack.esql.common.Failure;
1717
import org.elasticsearch.xpack.esql.common.Failures;
1818
import org.elasticsearch.xpack.esql.core.expression.Expression;
@@ -39,7 +39,7 @@
3939
/**
4040
* Full text function that performs a {@link TermQuery} .
4141
*/
42-
public class Term extends FullTextFunction implements Validatable {
42+
public class Term extends FullTextFunction implements PostOptimizationVerificationAware {
4343

4444
public static final NamedWriteableRegistry.Entry ENTRY = new NamedWriteableRegistry.Entry(Expression.class, "Term", Term::readFrom);
4545

@@ -100,7 +100,7 @@ protected TypeResolution resolveNonQueryParamTypes() {
100100
}
101101

102102
@Override
103-
public void validate(Failures failures) {
103+
public void postLogicalOptimizationVerification(Failures failures) {
104104
if (field instanceof FieldAttribute == false) {
105105
failures.add(
106106
Failure.fail(

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/grouping/Bucket.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import org.elasticsearch.compute.operator.EvalOperator.ExpressionEvaluator;
1616
import org.elasticsearch.core.TimeValue;
1717
import org.elasticsearch.xpack.esql.EsqlIllegalArgumentException;
18-
import org.elasticsearch.xpack.esql.capabilities.Validatable;
18+
import org.elasticsearch.xpack.esql.capabilities.PostOptimizationVerificationAware;
1919
import org.elasticsearch.xpack.esql.common.Failures;
2020
import org.elasticsearch.xpack.esql.core.expression.Expression;
2121
import org.elasticsearch.xpack.esql.core.expression.Foldables;
@@ -56,7 +56,7 @@
5656
* from a number of desired buckets (as a hint) and a range (auto mode).
5757
* In the former case, two parameters will be provided, in the latter four.
5858
*/
59-
public class Bucket extends GroupingFunction implements Validatable, TwoOptionalArguments {
59+
public class Bucket extends GroupingFunction implements PostOptimizationVerificationAware, TwoOptionalArguments {
6060
public static final NamedWriteableRegistry.Entry ENTRY = new NamedWriteableRegistry.Entry(Expression.class, "Bucket", Bucket::new);
6161

6262
// TODO maybe we should just cover the whole of representable dates here - like ten years, 100 years, 1000 years, all the way up.
@@ -408,7 +408,7 @@ private static TypeResolution isStringOrDate(Expression e, String operationName,
408408
}
409409

410410
@Override
411-
public void validate(Failures failures) {
411+
public void postLogicalOptimizationVerification(Failures failures) {
412412
String operation = sourceText();
413413

414414
failures.add(isFoldable(buckets, operation, SECOND))

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/grouping/Categorize.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import org.elasticsearch.common.io.stream.StreamInput;
1212
import org.elasticsearch.common.io.stream.StreamOutput;
1313
import org.elasticsearch.compute.operator.EvalOperator.ExpressionEvaluator;
14-
import org.elasticsearch.xpack.esql.capabilities.Validatable;
1514
import org.elasticsearch.xpack.esql.core.expression.Expression;
1615
import org.elasticsearch.xpack.esql.core.expression.Nullability;
1716
import org.elasticsearch.xpack.esql.core.tree.NodeInfo;
@@ -37,7 +36,7 @@
3736
* For the implementation, see {@link org.elasticsearch.compute.aggregation.blockhash.CategorizeBlockHash}
3837
* </p>
3938
*/
40-
public class Categorize extends GroupingFunction implements Validatable {
39+
public class Categorize extends GroupingFunction {
4140
public static final NamedWriteableRegistry.Entry ENTRY = new NamedWriteableRegistry.Entry(
4241
Expression.class,
4342
"Categorize",

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/convert/FoldablesConvertFunction.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
package org.elasticsearch.xpack.esql.expression.function.scalar.convert;
99

1010
import org.elasticsearch.common.io.stream.StreamOutput;
11-
import org.elasticsearch.xpack.esql.capabilities.Validatable;
11+
import org.elasticsearch.xpack.esql.capabilities.PostOptimizationVerificationAware;
1212
import org.elasticsearch.xpack.esql.common.Failures;
1313
import org.elasticsearch.xpack.esql.core.expression.Expression;
1414
import org.elasticsearch.xpack.esql.core.tree.Source;
@@ -26,7 +26,7 @@
2626
* Base class for functions that converts a constant into an interval type - DATE_PERIOD or TIME_DURATION.
2727
* The functions will be folded at the end of LogicalPlanOptimizer by the coordinator, it does not reach data node.
2828
*/
29-
public abstract class FoldablesConvertFunction extends AbstractConvertFunction implements Validatable {
29+
public abstract class FoldablesConvertFunction extends AbstractConvertFunction implements PostOptimizationVerificationAware {
3030

3131
protected FoldablesConvertFunction(Source source, Expression field) {
3232
super(source, field);
@@ -70,7 +70,7 @@ public final Object fold() {
7070
}
7171

7272
@Override
73-
public final void validate(Failures failures) {
73+
public final void postLogicalOptimizationVerification(Failures failures) {
7474
failures.add(isFoldable(field(), sourceText(), null));
7575
}
7676
}

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/multivalue/MvSort.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
import org.elasticsearch.compute.operator.mvdedupe.MultivalueDedupeDouble;
3030
import org.elasticsearch.compute.operator.mvdedupe.MultivalueDedupeInt;
3131
import org.elasticsearch.compute.operator.mvdedupe.MultivalueDedupeLong;
32-
import org.elasticsearch.xpack.esql.capabilities.Validatable;
32+
import org.elasticsearch.xpack.esql.capabilities.PostOptimizationVerificationAware;
3333
import org.elasticsearch.xpack.esql.common.Failure;
3434
import org.elasticsearch.xpack.esql.common.Failures;
3535
import org.elasticsearch.xpack.esql.core.expression.Expression;
@@ -58,7 +58,7 @@
5858
/**
5959
* Sorts a multivalued field in lexicographical order.
6060
*/
61-
public class MvSort extends EsqlScalarFunction implements OptionalArgument, Validatable {
61+
public class MvSort extends EsqlScalarFunction implements OptionalArgument, PostOptimizationVerificationAware {
6262
public static final NamedWriteableRegistry.Entry ENTRY = new NamedWriteableRegistry.Entry(Expression.class, "MvSort", MvSort::new);
6363

6464
private final Expression field, order;
@@ -230,7 +230,7 @@ public DataType dataType() {
230230
}
231231

232232
@Override
233-
public void validate(Failures failures) {
233+
public void postLogicalOptimizationVerification(Failures failures) {
234234
if (order == null) {
235235
return;
236236
}

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/optimizer/LogicalVerifier.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
package org.elasticsearch.xpack.esql.optimizer;
99

10-
import org.elasticsearch.xpack.esql.capabilities.Validatable;
10+
import org.elasticsearch.xpack.esql.capabilities.PostOptimizationVerificationAware;
1111
import org.elasticsearch.xpack.esql.common.Failures;
1212
import org.elasticsearch.xpack.esql.optimizer.rules.PlanConsistencyChecker;
1313
import org.elasticsearch.xpack.esql.plan.logical.LogicalPlan;
@@ -28,8 +28,8 @@ public Failures verify(LogicalPlan plan) {
2828

2929
if (failures.hasFailures() == false) {
3030
p.forEachExpression(ex -> {
31-
if (ex instanceof Validatable v) {
32-
v.validate(failures);
31+
if (ex instanceof PostOptimizationVerificationAware va) {
32+
va.postLogicalOptimizationVerification(failures);
3333
}
3434
});
3535
}

0 commit comments

Comments
 (0)