Skip to content

Commit c063010

Browse files
Address code review comments
1 parent 7761e3f commit c063010

File tree

30 files changed

+128
-118
lines changed

30 files changed

+128
-118
lines changed

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/enrich/EnrichPolicyResolver.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
import java.util.Set;
6060
import java.util.stream.Collectors;
6161

62-
import static org.elasticsearch.xpack.esql.expression.function.Foldables.stringLiteralValueOf;
62+
import static org.elasticsearch.xpack.esql.expression.Foldables.stringLiteralValueOf;
6363
import static org.elasticsearch.xpack.esql.session.EsqlCCSUtils.markClusterWithFinalStateAndNoShards;
6464

6565
/**
Lines changed: 46 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* 2.0; you may not use this file except in compliance with the Elastic License
55
* 2.0.
66
*/
7-
package org.elasticsearch.xpack.esql.expression.function;
7+
package org.elasticsearch.xpack.esql.expression;
88

99
import org.apache.lucene.util.BytesRef;
1010
import org.elasticsearch.common.lucene.BytesRefs;
@@ -22,6 +22,51 @@
2222
import static org.elasticsearch.xpack.esql.common.Failure.fail;
2323

2424
public abstract class Foldables {
25+
/**
26+
* A utility class to validate the type resolution of expressions before and after logical planning.
27+
* If null is passed for Failures to the constructor, it means we are only type resolution.
28+
* This is usually called when doing pre-logical planning validation.
29+
* If a {@link Failures} instance is passed, it means we are doing post-logical planning validation as well.
30+
* This is usually called after folding is done, during
31+
* {@link org.elasticsearch.xpack.esql.capabilities.PostOptimizationVerificationAware} verification
32+
*/
33+
public static class TypeResolutionValidator {
34+
35+
Expression.TypeResolution typeResolution = Expression.TypeResolution.TYPE_RESOLVED;
36+
@Nullable
37+
private final Failures postValidationFailures; // null means we are doing pre-folding validation only
38+
private final Expression field;
39+
40+
public static TypeResolutionValidator forPreOptimizationValidation(Expression field) {
41+
return new TypeResolutionValidator(field, null);
42+
}
43+
44+
public static TypeResolutionValidator forPostOptimizationValidation(Expression field, Failures failures) {
45+
return new TypeResolutionValidator(field, failures);
46+
}
47+
48+
private TypeResolutionValidator(Expression field, Failures failures) {
49+
this.field = field;
50+
this.postValidationFailures = failures;
51+
}
52+
53+
public void invalidIfPostValidation(Failure failure) {
54+
if (postValidationFailures != null) {
55+
postValidationFailures.add(failure);
56+
}
57+
}
58+
59+
public void invalid(Expression.TypeResolution message) {
60+
typeResolution = message;
61+
if (postValidationFailures != null) {
62+
postValidationFailures.add(fail(field, message.message()));
63+
}
64+
}
65+
66+
public Expression.TypeResolution getResolvedType() {
67+
return typeResolution;
68+
}
69+
}
2570

2671
public static Object valueOf(FoldContext ctx, Expression e) {
2772
if (e.foldable()) {
@@ -144,50 +189,4 @@ public static int intValueOf(Expression field, String sourceText, String fieldNa
144189
Strings.format(null, "[{}] value must be a constant number in [{}], found [{}]", fieldName, sourceText, field)
145190
);
146191
}
147-
148-
/**
149-
* A utility class to validate the type resolution of expressions before and after logical planning.
150-
* If null is passed for Failures to the constructor, it means we are only type resolution.
151-
* This is usually called when doing pre-logical planning validation.
152-
* If a {@link Failures} instance is passed, it means we are doing post-logical planning validation as well.
153-
* This is usually called after folding is done, during
154-
* {@link org.elasticsearch.xpack.esql.capabilities.PostOptimizationVerificationAware} verification
155-
*/
156-
public static class TypeResolutionValidator {
157-
158-
Expression.TypeResolution typeResolution = Expression.TypeResolution.TYPE_RESOLVED;
159-
@Nullable
160-
private final Failures postValidationFailures; // null means we are doing pre-folding validation only
161-
private final Expression field;
162-
163-
public static TypeResolutionValidator forPreOptimizationValidation(Expression field) {
164-
return new TypeResolutionValidator(field, null);
165-
}
166-
167-
public static TypeResolutionValidator forPostOptimizationValidation(Expression field, Failures failures) {
168-
return new TypeResolutionValidator(field, failures);
169-
}
170-
171-
private TypeResolutionValidator(Expression field, Failures failures) {
172-
this.field = field;
173-
this.postValidationFailures = failures;
174-
}
175-
176-
public void invalidIfPostValidation(Failure failure) {
177-
if (postValidationFailures != null) {
178-
postValidationFailures.add(failure);
179-
}
180-
}
181-
182-
public void invalid(Expression.TypeResolution message) {
183-
typeResolution = message;
184-
if (postValidationFailures != null) {
185-
postValidationFailures.add(fail(field, message.message()));
186-
}
187-
}
188-
189-
public Expression.TypeResolution getResolvedType() {
190-
return typeResolution;
191-
}
192-
}
193192
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.isType;
4949
import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.isWholeNumber;
5050
import static org.elasticsearch.xpack.esql.core.util.CollectionUtils.nullSafeList;
51-
import static org.elasticsearch.xpack.esql.expression.function.Foldables.intValueOf;
51+
import static org.elasticsearch.xpack.esql.expression.Foldables.intValueOf;
5252

5353
public class CountDistinct extends AggregateFunction implements OptionalArgument, ToAggregator, SurrogateExpression {
5454
public static final NamedWriteableRegistry.Entry ENTRY = new NamedWriteableRegistry.Entry(

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.ParamOrdinal.SECOND;
3838
import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.isFoldable;
3939
import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.isType;
40-
import static org.elasticsearch.xpack.esql.expression.function.Foldables.intValueOf;
40+
import static org.elasticsearch.xpack.esql.expression.Foldables.intValueOf;
4141

4242
public class Percentile extends NumericAggregate implements SurrogateExpression {
4343
public static final NamedWriteableRegistry.Entry ENTRY = new NamedWriteableRegistry.Entry(

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
import org.elasticsearch.xpack.esql.core.tree.NodeInfo;
2525
import org.elasticsearch.xpack.esql.core.tree.Source;
2626
import org.elasticsearch.xpack.esql.core.type.DataType;
27+
import org.elasticsearch.xpack.esql.expression.Foldables;
2728
import org.elasticsearch.xpack.esql.expression.function.Example;
28-
import org.elasticsearch.xpack.esql.expression.function.Foldables;
2929
import org.elasticsearch.xpack.esql.expression.function.FunctionAppliesTo;
3030
import org.elasticsearch.xpack.esql.expression.function.FunctionAppliesToLifecycle;
3131
import org.elasticsearch.xpack.esql.expression.function.FunctionInfo;
@@ -42,9 +42,9 @@
4242
import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.isNotNull;
4343
import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.isRepresentableExceptCounters;
4444
import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.isType;
45-
import static org.elasticsearch.xpack.esql.expression.function.Foldables.TypeResolutionValidator.forPostOptimizationValidation;
46-
import static org.elasticsearch.xpack.esql.expression.function.Foldables.TypeResolutionValidator.forPreOptimizationValidation;
47-
import static org.elasticsearch.xpack.esql.expression.function.Foldables.resolveTypeLimit;
45+
import static org.elasticsearch.xpack.esql.expression.Foldables.TypeResolutionValidator.forPostOptimizationValidation;
46+
import static org.elasticsearch.xpack.esql.expression.Foldables.TypeResolutionValidator.forPreOptimizationValidation;
47+
import static org.elasticsearch.xpack.esql.expression.Foldables.resolveTypeLimit;
4848

4949
public class Sample extends AggregateFunction implements ToAggregator, PostOptimizationVerificationAware {
5050
public static final NamedWriteableRegistry.Entry ENTRY = new NamedWriteableRegistry.Entry(Expression.class, "Sample", Sample::new);

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@
2727
import org.elasticsearch.xpack.esql.core.tree.NodeInfo;
2828
import org.elasticsearch.xpack.esql.core.tree.Source;
2929
import org.elasticsearch.xpack.esql.core.type.DataType;
30+
import org.elasticsearch.xpack.esql.expression.Foldables;
31+
import org.elasticsearch.xpack.esql.expression.Foldables.TypeResolutionValidator;
3032
import org.elasticsearch.xpack.esql.expression.SurrogateExpression;
3133
import org.elasticsearch.xpack.esql.expression.function.Example;
32-
import org.elasticsearch.xpack.esql.expression.function.Foldables;
33-
import org.elasticsearch.xpack.esql.expression.function.Foldables.TypeResolutionValidator;
3434
import org.elasticsearch.xpack.esql.expression.function.FunctionInfo;
3535
import org.elasticsearch.xpack.esql.expression.function.FunctionType;
3636
import org.elasticsearch.xpack.esql.expression.function.Param;
@@ -49,8 +49,8 @@
4949
import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.isNotNull;
5050
import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.isString;
5151
import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.isType;
52-
import static org.elasticsearch.xpack.esql.expression.function.Foldables.TypeResolutionValidator.forPostOptimizationValidation;
53-
import static org.elasticsearch.xpack.esql.expression.function.Foldables.TypeResolutionValidator.forPreOptimizationValidation;
52+
import static org.elasticsearch.xpack.esql.expression.Foldables.TypeResolutionValidator.forPostOptimizationValidation;
53+
import static org.elasticsearch.xpack.esql.expression.Foldables.TypeResolutionValidator.forPreOptimizationValidation;
5454

5555
public class Top extends AggregateFunction implements ToAggregator, SurrogateExpression, PostOptimizationVerificationAware {
5656
public static final NamedWriteableRegistry.Entry ENTRY = new NamedWriteableRegistry.Entry(Expression.class, "Top", Top::new);

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@
5656
import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.ParamOrdinal.DEFAULT;
5757
import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.isNotNull;
5858
import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.isString;
59-
import static org.elasticsearch.xpack.esql.expression.function.Foldables.TypeResolutionValidator.forPostOptimizationValidation;
60-
import static org.elasticsearch.xpack.esql.expression.function.Foldables.TypeResolutionValidator.forPreOptimizationValidation;
61-
import static org.elasticsearch.xpack.esql.expression.function.Foldables.resolveTypeQuery;
59+
import static org.elasticsearch.xpack.esql.expression.Foldables.TypeResolutionValidator.forPostOptimizationValidation;
60+
import static org.elasticsearch.xpack.esql.expression.Foldables.TypeResolutionValidator.forPreOptimizationValidation;
61+
import static org.elasticsearch.xpack.esql.expression.Foldables.resolveTypeQuery;
6262

6363
/**
6464
* Base class for full-text functions that use ES queries to match documents.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
import org.elasticsearch.xpack.esql.core.querydsl.query.Query;
1717
import org.elasticsearch.xpack.esql.core.tree.NodeInfo;
1818
import org.elasticsearch.xpack.esql.core.tree.Source;
19+
import org.elasticsearch.xpack.esql.expression.Foldables;
1920
import org.elasticsearch.xpack.esql.expression.function.Example;
20-
import org.elasticsearch.xpack.esql.expression.function.Foldables;
2121
import org.elasticsearch.xpack.esql.expression.function.FunctionAppliesTo;
2222
import org.elasticsearch.xpack.esql.expression.function.FunctionAppliesToLifecycle;
2323
import org.elasticsearch.xpack.esql.expression.function.FunctionInfo;

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
@@ -26,8 +26,8 @@
2626
import org.elasticsearch.xpack.esql.core.type.DataType;
2727
import org.elasticsearch.xpack.esql.core.util.Check;
2828
import org.elasticsearch.xpack.esql.core.util.NumericUtils;
29+
import org.elasticsearch.xpack.esql.expression.Foldables;
2930
import org.elasticsearch.xpack.esql.expression.function.Example;
30-
import org.elasticsearch.xpack.esql.expression.function.Foldables;
3131
import org.elasticsearch.xpack.esql.expression.function.FunctionAppliesTo;
3232
import org.elasticsearch.xpack.esql.expression.function.FunctionAppliesToLifecycle;
3333
import org.elasticsearch.xpack.esql.expression.function.FunctionInfo;
@@ -79,8 +79,8 @@
7979
import static org.elasticsearch.xpack.esql.core.type.DataType.TEXT;
8080
import static org.elasticsearch.xpack.esql.core.type.DataType.UNSIGNED_LONG;
8181
import static org.elasticsearch.xpack.esql.core.type.DataType.VERSION;
82-
import static org.elasticsearch.xpack.esql.expression.function.Foldables.TypeResolutionValidator.forPreOptimizationValidation;
83-
import static org.elasticsearch.xpack.esql.expression.function.Foldables.resolveTypeQuery;
82+
import static org.elasticsearch.xpack.esql.expression.Foldables.TypeResolutionValidator.forPreOptimizationValidation;
83+
import static org.elasticsearch.xpack.esql.expression.Foldables.resolveTypeQuery;
8484
import static org.elasticsearch.xpack.esql.expression.predicate.operator.comparison.EsqlBinaryComparison.formatIncompatibleTypesMessage;
8585

8686
/**

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
import org.elasticsearch.xpack.esql.core.tree.Source;
2424
import org.elasticsearch.xpack.esql.core.type.DataType;
2525
import org.elasticsearch.xpack.esql.core.util.Check;
26+
import org.elasticsearch.xpack.esql.expression.Foldables;
2627
import org.elasticsearch.xpack.esql.expression.function.Example;
27-
import org.elasticsearch.xpack.esql.expression.function.Foldables;
2828
import org.elasticsearch.xpack.esql.expression.function.FunctionAppliesTo;
2929
import org.elasticsearch.xpack.esql.expression.function.FunctionAppliesToLifecycle;
3030
import org.elasticsearch.xpack.esql.expression.function.FunctionInfo;
@@ -62,8 +62,8 @@
6262
import static org.elasticsearch.xpack.esql.core.type.DataType.INTEGER;
6363
import static org.elasticsearch.xpack.esql.core.type.DataType.KEYWORD;
6464
import static org.elasticsearch.xpack.esql.core.type.DataType.TEXT;
65-
import static org.elasticsearch.xpack.esql.expression.function.Foldables.TypeResolutionValidator.forPreOptimizationValidation;
66-
import static org.elasticsearch.xpack.esql.expression.function.Foldables.resolveTypeQuery;
65+
import static org.elasticsearch.xpack.esql.expression.Foldables.TypeResolutionValidator.forPreOptimizationValidation;
66+
import static org.elasticsearch.xpack.esql.expression.Foldables.resolveTypeQuery;
6767

6868
/**
6969
* Full text function that performs a {@link org.elasticsearch.xpack.esql.querydsl.query.MatchPhraseQuery} .

0 commit comments

Comments
 (0)