Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.elasticsearch.xpack.esql.core.expression.Expressions;
import org.elasticsearch.xpack.esql.optimizer.rules.PlanConsistencyChecker;
import org.elasticsearch.xpack.esql.plan.logical.Enrich;
import org.elasticsearch.xpack.esql.plan.logical.ExecutesOn;
import org.elasticsearch.xpack.esql.plan.physical.EnrichExec;
import org.elasticsearch.xpack.esql.plan.physical.FieldExtractExec;
import org.elasticsearch.xpack.esql.plan.physical.PhysicalPlan;
Expand Down Expand Up @@ -54,6 +55,11 @@ void checkPlanConsistency(PhysicalPlan optimizedPlan, Failures failures, Failure
);
}
}

if (p instanceof ExecutesOn ex && ex.executesOn() == ExecutesOn.ExecuteLocation.REMOTE) {
failures.add(fail(p, "Physical plan contains remote executing operation [{}] in local part", p.nodeName()));
}

PlanConsistencyChecker.checkPlan(p, depFailures);

if (failures.hasFailures() == false) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.elasticsearch.xpack.esql.index.EsIndex;
import org.elasticsearch.xpack.esql.io.stream.PlanStreamInput;
import org.elasticsearch.xpack.esql.plan.logical.Enrich;
import org.elasticsearch.xpack.esql.plan.logical.ExecutesOn;

import java.io.IOException;
import java.util.List;
Expand All @@ -30,7 +31,7 @@

import static org.elasticsearch.xpack.esql.expression.NamedExpressions.mergeOutputAttributes;

public class EnrichExec extends UnaryExec implements EstimatesRowSize {
public class EnrichExec extends UnaryExec implements EstimatesRowSize, ExecutesOn {
public static final NamedWriteableRegistry.Entry ENTRY = new NamedWriteableRegistry.Entry(
PhysicalPlan.class,
"EnrichExec",
Expand Down Expand Up @@ -220,4 +221,14 @@ public boolean equals(Object o) {
public int hashCode() {
return Objects.hash(super.hashCode(), mode, matchType, matchField, policyName, policyMatchField, concreteIndices, enrichFields);
}

@Override
public ExecuteLocation executesOn() {
if (mode == Enrich.Mode.REMOTE) {
return ExecuteLocation.REMOTE;
} else if (mode == Enrich.Mode.COORDINATOR) {
return ExecuteLocation.COORDINATOR;
}
return ExecuteLocation.ANY;
}
}