Skip to content

Commit 67882f1

Browse files
committed
Share better
1 parent 66536ef commit 67882f1

File tree

3 files changed

+16
-13
lines changed

3 files changed

+16
-13
lines changed

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/analysis/Analyzer.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
import org.elasticsearch.xpack.esql.index.EsIndex;
7373
import org.elasticsearch.xpack.esql.index.IndexResolution;
7474
import org.elasticsearch.xpack.esql.inference.ResolvedInference;
75+
import org.elasticsearch.xpack.esql.optimizer.rules.logical.SubstituteSurrogateExpressions;
7576
import org.elasticsearch.xpack.esql.parser.ParsingException;
7677
import org.elasticsearch.xpack.esql.plan.IndexPattern;
7778
import org.elasticsearch.xpack.esql.plan.logical.Aggregate;
@@ -1617,6 +1618,7 @@ private LogicalPlan doRule(LogicalPlan plan) {
16171618
}
16181619

16191620
private Expression resolveConvertFunction(ConvertFunction convert, List<FieldAttribute> unionFieldAttributes) {
1621+
Expression convertExpression = (Expression) convert;
16201622
if (convert.field() instanceof FieldAttribute fa && fa.field() instanceof InvalidMappedField imf) {
16211623
HashMap<TypeResolutionKey, Expression> typeResolutions = new HashMap<>();
16221624
Set<DataType> supportedTypes = convert.supportedTypes();
@@ -1643,9 +1645,11 @@ private Expression resolveConvertFunction(ConvertFunction convert, List<FieldAtt
16431645
return createIfDoesNotAlreadyExist(fa, resolvedField, unionFieldAttributes);
16441646
}
16451647
} else if (convert.field() instanceof AbstractConvertFunction subConvert) {
1646-
return convert.replaceChildren(Collections.singletonList(resolveConvertFunction(subConvert, unionFieldAttributes)));
1648+
return convertExpression.replaceChildren(
1649+
Collections.singletonList(resolveConvertFunction(subConvert, unionFieldAttributes))
1650+
);
16471651
}
1648-
return (Expression) convert;
1652+
return convertExpression;
16491653
}
16501654

16511655
private Expression createIfDoesNotAlreadyExist(
@@ -1693,19 +1697,13 @@ private Expression typeSpecificConvert(ConvertFunction convert, Source source, D
16931697
originalFieldAttr.id(),
16941698
true
16951699
);
1696-
Expression e = convert.replaceChildren(Collections.singletonList(resolvedAttr));
1700+
Expression e = ((Expression) convert).replaceChildren(Collections.singletonList(resolvedAttr));
16971701
/*
16981702
* Resolve surrogates immediately because these type specific conversions are serialized
16991703
* and SurrogateExpressions are expected to be resolved on the coordinating node. At least,
17001704
* TO_IP is expected to be resolved there.
17011705
*/
1702-
if (e instanceof SurrogateExpression s) {
1703-
Expression surrogate = s.surrogate();
1704-
if (surrogate != null) {
1705-
return surrogate;
1706-
}
1707-
}
1708-
return e;
1706+
return SubstituteSurrogateExpressions.rule(e);
17091707
}
17101708
}
17111709

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import org.elasticsearch.xpack.esql.core.expression.Expression;
1111
import org.elasticsearch.xpack.esql.core.type.DataType;
1212

13-
import java.util.List;
1413
import java.util.Set;
1514

1615
/**
@@ -26,6 +25,4 @@ public interface ConvertFunction {
2625
* The types that {@link #field()} can have.
2726
*/
2827
Set<DataType> supportedTypes();
29-
30-
Expression replaceChildren(List<Expression> newChildren);
3128
}

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/optimizer/rules/logical/SubstituteSurrogateExpressions.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import org.elasticsearch.xpack.esql.core.expression.Expression;
1111
import org.elasticsearch.xpack.esql.expression.SurrogateExpression;
12+
import org.elasticsearch.xpack.esql.expression.function.scalar.math.Exp;
1213
import org.elasticsearch.xpack.esql.optimizer.LogicalOptimizerContext;
1314

1415
/**
@@ -22,6 +23,13 @@ public SubstituteSurrogateExpressions() {
2223

2324
@Override
2425
protected Expression rule(Expression e, LogicalOptimizerContext ctx) {
26+
return rule(e);
27+
}
28+
29+
/**
30+
* Perform the actual substitution.
31+
*/
32+
public static Expression rule(Expression e) {
2533
if (e instanceof SurrogateExpression s) {
2634
Expression surrogate = s.surrogate();
2735
if (surrogate != null) {

0 commit comments

Comments
 (0)