Skip to content

Commit 8b801bb

Browse files
committed
Fix for KEEP/DROP/RENAME/MV_EXPAND/ENRICH
1 parent 5f50233 commit 8b801bb

File tree

8 files changed

+1133
-1017
lines changed

8 files changed

+1133
-1017
lines changed

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

Lines changed: 62 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -351,17 +351,21 @@ German | null | fork2
351351
Spanish | null | fork2
352352
;
353353

354-
forkBranchWithDrop-Ignore
354+
forkBranchWithDrop
355355
required_capability: fork_v8
356356

357357
FROM languages
358-
| FORK ( DROP language_code | WHERE language_name == "English" | EVAL x = 1 )
358+
| FORK ( EVAL x = 1 | DROP language_code | WHERE language_name == "English" | DROP x )
359359
( WHERE language_name != "English" )
360360
| SORT _fork, language_name
361+
| KEEP language_name, language_code, _fork
361362
;
362363

363-
language_name:keyword | language_code:integer | x:integer | _fork:keyword
364-
a | 1 | 2
364+
language_name:keyword | language_code:integer | _fork:keyword
365+
English | null | fork1
366+
French | 2 | fork2
367+
German | 4 | fork2
368+
Spanish | 3 | fork2
365369
;
366370

367371

@@ -381,6 +385,22 @@ French | fork1
381385
English | fork2
382386
;
383387

388+
forkBranchWithKeep
389+
required_capability: fork_v8
390+
391+
FROM languages
392+
| FORK ( WHERE language_name == "English" | KEEP language_name, language_code )
393+
( WHERE language_name != "English" )
394+
| SORT _fork, language_name
395+
;
396+
397+
language_name:keyword | language_code:integer | _fork:keyword
398+
English | 1 | fork1
399+
French | 2 | fork2
400+
German | 4 | fork2
401+
Spanish | 3 | fork2
402+
;
403+
384404
forkBeforeRename
385405
required_capability: fork_v8
386406

@@ -397,19 +417,39 @@ code:integer | language_name:keyword | _fork:keyword
397417
1 | English | fork2
398418
;
399419

400-
forkBranchWithRenameAs-Ignore
420+
forkBranchWithRenameAs
401421
required_capability: fork_v8
402422

403423
FROM languages
404424
| FORK (RENAME language_code AS code | WHERE code == 1 OR code == 2)
405425
(WHERE language_code == 1 | RENAME language_code AS x)
406426
| SORT _fork, language_name
427+
| KEEP code, language_name, x, _fork
428+
;
429+
430+
code:integer | language_name:keyword | x:integer | _fork:keyword
431+
1 | English | null | fork1
432+
2 | French | null | fork1
433+
null | English | 1 | fork2
434+
;
435+
436+
forkBranchWithRenameEquals
437+
required_capability: fork_v8
438+
439+
FROM languages
440+
| FORK (RENAME code = language_code | WHERE code == 1 OR code == 2)
441+
(WHERE language_code == 1 | RENAME x = language_code)
442+
| SORT _fork, language_name
443+
| KEEP code, language_name, x, _fork
407444
;
408445

409-
language_name:keyword | x:integer | code:integer | _fork:keyword
410-
1 | 2 | 3 | 4
446+
code:integer | language_name:keyword | x:integer | _fork:keyword
447+
1 | English | null | fork1
448+
2 | French | null | fork1
449+
null | English | 1 | fork2
411450
;
412451

452+
413453
forkAfterRename
414454
required_capability: fork_v8
415455

@@ -502,19 +542,24 @@ Japan | Tokyo | null
502542
Japan | Tokyo | null | fork2
503543
;
504544

505-
forkBranchWithEnrich-Ignore
545+
forkBranchWithEnrich
506546
required_capability: fork_v8
507547

508548
FROM addresses
509549
| KEEP city.country.continent.planet.name, city.country.name, city.name
510550
| EVAL city.name = REPLACE(city.name, "San Francisco", "South San Francisco")
511551
| FORK (ENRICH city_names ON city.name WITH city.country.continent.planet.name = airport)
512-
(WHERE city.country.name == "Japan")
552+
(ENRICH city_names ON city.name WITH city.country.continent.planet.name = airport)
513553
| SORT _fork, city.name
514554
;
515555

516556
city.country.name:keyword | city.name:keyword | city.country.continent.planet.name:text | _fork:keyword
517-
Netherlands | Amsterdam | null | a
557+
Netherlands | Amsterdam | null | fork1
558+
United States of America | South San Francisco | San Francisco Int'l | fork1
559+
Japan | Tokyo | null | fork1
560+
Netherlands | Amsterdam | null | fork2
561+
United States of America | South San Francisco | San Francisco Int'l | fork2
562+
Japan | Tokyo | null | fork2
518563
;
519564

520565
forkBeforeEnrich
@@ -556,7 +601,7 @@ emp_no:integer | job_positions:keyword | _fork:keyword
556601
10087 | Junior Developer | fork2
557602
;
558603

559-
forkBranchWithMvExpand-Ignore
604+
forkBranchWithMvExpand
560605
required_capability: fork_v8
561606

562607
FROM employees
@@ -566,8 +611,12 @@ FROM employees
566611
| SORT _fork, emp_no, job_positions
567612
;
568613

