Skip to content

Commit 96a20d2

Browse files
ESQL: Enable Lookup Join on Expression Tech Preview (elastic#134952)
Enable Lookup Join on Expression Tech Preview
1 parent 39a53dc commit 96a20d2

File tree

5 files changed

+34
-17
lines changed

5 files changed

+34
-17
lines changed

docs/changelog/134952.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
pr: 134952
2+
summary: Add support for expressions with LOOKUP JOIN in tech preview
3+
area: ES|QL
4+
type: enhancement
5+
issues: [ ]
6+
highlight:
7+
title: Add support for expressions with LOOKUP JOIN in tech preview
8+
body: |-
9+
Enable Lookup Join on Expression Tech Preview
10+
FROM index1 | LOOKUP JOIN lookup_index on left_field1 > right_field1 AND left_field2 <= right_field2
11+
notable: true

docs/reference/query-languages/esql/_snippets/commands/layout/lookup-join.md

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,22 @@ FROM <source_index>
1919
FROM <source_index>
2020
| LOOKUP JOIN <lookup_index> ON <field_name1>, <field_name2>, <field_name3>
2121
```
22+
```esql
23+
FROM <source_index>
24+
| LOOKUP JOIN <lookup_index> ON <left_field1> >= <lookup_field1> AND <left_field2> == <lookup_field2>
25+
```
2226

2327
**Parameters**
2428

2529
`<lookup_index>`
2630
: The name of the lookup index. This must be a specific index name - wildcards, aliases, and remote cluster references are not supported. Indices used for lookups must be configured with the [`lookup` index mode](/reference/elasticsearch/index-settings/index-modules.md#index-mode-setting).
2731

28-
`<field_name>` or `<field_name1>, <field_name2>, <field_name3>`
29-
: The field(s) to join on. Can be either:
30-
* A single field name
31-
* A comma-separated list of field names {applies_to}`stack: ga 9.2`
32-
: These fields must exist in both your current query results and in the lookup index. If the fields contains multi-valued entries, those entries will not match anything (the added fields will contain `null` for those rows).
32+
`<field_name>` or `<field_name1>, <field_name2>, <field_name3>` or `<left_field1> >= <lookup_field1> AND <left_field2> == <lookup_field2>`
33+
: The join condition. Can be one of the following:
34+
* A single field name
35+
* A comma-separated list of field names {applies_to}`stack: ga 9.2`
36+
* An expression with one or more join conditions linked by `AND`. Each condition compares a field from the left index with a field from the lookup index using [binary operators](/reference/query-languages/esql/functions-operators/operators.md#esql-binary-operators) (`==`, `>=`, `<=`, `>`, `<`, `!=`). Each field name in the join condition must exist in only one of the indexes. Use RENAME to resolve naming conflicts. {applies_to}`stack: preview 9.2` {applies_to}`serverless: preview`
37+
: If using join on a single field or a field list, the fields used must exist in both your current query results and in the lookup index. If the fields contains multi-valued entries, those entries will not match anything (the added fields will contain `null` for those rows).
3338

3439

3540
**Description**

docs/reference/query-languages/esql/esql-lookup-join.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,15 @@ The `LOOKUP JOIN` command adds fields from the lookup index as new columns to yo
3434

3535
The command requires two parameters:
3636
* The name of the lookup index (which must have the `lookup` [`index.mode setting`](/reference/elasticsearch/index-settings/index-modules.md#index-mode-setting))
37-
* The field(s) to join on. Can be either:
38-
* A single field name
39-
* A comma-separated list of field names {applies_to}`stack: ga 9.2`
37+
* The join condition. Can be one of the following:
38+
* A single field name
39+
* A comma-separated list of field names {applies_to}`stack: ga 9.2`
40+
* An expression with one or more join conditions linked by `AND`. Each condition compares a field from the left index with a field from the lookup index using [binary operators](/reference/query-languages/esql/functions-operators/operators.md#esql-binary-operators) (`==`, `>=`, `<=`, `>`, `<`, `!=`). Each field name in the join condition must exist in only one of the indexes. Use RENAME to resolve naming conflicts. {applies_to}`stack: preview 9.2` {applies_to}`serverless: preview`
4041

4142
```esql
4243
LOOKUP JOIN <lookup_index> ON <field_name> # Join on a single field
4344
LOOKUP JOIN <lookup_index> ON <field_name1>, <field_name2>, <field_name3> # Join on multiple fields
45+
LOOKUP JOIN <lookup_index> ON <left_field1> >= <lookup_field1> AND <left_field2> == <lookup_field2> # Join on expression
4446
```
4547

4648
:::{image} ../images/esql-lookup-join.png

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1478,7 +1478,7 @@ public enum Cap {
14781478
/**
14791479
* Allow lookup join on boolean expressions
14801480
*/
1481-
LOOKUP_JOIN_ON_BOOLEAN_EXPRESSION(Build.current().isSnapshot()),
1481+
LOOKUP_JOIN_ON_BOOLEAN_EXPRESSION,
14821482

14831483
/**
14841484
* FORK with remote indices

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/parser/StatementParserTests.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3250,13 +3250,13 @@ public void testValidJoinPatternFieldJoin() {
32503250
assertThat(joinType.coreJoin().joinName(), equalTo("LEFT OUTER"));
32513251
}
32523252

3253-
public void testExpressionJoinNonSnapshotBuild() {
3254-
assumeFalse("LOOKUP JOIN is not yet in non-snapshot builds", Build.current().isSnapshot());
3255-
expectThrows(
3256-
ParsingException.class,
3257-
startsWith("line 1:31: JOIN ON clause only supports fields at the moment."),
3258-
() -> statement("FROM test | LOOKUP JOIN test2 ON left_field >= right_field")
3259-
);
3253+
/**
3254+
* Verify that both in snapshot and in release build the feature is enabled and the parsing works
3255+
* without checking for the capability
3256+
*/
3257+
public void testExpressionJoinEnabled() {
3258+
var plan = statement("FROM test | LOOKUP JOIN test2 ON left_field >= right_field");
3259+
var join = as(plan, LookupJoin.class);
32603260
}
32613261

32623262
public void testValidJoinPatternExpressionJoin() {
@@ -3290,7 +3290,6 @@ public void testValidJoinPatternExpressionJoin() {
32903290
}
32913291
}
32923292

3293-
// add a check that the feature is disabled on non-snaphsot build
32943293
String query = "FROM " + basePattern + " | LOOKUP JOIN " + joinPattern + " ON " + onExpressionString;
32953294
var plan = statement(query);
32963295

0 commit comments

Comments
 (0)