Skip to content

Commit 64a07c7

Browse files
Add UTs for join on 2,3,4 columns
1 parent 3fd48e4 commit 64a07c7

File tree

4 files changed

+131
-5
lines changed

4 files changed

+131
-5
lines changed

x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/operator/lookup/ExpressionQueryList.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ public Query getQuery(int position) {
3333
BooleanQuery.Builder builder = new BooleanQuery.Builder();
3434
for (QueryList queryList : queryLists) {
3535
Query q = queryList.getQuery(position);
36+
if (q == null) {
37+
// if any of the matchFields are null, it means there is no match for this position
38+
// A AND NULL is always NULL, so we can skip this position
39+
return null;
40+
}
3641
builder.add(q, BooleanClause.Occur.FILTER);
3742
}
3843
return builder.build();

x-pack/plugin/esql/qa/testFixtures/src/main/resources/lookup-join.csv-spec

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4871,3 +4871,124 @@ Connected to 10.1.0.1 | English | English | U
48714871
Connected to 10.1.0.1 | English | English | null
48724872
Connected to 10.1.0.1 | English | null | United Kingdom
48734873
;
4874+
4875+
lookupJoinOnTwoFields
4876+
required_capability: join_lookup_v12
4877+
required_capability: lookup_join_on_multiple_fields
4878+
4879+
FROM multi_column_joinable
4880+
| LOOKUP JOIN multi_column_joinable_lookup ON id_int, name_str
4881+
| KEEP id_int, name_str, extra1, other1, other2
4882+
| SORT id_int, name_str, extra1, other1, other2
4883+
;
4884+
4885+
id_int:integer | name_str:keyword | extra1:keyword | other1:keyword | other2:integer
4886+
1 | Alice | foo | alpha | 1000
4887+
1 | Alice | foo | beta | 2000
4888+
2 | Bob | bar | gamma | 3000
4889+
3 | Charlie | baz | delta | 4000
4890+
3 | Charlie | baz | epsilon | 5000
4891+
4 | David | qux | zeta | 6000
4892+
5 | Eve | quux | eta | 7000
4893+
5 | Eve | quux | theta | 8000
4894+
6 | null | corge | null | null
4895+
7 | Grace | grault | kappa | 10000
4896+
8 | Hank | garply | lambda | 11000
4897+
9 | Ivy | waldo | null | null
4898+
10 | John | fred | null | null
4899+
12 | Liam | xyzzy | nu | 13000
4900+
13 | Mia | thud | xi | 14000
4901+
14 | Nina | foo2 | omicron | 15000
4902+
15 | Oscar | bar2 | null | null
4903+
null | Kate | plugh | null | null
4904+
;
4905+
4906+
lookupJoinOnThreeFields
4907+
required_capability: join_lookup_v12
4908+
required_capability: lookup_join_on_multiple_fields
4909+
4910+
FROM multi_column_joinable
4911+
| LOOKUP JOIN multi_column_joinable_lookup ON id_int, name_str, is_active_bool
4912+
| KEEP id_int, name_str, extra1, other1, other2
4913+
| SORT id_int, name_str, extra1, other1, other2
4914+
;
4915+
4916+
id_int:integer | name_str:keyword | extra1:keyword | other1:keyword | other2:integer
4917+
1 | Alice | foo | alpha | 1000
4918+
1 | Alice | foo | beta | 2000
4919+
2 | Bob | bar | gamma | 3000
4920+
3 | Charlie | baz | delta | 4000
4921+
4 | David | qux | zeta | 6000
4922+
5 | Eve | quux | eta | 7000
4923+
5 | Eve | quux | theta | 8000
4924+
6 | null | corge | null | null
4925+
7 | Grace | grault | kappa | 10000
4926+
8 | Hank | garply | lambda | 11000
4927+
9 | Ivy | waldo | null | null
4928+
10 | John | fred | null | null
4929+
12 | Liam | xyzzy | nu | 13000
4930+
13 | Mia | thud | xi | 14000
4931+
14 | Nina | foo2 | omicron | 15000
4932+
15 | Oscar | bar2 | null | null
4933+
null | Kate | plugh | null | null
4934+
;
4935+
4936+
4937+
lookupJoinOnFourFields
4938+
required_capability: join_lookup_v12
4939+
required_capability: lookup_join_on_multiple_fields
4940+
4941+
FROM multi_column_joinable
4942+
| LOOKUP JOIN multi_column_joinable_lookup ON id_int, name_str, is_active_bool, ip_addr
4943+
| KEEP id_int, name_str, extra1, other1, other2
4944+
| SORT id_int, name_str, extra1, other1, other2
4945+
;
4946+
4947+
id_int:integer | name_str:keyword | extra1:keyword | other1:keyword | other2:integer
4948+
1 | Alice | foo | alpha | 1000
4949+
2 | Bob | bar | null | null
4950+
3 | Charlie | baz | delta | 4000
4951+
4 | David | qux | zeta | 6000
4952+
5 | Eve | quux | eta | 7000
4953+
5 | Eve | quux | theta | 8000
4954+
6 | null | corge | null | null
4955+
7 | Grace | grault | null | null
4956+
8 | Hank | garply | lambda | 11000
4957+
9 | Ivy | waldo | null | null
4958+
10 | John | fred | null | null
4959+
12 | Liam | xyzzy | nu | 13000
4960+
13 | Mia | thud | xi | 14000
4961+
14 | Nina | foo2 | omicron | 15000
4962+
15 | Oscar | bar2 | null | null
4963+
null | Kate | plugh | null | null
4964+
;
4965+
4966+
4967+
lookupJoinOnTwoOtherFields
4968+
required_capability: join_lookup_v12
4969+
required_capability: lookup_join_on_multiple_fields
4970+
4971+
FROM multi_column_joinable
4972+
| LOOKUP JOIN multi_column_joinable_lookup ON is_active_bool, ip_addr
4973+
| KEEP id_int, name_str, extra1, other1, other2, is_active_bool, ip_addr
4974+
| SORT id_int, name_str, extra1, other1, other2, is_active_bool, ip_addr
4975+
;
4976+
4977+
id_int:integer | name_str:keyword | extra1:keyword | other1:keyword | other2:integer | is_active_bool:boolean | ip_addr:ip
4978+
1 | Alice | foo | alpha | 1000 | true | 192.168.1.1
4979+
3 | Charlie | baz | delta | 4000 | true | 192.168.1.3
4980+
4 | David | qux | zeta | 6000 | false | 192.168.1.4
4981+
5 | Eve | quux | eta | 7000 | true | 192.168.1.5
4982+
5 | Eve | quux | theta | 8000 | true | 192.168.1.5
4983+
6 | null | corge | iota | 9000 | true | 192.168.1.6
4984+
8 | Hank | garply | lambda | 11000 | true | 192.168.1.8
4985+
12 | Liam | xyzzy | nu | 13000 | true | 192.168.1.12
4986+
13 | Mia | thud | xi | 14000 | false | 192.168.1.13
4987+
14 | Nina | foo2 | omicron | 15000 | true | 192.168.1.14
4988+
null | Kate | plugh | mu | 12000 | false | 192.168.1.11
4989+
null | null | bar | null | null | false | 192.168.1.2
4990+
null | null | bar2 | null | null | false | 192.168.1.15
4991+
null | null | fred | null | null | true | 192.168.1.10
4992+
null | null | grault | null | null | false | null
4993+
null | null | waldo | null | null | false | 192.168.1.9
4994+
;

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/action/EsqlCapabilities.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1282,9 +1282,9 @@ public enum Cap {
12821282
COSINE_VECTOR_SIMILARITY_FUNCTION(Build.current().isSnapshot()),
12831283

12841284
/**
1285-
* Support for lookup join on multiple indices.
1285+
* Support for lookup join on multiple fields.
12861286
*/
1287-
LOOKUP_JOIN_ON_MULTIPLE_INDICES,
1287+
LOOKUP_JOIN_ON_MULTIPLE_FIELDS,
12881288
/**
12891289
* Support for the options field of CATEGORIZE.
12901290
*/

x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/esql/190_lookup_join.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -278,14 +278,14 @@ lookup-no-key:
278278
- contains: { error.reason: "Unknown column [key] in right side of join" }
279279

280280
---
281-
basic join on two columns:
281+
basic join on two fields:
282282
- requires:
283283
capabilities:
284284
- method: POST
285285
path: /_query
286286
parameters: [ ]
287-
capabilities: [ lookup_join_on_multiple_indices ]
288-
reason: "uses LOOKUP JOIN on two columns"
287+
capabilities: [ lookup_join_on_multiple_fields ]
288+
reason: "uses LOOKUP JOIN on two fields"
289289
- do:
290290
esql.query:
291291
body:

0 commit comments

Comments
 (0)