Skip to content

Commit bb3a24c

Browse files
costinnik9000
andauthored
Esql/lookup join grammar (elastic#116515) (elastic#117107)
First PR for adding LOOKUP JOIN in ESQL. Introduces grammar and wires the main building blocks to execute a query ; follow-ups are required (see elastic#116208 for more details). Co-authored-by: Nik Everett <[email protected]> (cherry picked from commit bc785f5)
1 parent d575db0 commit bb3a24c

File tree

58 files changed

+3942
-2474
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+3942
-2474
lines changed

docs/changelog/116515.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 116515
2+
summary: Esql/lookup join grammar
3+
area: ES|QL
4+
type: feature
5+
issues: []

docs/reference/esql/esql-commands.asciidoc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ image::images/esql/processing-command.svg[A processing command changing an input
3838
* <<esql-eval>>
3939
* <<esql-grok>>
4040
ifeval::["{release-state}"=="unreleased"]
41-
* experimental:[] <<esql-inlinestats-by>>
41+
//* experimental:[] <<esql-inlinestats-by>>
4242
endif::[]
4343
* <<esql-keep>>
4444
* <<esql-limit>>
4545
ifeval::["{release-state}"=="unreleased"]
46-
* experimental:[] <<esql-lookup>>
46+
//* experimental:[] <<esql-lookup>>
4747
endif::[]
4848
* experimental:[] <<esql-mv_expand>>
4949
* <<esql-rename>>
@@ -63,12 +63,12 @@ include::processing-commands/enrich.asciidoc[]
6363
include::processing-commands/eval.asciidoc[]
6464
include::processing-commands/grok.asciidoc[]
6565
ifeval::["{release-state}"=="unreleased"]
66-
include::processing-commands/inlinestats.asciidoc[]
66+
//include::processing-commands/inlinestats.asciidoc[]
6767
endif::[]
6868
include::processing-commands/keep.asciidoc[]
6969
include::processing-commands/limit.asciidoc[]
7070
ifeval::["{release-state}"=="unreleased"]
71-
include::processing-commands/lookup.asciidoc[]
71+
//include::processing-commands/lookup.asciidoc[]
7272
endif::[]
7373
include::processing-commands/mv_expand.asciidoc[]
7474
include::processing-commands/rename.asciidoc[]

docs/reference/esql/esql-query-api.asciidoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ https://en.wikipedia.org/wiki/Query_plan[EXPLAIN PLAN].
9292

9393

9494
ifeval::["{release-state}"=="unreleased"]
95-
`table`::
96-
(Optional, object) Named "table" parameters that can be referenced by the <<esql-lookup>> command.
95+
//`table`::
96+
//(Optional, object) Named "table" parameters that can be referenced by the <<esql-lookup>> command.
9797
endif::[]
9898

9999
[discrete]

x-pack/plugin/esql/qa/server/multi-clusters/src/javaRestTest/java/org/elasticsearch/xpack/esql/ccq/MultiClusterSpecIT.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import static org.elasticsearch.xpack.esql.EsqlTestUtils.classpathResources;
4848
import static org.elasticsearch.xpack.esql.action.EsqlCapabilities.Cap.INLINESTATS;
4949
import static org.elasticsearch.xpack.esql.action.EsqlCapabilities.Cap.INLINESTATS_V2;
50+
import static org.elasticsearch.xpack.esql.action.EsqlCapabilities.Cap.JOIN_LOOKUP;
5051
import static org.elasticsearch.xpack.esql.action.EsqlCapabilities.Cap.JOIN_PLANNING_V1;
5152
import static org.elasticsearch.xpack.esql.action.EsqlCapabilities.Cap.METADATA_FIELDS_REMOTE_TEST;
5253
import static org.elasticsearch.xpack.esql.qa.rest.EsqlSpecTestCase.Mode.SYNC;
@@ -124,6 +125,7 @@ protected void shouldSkipTest(String testName) throws IOException {
124125
assumeFalse("INLINESTATS not yet supported in CCS", testCase.requiredCapabilities.contains(INLINESTATS.capabilityName()));
125126
assumeFalse("INLINESTATS not yet supported in CCS", testCase.requiredCapabilities.contains(INLINESTATS_V2.capabilityName()));
126127
assumeFalse("INLINESTATS not yet supported in CCS", testCase.requiredCapabilities.contains(JOIN_PLANNING_V1.capabilityName()));
128+
assumeFalse("LOOKUP JOIN not yet supported in CCS", testCase.requiredCapabilities.contains(JOIN_LOOKUP.capabilityName()));
127129
}
128130

129131
private TestFeatureService remoteFeaturesService() throws IOException {

x-pack/plugin/esql/qa/testFixtures/src/main/java/org/elasticsearch/xpack/esql/CsvTestsDataLoader.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ public class CsvTestsDataLoader {
9393
private static final TestsDataset BOOKS = new TestsDataset("books");
9494
private static final TestsDataset SEMANTIC_TEXT = new TestsDataset("semantic_text").withInferenceEndpoint(true);
9595

96+
private static final String LOOKUP_INDEX_SUFFIX = "_lookup";
97+
9698
public static final Map<String, TestsDataset> CSV_DATASET_MAP = Map.ofEntries(
9799
Map.entry(EMPLOYEES.indexName, EMPLOYEES),
98100
Map.entry(HOSTS.indexName, HOSTS),
@@ -128,7 +130,9 @@ public class CsvTestsDataLoader {
128130
Map.entry(DISTANCES.indexName, DISTANCES),
129131
Map.entry(ADDRESSES.indexName, ADDRESSES),
130132
Map.entry(BOOKS.indexName, BOOKS),
131-
Map.entry(SEMANTIC_TEXT.indexName, SEMANTIC_TEXT)
133+
Map.entry(SEMANTIC_TEXT.indexName, SEMANTIC_TEXT),
134+
// JOIN LOOKUP alias
135+
Map.entry(LANGUAGES.indexName + LOOKUP_INDEX_SUFFIX, LANGUAGES.withIndex(LANGUAGES.indexName + LOOKUP_INDEX_SUFFIX))
132136
);
133137

134138
private static final EnrichConfig LANGUAGES_ENRICH = new EnrichConfig("languages_policy", "enrich-policy-languages.json");
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
//
2+
// CSV spec for LOOKUP JOIN command
3+
// Reuses the sample dataset and commands from enrich.csv-spec
4+
//
5+
6+
basicOnTheDataNode
7+
required_capability: join_lookup
8+
9+
//TODO: this returns different results in CI then locally
10+
// sometimes null, sometimes spanish (likely related to the execution order)
11+
FROM employees
12+
| EVAL language_code = languages
13+
| LOOKUP JOIN languages_lookup ON language_code
14+
| WHERE emp_no < 500
15+
| KEEP emp_no, language_name
16+
| SORT emp_no
17+
| LIMIT 1
18+
;
19+
20+
emp_no:integer | language_name:keyword
21+
//10091 | Spanish
22+
;
23+
24+
basicRow-Ignore
25+
required_capability: join_lookup
26+
27+
ROW language_code = 1
28+
| LOOKUP JOIN languages_lookup ON language_code
29+
;
30+
31+
language_code:keyword | language_name:keyword
32+
1 | English
33+
;
34+
35+
basicOnTheCoordinator
36+
required_capability: join_lookup
37+
38+
FROM employees
39+
| SORT emp_no
40+
| LIMIT 1
41+
| EVAL language_code = languages
42+
| LOOKUP JOIN languages_lookup ON language_code
43+
| KEEP emp_no, language_name
44+
;
45+
46+
emp_no:integer | language_name:keyword
47+
10001 | French
48+
;

0 commit comments

Comments
 (0)