569-
emp_no:integer | job_positions:keyword | _fork:keyword
570-
1 | 2 | 3
614+
emp_no:integer | job_positions:keyword | _fork:keyword
615+
10048 | Internship | fork1
616+
10081 | Accountant | fork1
617+
10081 | Internship | fork1
618+
10081 | [Accountant, Internship] | fork2
619+
10087 | [Internship, Junior Developer] | fork2
571620
;
572621

573622
forkAfterMvExpand

x-pack/plugin/esql/src/internalClusterTest/java/org/elasticsearch/xpack/esql/action/ForkIT.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -777,6 +777,29 @@ public void testWithDrop() {
777777
}
778778
}
779779

780+
public void testWithKeep() {
781+
var query = """
782+
FROM test
783+
| WHERE id > 2
784+
| FORK
785+
( WHERE content:"fox" | KEEP id)
786+
( WHERE content:"dog" | KEEP id)
787+
| SORT id, _fork
788+
""";
789+
790+
try (var resp = run(query)) {
791+
assertColumnNames(resp.columns(), List.of("id", "_fork"));
792+
assertColumnTypes(resp.columns(), List.of("integer", "keyword"));
793+
Iterable<Iterable<Object>> expectedValues = List.of(
794+
List.of(3, "fork2"),
795+
List.of(4, "fork2"),
796+
List.of(6, "fork1"),
797+
List.of(6, "fork2")
798+
);
799+
assertValues(resp.values(), expectedValues);
800+
}
801+
}
802+
780803
public void testWithEvalWithConflictingTypes() {
781804
var query = """
782805
FROM test

x-pack/plugin/esql/src/main/antlr/lexer/Enrich.g4

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ ENRICH : 'enrich' -> pushMode(ENRICH_MODE);
1414

1515
mode ENRICH_MODE;
1616
ENRICH_PIPE : PIPE -> type(PIPE), popMode;
17+
ENRICH_RP : RP -> type(RP), popMode, popMode;
1718
ENRICH_OPENING_BRACKET : OPENING_BRACKET -> type(OPENING_BRACKET), pushMode(SETTING_MODE);
1819

1920
ENRICH_ON : ON -> type(ON), pushMode(ENRICH_FIELD_MODE);
@@ -49,6 +50,7 @@ ENRICH_WS
4950
// submode for Enrich to allow different lexing between policy source (loose) and field identifiers
5051
mode ENRICH_FIELD_MODE;
5152
ENRICH_FIELD_PIPE : PIPE -> type(PIPE), popMode, popMode;
53+
ENRICH_FIELD_RP : RP -> type(RP), popMode, popMode, popMode;
5254
ENRICH_FIELD_ASSIGN : ASSIGN -> type(ASSIGN);
5355
ENRICH_FIELD_COMMA : COMMA -> type(COMMA);
5456
ENRICH_FIELD_DOT: DOT -> type(DOT);
@@ -82,6 +84,7 @@ ENRICH_FIELD_WS
8284
8385
mode SETTING_MODE;
8486
SETTING_CLOSING_BRACKET : CLOSING_BRACKET -> type(CLOSING_BRACKET), popMode;
87+
SETTING_RP : RP -> type(RP), popMode, popMode, popMode;
8588
8689
SETTING_COLON : COLON -> type(COLON);
8790

x-pack/plugin/esql/src/main/antlr/lexer/MvExpand.g4

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ MV_EXPAND : 'mv_expand' -> pushMode(MVEXPAND_MODE);
1414

1515
mode MVEXPAND_MODE;
1616
MVEXPAND_PIPE : PIPE -> type(PIPE), popMode;
17+
MVEXPAND_RP : RP -> type(RP), popMode, popMode;
1718
MVEXPAND_DOT: DOT -> type(DOT);
1819
MVEXPAND_PARAM : PARAM -> type(PARAM);
1920
MVEXPAND_NAMED_OR_POSITIONAL_PARAM : NAMED_OR_POSITIONAL_PARAM -> type(NAMED_OR_POSITIONAL_PARAM);

x-pack/plugin/esql/src/main/antlr/lexer/Project.g4

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ DEV_INSIST : {this.isDevVersion()}? 'insist_🐔' -> pushMode(PROJECT_
1515

1616
mode PROJECT_MODE;
1717
PROJECT_PIPE : PIPE -> type(PIPE), popMode;
18+
PROJECT_RP : RP -> type(RP), popMode, popMode;
1819
PROJECT_DOT: DOT -> type(DOT);
1920
PROJECT_COMMA : COMMA -> type(COMMA);
2021
PROJECT_PARAM : PARAM -> type(PARAM);

x-pack/plugin/esql/src/main/antlr/lexer/Rename.g4

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ RENAME : 'rename' -> pushMode(RENAME_MODE);
1414

1515
mode RENAME_MODE;
1616
RENAME_PIPE : PIPE -> type(PIPE), popMode;
17+
RENAME_RP : RP -> type(RP), popMode, popMode;
1718
RENAME_ASSIGN : ASSIGN -> type(ASSIGN);
1819
RENAME_COMMA : COMMA -> type(COMMA);
1920
RENAME_DOT: DOT -> type(DOT);

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/parser/EsqlBaseLexer.interp

Lines changed: 7 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)