Skip to content

Commit

Permalink
Lookup join on multiple join fields not yet supported (#118858) (#118940
Browse files Browse the repository at this point in the history
)
  • Loading branch information
astefan authored Dec 18, 2024
1 parent f410f2e commit 59d0584
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
5 changes: 5 additions & 0 deletions docs/changelog/118858.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 118858
summary: Lookup join on multiple join fields not yet supported
area: ES|QL
type: enhancement
issues: []
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,11 @@ public PlanFactory visitJoinCommand(EsqlBaseParser.JoinCommandContext ctx) {
}
}

var matchFieldsCount = joinFields.size();
if (matchFieldsCount > 1) {
throw new ParsingException(source, "JOIN ON clause only supports one field at the moment, found [{}]", matchFieldsCount);
}

return p -> new LookupJoin(source, p, right, joinFields);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.elasticsearch.xcontent.XContentBuilder;
import org.elasticsearch.xcontent.json.JsonXContent;
import org.elasticsearch.xpack.esql.LoadMapping;
import org.elasticsearch.xpack.esql.action.EsqlCapabilities;
import org.elasticsearch.xpack.esql.core.expression.Expression;
import org.elasticsearch.xpack.esql.core.type.DataType;
import org.elasticsearch.xpack.esql.expression.function.EsqlFunctionRegistry;
Expand Down Expand Up @@ -111,6 +112,46 @@ public void testTooBigQuery() {
assertEquals("-1:-1: ESQL statement is too large [1000011 characters > 1000000]", error(query.toString()));
}

public void testJoinOnConstant() {
assumeTrue("LOOKUP JOIN available as snapshot only", EsqlCapabilities.Cap.JOIN_LOOKUP_V7.isEnabled());
assertEquals(
"1:55: JOIN ON clause only supports fields at the moment, found [123]",
error("row languages = 1, gender = \"f\" | lookup join test on 123")
);
assertEquals(
"1:55: JOIN ON clause only supports fields at the moment, found [\"abc\"]",
error("row languages = 1, gender = \"f\" | lookup join test on \"abc\"")
);
assertEquals(
"1:55: JOIN ON clause only supports fields at the moment, found [false]",
error("row languages = 1, gender = \"f\" | lookup join test on false")
);
}

public void testJoinOnMultipleFields() {
assumeTrue("LOOKUP JOIN available as snapshot only", EsqlCapabilities.Cap.JOIN_LOOKUP_V7.isEnabled());
assertEquals(
"1:35: JOIN ON clause only supports one field at the moment, found [2]",
error("row languages = 1, gender = \"f\" | lookup join test on gender, languages")
);
}

public void testJoinTwiceOnTheSameField() {
assumeTrue("LOOKUP JOIN available as snapshot only", EsqlCapabilities.Cap.JOIN_LOOKUP_V7.isEnabled());
assertEquals(
"1:35: JOIN ON clause only supports one field at the moment, found [2]",
error("row languages = 1, gender = \"f\" | lookup join test on languages, languages")
);
}

public void testJoinTwiceOnTheSameField_TwoLookups() {
assumeTrue("LOOKUP JOIN available as snapshot only", EsqlCapabilities.Cap.JOIN_LOOKUP_V7.isEnabled());
assertEquals(
"1:80: JOIN ON clause only supports one field at the moment, found [2]",
error("row languages = 1, gender = \"f\" | lookup join test on languages | eval x = 1 | lookup join test on gender, gender")
);
}

private String functionName(EsqlFunctionRegistry registry, Expression functionCall) {
for (FunctionDefinition def : registry.listFunctions()) {
if (functionCall.getClass().equals(def.clazz())) {
Expand Down

0 comments on commit 59d0584

Please sign in to comment.