Skip to content

Commit fd248f7

Browse files
Make sure verify is being called when we call LocalPhysicalPlanOptimizer.localOptimize()
1 parent 3fdc7cd commit fd248f7

File tree

4 files changed

+15
-16
lines changed

4 files changed

+15
-16
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public Failures verify(LogicalPlan plan, boolean skipRemoteEnrichVerification) {
2424
Failures failures = new Failures();
2525
Failures dependencyFailures = new Failures();
2626

27-
if(skipRemoteEnrichVerification) {
27+
if (skipRemoteEnrichVerification) {
2828
// AwaitsFix https://github.com/elastic/elasticsearch/issues/118531
2929
var enriches = plan.collectFirstChildren(Enrich.class::isInstance);
3030
if (enriches.isEmpty() == false && ((Enrich) enriches.get(0)).mode() == Enrich.Mode.REMOTE) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public Failures verify(PhysicalPlan plan, boolean skipRemoteEnrichVerification)
3131
Failures failures = new Failures();
3232
Failures depFailures = new Failures();
3333

34-
if (skipRemoteEnrichVerification){
34+
if (skipRemoteEnrichVerification) {
3535
// AwaitsFix https://github.com/elastic/elasticsearch/issues/118531
3636
var enriches = plan.collectFirstChildren(EnrichExec.class::isInstance);
3737
if (enriches.isEmpty() == false && ((EnrichExec) enriches.get(0)).mode() == Enrich.Mode.REMOTE) {

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/optimizer/LocalPhysicalPlanOptimizerTests.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import org.elasticsearch.xpack.esql.core.expression.Expression;
4444
import org.elasticsearch.xpack.esql.core.expression.Expressions;
4545
import org.elasticsearch.xpack.esql.core.expression.FieldAttribute;
46+
import org.elasticsearch.xpack.esql.core.expression.FoldContext;
4647
import org.elasticsearch.xpack.esql.core.expression.Literal;
4748
import org.elasticsearch.xpack.esql.core.expression.NamedExpression;
4849
import org.elasticsearch.xpack.esql.core.expression.ReferenceAttribute;
@@ -2062,7 +2063,7 @@ public void testToDateNanosPushDown() {
20622063
assertThat(expected.toString(), is(esQuery.query().toString()));
20632064
}
20642065

2065-
public void testVerifierOnMissingReferencesWithBinaryPlans() throws Exception {
2066+
public void testVerifierOnMissingReferences() throws Exception {
20662067

20672068
PhysicalPlan plan = plannerOptimizer.plan("""
20682069
from test
@@ -2079,7 +2080,17 @@ public void testVerifierOnMissingReferencesWithBinaryPlans() throws Exception {
20792080
List<Order> orders = List.of(new Order(plan.source(), missingAttr, Order.OrderDirection.ASC, Order.NullsPosition.FIRST));
20802081
TopNExec topNExec = new TopNExec(plan.source(), plan, orders, new Literal(Source.EMPTY, limit, INTEGER), randomEstimatedRowSize());
20812082

2082-
Exception e = expectThrows(IllegalStateException.class, () -> plannerOptimizer.localPhysicalVerify(topNExec));
2083+
// We want to verify that the localOptimize detects the missing attribute.
2084+
// However, it also throws an error in one of the rules before we get to the verifier.
2085+
// So we use an implementation of LocalPhysicalPlanOptimizer that does not have any rules.
2086+
LocalPhysicalOptimizerContext context = new LocalPhysicalOptimizerContext(config, FoldContext.small(), SearchStats.EMPTY);
2087+
LocalPhysicalPlanOptimizer optimizerWithNoopExecute = new LocalPhysicalPlanOptimizer(context) {
2088+
@Override
2089+
protected List<Batch<PhysicalPlan>> batches() {
2090+
return List.of();
2091+
}
2092+
};
2093+
Exception e = expectThrows(IllegalStateException.class, () -> optimizerWithNoopExecute.localOptimize(topNExec));
20832094
assertThat(e.getMessage(), containsString(" optimized incorrectly due to missing references [missing attr"));
20842095
}
20852096

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/optimizer/TestPlannerOptimizer.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ public class TestPlannerOptimizer {
2323
private final Analyzer analyzer;
2424
private final LogicalPlanOptimizer logicalOptimizer;
2525
private final PhysicalPlanOptimizer physicalPlanOptimizer;
26-
private final LocalPhysicalPlanOptimizer localPhysicalPlanOptimizer;
2726

2827
private final Mapper mapper;
2928
private final Configuration config;
@@ -40,9 +39,6 @@ public TestPlannerOptimizer(Configuration config, Analyzer analyzer, LogicalPlan
4039
parser = new EsqlParser();
4140
physicalPlanOptimizer = new PhysicalPlanOptimizer(new PhysicalOptimizerContext(config));
4241
mapper = new Mapper();
43-
localPhysicalPlanOptimizer = new LocalPhysicalPlanOptimizer(
44-
new LocalPhysicalOptimizerContext(config, FoldContext.small(), SearchStats.EMPTY)
45-
);
4642

4743
}
4844

@@ -89,12 +85,4 @@ private PhysicalPlan physicalPlan(String query, Analyzer analyzer) {
8985
var physical = mapper.map(logical);
9086
return physical;
9187
}
92-
93-
public PhysicalPlan localPhysicalOptimize(PhysicalPlan plan) {
94-
return localPhysicalPlanOptimizer.localOptimize(plan);
95-
}
96-
97-
public PhysicalPlan localPhysicalVerify(PhysicalPlan plan) {
98-
return localPhysicalPlanOptimizer.verify(plan);
99-
}
10088
}

0 commit comments

Comments
 (0)