Skip to content

Commit acb933c

Browse files
committed
Add limit handling
1 parent 841a22e commit acb933c

File tree

2 files changed

+30
-8
lines changed

2 files changed

+30
-8
lines changed

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/plan/logical/join/LookupJoin.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,28 @@
77

88
package org.elasticsearch.xpack.esql.plan.logical.join;
99

10+
import org.elasticsearch.xpack.esql.capabilities.PostAnalysisVerificationAware;
1011
import org.elasticsearch.xpack.esql.capabilities.TelemetryAware;
12+
import org.elasticsearch.xpack.esql.common.Failures;
1113
import org.elasticsearch.xpack.esql.core.expression.Attribute;
1214
import org.elasticsearch.xpack.esql.core.tree.NodeInfo;
1315
import org.elasticsearch.xpack.esql.core.tree.Source;
16+
import org.elasticsearch.xpack.esql.plan.logical.Limit;
1417
import org.elasticsearch.xpack.esql.plan.logical.LogicalPlan;
1518
import org.elasticsearch.xpack.esql.plan.logical.SurrogateLogicalPlan;
1619
import org.elasticsearch.xpack.esql.plan.logical.join.JoinTypes.UsingJoinType;
1720

21+
import java.util.LinkedList;
1822
import java.util.List;
1923

2024
import static java.util.Collections.emptyList;
25+
import static org.elasticsearch.xpack.esql.common.Failure.fail;
2126
import static org.elasticsearch.xpack.esql.plan.logical.join.JoinTypes.LEFT;
2227

2328
/**
2429
* Lookup join - specialized LEFT (OUTER) JOIN between the main left side and a lookup index (index_mode = lookup) on the right.
2530
*/
26-
public class LookupJoin extends Join implements SurrogateLogicalPlan, TelemetryAware {
31+
public class LookupJoin extends Join implements SurrogateLogicalPlan, TelemetryAware, PostAnalysisVerificationAware {
2732

2833
public LookupJoin(Source source, LogicalPlan left, LogicalPlan right, List<Attribute> joinFields, boolean isRemote) {
2934
this(source, left, right, new UsingJoinType(LEFT, joinFields), emptyList(), emptyList(), emptyList(), isRemote);
@@ -87,4 +92,21 @@ protected NodeInfo<Join> info() {
8792
public String telemetryLabel() {
8893
return "LOOKUP JOIN";
8994
}
95+
96+
@Override
97+
public void postAnalysisVerification(Failures failures) {
98+
super.postAnalysisVerification(failures);
99+
if (isRemote()) {
100+
checkRemoteJoin(failures);
101+
}
102+
}
103+
104+
private void checkRemoteJoin(Failures failures) {
105+
// Check only for LIMITs, Join will check the rest post-optimization
106+
this.forEachUp(Limit.class, f -> {
107+
failures.add(
108+
fail(this, "LOOKUP JOIN with remote indices can't be executed after [" + f.source().text() + "]" + f.source().source())
109+
);
110+
});
111+
}
90112
}

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -285,13 +285,13 @@ public void testRemoteLookupJoinWithPipelineBreaker() {
285285
)
286286
);
287287

288-
// assertEquals(
289-
// "1:68: LOOKUP JOIN with remote indices can't be executed after [LIMIT 2]@1:25",
290-
// error(
291-
// "FROM test,remote:test | LIMIT 2 | EVAL language_code = languages | LOOKUP JOIN languages_lookup ON language_code",
292-
// analyzer
293-
// )
294-
// );
288+
assertEquals(
289+
"1:68: LOOKUP JOIN with remote indices can't be executed after [LIMIT 2]@1:25",
290+
error(
291+
"FROM test,remote:test | LIMIT 2 | EVAL language_code = languages | LOOKUP JOIN languages_lookup ON language_code",
292+
analyzer
293+
)
294+
);
295295

296296
assertEquals(
297297
"1:96: LOOKUP JOIN with remote indices can't be executed after [ENRICH _coordinator:languages_coord]@1:58",

0 commit comments

Comments
 (0)