Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/changelog/130409.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 130409
summary: Add Dependency Checker for `LogicalLocalPlanOptimizer`
area: ES|QL
type: enhancement
issues: []
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

package org.elasticsearch.xpack.esql.optimizer;

import org.elasticsearch.xpack.esql.VerificationException;
import org.elasticsearch.xpack.esql.common.Failures;
import org.elasticsearch.xpack.esql.optimizer.rules.logical.PropagateEmptyRelation;
import org.elasticsearch.xpack.esql.optimizer.rules.logical.ReplaceStatsFilteredAggWithEval;
import org.elasticsearch.xpack.esql.optimizer.rules.logical.ReplaceStringCasingWithInsensitiveRegexMatch;
Expand Down Expand Up @@ -35,6 +37,8 @@
*/
public class LocalLogicalPlanOptimizer extends ParameterizedRuleExecutor<LogicalPlan, LocalLogicalOptimizerContext> {

private final LogicalVerifier verifier = LogicalVerifier.INSTANCE;

private static final List<Batch<LogicalPlan>> RULES = arrayAsArrayList(
new Batch<>(
"Local rewrite",
Expand Down Expand Up @@ -81,6 +85,12 @@ private static Batch<LogicalPlan> localOperators() {
}

public LogicalPlan localOptimize(LogicalPlan plan) {
return execute(plan);
LogicalPlan optimized = execute(plan);
Failures failures = verifier.verify(optimized);
if (failures.hasFailures()) {
throw new VerificationException("Plan after optimize not valid: " + failures + " for plan: " + plan.nodeString());
}
return optimized;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.elasticsearch.xpack.esql.capabilities.PostOptimizationVerificationAware;
import org.elasticsearch.xpack.esql.common.Failures;
import org.elasticsearch.xpack.esql.optimizer.rules.PlanConsistencyChecker;
import org.elasticsearch.xpack.esql.plan.logical.Enrich;
import org.elasticsearch.xpack.esql.plan.logical.LogicalPlan;

public final class LogicalVerifier {
Expand All @@ -23,6 +24,12 @@ public Failures verify(LogicalPlan plan) {
Failures failures = new Failures();
Failures dependencyFailures = new Failures();

// AwaitsFix https://github.com/elastic/elasticsearch/issues/118531
var enriches = plan.collectFirstChildren(Enrich.class::isInstance);
if (enriches.isEmpty() == false && ((Enrich) enriches.get(0)).mode() == Enrich.Mode.REMOTE) {
return failures;
}

plan.forEachUp(p -> {
PlanConsistencyChecker.checkPlan(p, dependencyFailures);

Expand Down
Loading