-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Introduce execution location marker for better handling of remote/local compatibility #132205
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 13 commits
2c051b5
170d83c
411a2ed
ae7a7ce
9e4be57
37600f0
f7f5e9b
841a22e
acb933c
0535258
e67924c
8413dbc
997b9bd
61fe122
e00abb5
6ff5827
2e2f953
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,7 +45,13 @@ | |
import static org.elasticsearch.xpack.esql.expression.NamedExpressions.mergeOutputAttributes; | ||
import static org.elasticsearch.xpack.esql.plan.logical.Filter.checkFilterConditionDataType; | ||
|
||
public class Aggregate extends UnaryPlan implements PostAnalysisVerificationAware, TelemetryAware, SortAgnostic, PipelineBreaker { | ||
public class Aggregate extends UnaryPlan | ||
implements | ||
PostAnalysisVerificationAware, | ||
TelemetryAware, | ||
SortAgnostic, | ||
PipelineBreaker, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thought: Hmm, maybe PipelineBreaker should inherit from ExecutesOn.Coordinator? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not sure yet... Need to think about it a bit more to have a good answer for this. |
||
ExecutesOn.Coordinator { | ||
public static final NamedWriteableRegistry.Entry ENTRY = new NamedWriteableRegistry.Entry( | ||
LogicalPlan.class, | ||
"Aggregate", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.esql.plan.logical; | ||
|
||
/** | ||
* Mark nodes that execute only in a specific way, either on the coordinator or on a remote node. | ||
*/ | ||
public interface ExecutesOn { | ||
enum ExecuteLocation { | ||
COORDINATOR, | ||
REMOTE, | ||
ANY; // Can be executed on either coordinator or remote nodes | ||
} | ||
|
||
ExecuteLocation executesOn(); | ||
|
||
/** | ||
* Executes on the remote nodes only (note that may include coordinator, but not on the aggregation stage). | ||
*/ | ||
interface Remote extends ExecutesOn { | ||
@Override | ||
default ExecuteLocation executesOn() { | ||
return ExecuteLocation.REMOTE; | ||
} | ||
} | ||
|
||
/** | ||
* Executes on the coordinator only. Can not be run on remote nodes. | ||
*/ | ||
interface Coordinator extends ExecutesOn { | ||
@Override | ||
default ExecuteLocation executesOn() { | ||
return ExecuteLocation.COORDINATOR; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,7 +33,12 @@ | |
* A Fork is a n-ary {@code Plan} where each child is a sub plan, e.g. | ||
* {@code FORK [WHERE content:"fox" ] [WHERE content:"dog"] } | ||
*/ | ||
public class Fork extends LogicalPlan implements PostAnalysisPlanVerificationAware, TelemetryAware, PipelineBreaker { | ||
public class Fork extends LogicalPlan | ||
implements | ||
PostAnalysisPlanVerificationAware, | ||
TelemetryAware, | ||
PipelineBreaker, | ||
|
||
ExecutesOn.Coordinator { | ||
|
||
public static final String FORK_FIELD = "_fork"; | ||
public static final int MAX_BRANCHES = 8; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ | |
import org.elasticsearch.common.io.stream.StreamInput; | ||
import org.elasticsearch.common.io.stream.StreamOutput; | ||
import org.elasticsearch.xpack.esql.capabilities.PostAnalysisVerificationAware; | ||
import org.elasticsearch.xpack.esql.capabilities.PostOptimizationVerificationAware; | ||
import org.elasticsearch.xpack.esql.common.Failures; | ||
import org.elasticsearch.xpack.esql.core.expression.Attribute; | ||
import org.elasticsearch.xpack.esql.core.expression.AttributeSet; | ||
|
@@ -21,14 +22,19 @@ | |
import org.elasticsearch.xpack.esql.core.type.DataType; | ||
import org.elasticsearch.xpack.esql.io.stream.PlanStreamInput; | ||
import org.elasticsearch.xpack.esql.plan.logical.BinaryPlan; | ||
import org.elasticsearch.xpack.esql.plan.logical.ExecutesOn; | ||
import org.elasticsearch.xpack.esql.plan.logical.Limit; | ||
import org.elasticsearch.xpack.esql.plan.logical.LogicalPlan; | ||
import org.elasticsearch.xpack.esql.plan.logical.PipelineBreaker; | ||
import org.elasticsearch.xpack.esql.plan.logical.SortAgnostic; | ||
|
||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.Set; | ||
|
||
import static org.elasticsearch.xpack.esql.common.Failure.fail; | ||
import static org.elasticsearch.xpack.esql.core.type.DataType.AGGREGATE_METRIC_DOUBLE; | ||
|
@@ -56,7 +62,7 @@ | |
import static org.elasticsearch.xpack.esql.plan.logical.join.JoinTypes.LEFT; | ||
import static org.elasticsearch.xpack.esql.type.EsqlDataTypeConverter.commonType; | ||
|
||
public class Join extends BinaryPlan implements PostAnalysisVerificationAware, SortAgnostic { | ||
public class Join extends BinaryPlan implements PostAnalysisVerificationAware, SortAgnostic, ExecutesOn, PostOptimizationVerificationAware { | ||
public static final NamedWriteableRegistry.Entry ENTRY = new NamedWriteableRegistry.Entry(LogicalPlan.class, "Join", Join::new); | ||
public static final DataType[] UNSUPPORTED_TYPES = { | ||
TEXT, | ||
|
@@ -309,4 +315,39 @@ private static boolean comparableTypes(Attribute left, Attribute right) { | |
public boolean isRemote() { | ||
return isRemote; | ||
} | ||
|
||
@Override | ||
public ExecuteLocation executesOn() { | ||
return isRemote ? ExecuteLocation.REMOTE : ExecuteLocation.COORDINATOR; | ||
} | ||
|
||
private void checkRemoteJoin(Failures failures) { | ||
Set<Source> fails = new HashSet<>(); | ||
|
||
var myself = this; | ||
this.forEachUp(LogicalPlan.class, u -> { | ||
if (u == myself) { | ||
return; // skip myself | ||
} | ||
if (u instanceof Limit) { | ||
// Limit is ok because it can be moved in by the optimizer | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's maybe comment that we check for upstream limits before optimization and thus can be sure that any limits encounter now were duplicated and have a corresponding downstream limit that ensures correctness. |
||
return; | ||
} | ||
if (u instanceof PipelineBreaker || (u instanceof ExecutesOn ex && ex.executesOn() == ExecuteLocation.COORDINATOR)) { | ||
fails.add(u.source()); | ||
} | ||
}); | ||
|
||
fails.forEach( | ||
f -> failures.add(fail(this, "LOOKUP JOIN with remote indices can't be executed after [" + f.text() + "]" + f.source())) | ||
); | ||
|
||
} | ||
|
||
@Override | ||
public void postOptimizationVerification(Failures failures) { | ||
if (isRemote()) { | ||
checkRemoteJoin(failures); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is just a bug - no reason why TopN source has to come from limit, OrderBy is much better IMO.