-
Notifications
You must be signed in to change notification settings - Fork 25.6k
ES|QL: Add docs for FORK #130314
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
ES|QL: Add docs for FORK #130314
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
93e54fb
Add docs for FORK
ioanatia 4c29a91
typo
ioanatia 83f1f19
Update docs/reference/query-languages/esql/_snippets/lists/processing…
ioanatia fe63238
Apply suggestions from code review
ioanatia 8a5630b
Group limitations
ioanatia a91b594
Apply suggestions from code review
ioanatia 02804f8
Update docs/reference/query-languages/esql/_snippets/commands/layout/…
ioanatia File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
...ce/query-languages/esql/_snippets/commands/examples/fork.csv-spec/simpleFork.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| % This is generated by ESQL's AbstractFunctionTestCase. Do not edit it. See ../README.md for how to regenerate it. | ||
|
|
||
| ```esql | ||
| FROM employees | ||
| | FORK ( WHERE emp_no == 10001 ) | ||
| ( WHERE emp_no == 10002 ) | ||
| | KEEP emp_no, _fork | ||
| | SORT emp_no | ||
| ``` | ||
|
|
||
| | emp_no:integer | _fork:keyword | | ||
| | --- | --- | | ||
| | 10001 | fork1 | | ||
| | 10002 | fork2 | |
19 changes: 19 additions & 0 deletions
19
...languages/esql/_snippets/commands/examples/fork.csv-spec/simpleForkWithStats.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| % This is generated by ESQL's AbstractFunctionTestCase. Do not edit it. See ../README.md for how to regenerate it. | ||
|
|
||
| ```esql | ||
| FROM books METADATA _score | ||
| | WHERE author:"Faulkner" | ||
| | EVAL score = round(_score, 2) | ||
| | FORK (SORT score DESC, author | LIMIT 5 | KEEP author, score) | ||
| (STATS total = COUNT(*)) | ||
| | SORT _fork, score DESC, author | ||
| ``` | ||
|
|
||
| | author:text | score:double | _fork:keyword | total:long | | ||
| | --- | --- | --- | --- | | ||
| | William Faulkner | 2.39 | fork1 | null | | ||
| | William Faulkner | 2.39 | fork1 | null | | ||
| | Colleen Faulkner | 1.59 | fork1 | null | | ||
| | Danny Faulkner | 1.59 | fork1 | null | | ||
| | Keith Faulkner | 1.59 | fork1 | null | | ||
| | null | null | fork2 | 18 | |
67 changes: 67 additions & 0 deletions
67
docs/reference/query-languages/esql/_snippets/commands/layout/fork.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| ## `FORK` [esql-fork] | ||
|
|
||
| ```yaml {applies_to} | ||
| serverless: preview | ||
| stack: preview 9.1.0 | ||
| ``` | ||
| The `FORK` processing command runs multiple execution branches and outputs the | ||
| results back into a single table. | ||
ioanatia marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| **Syntax** | ||
|
|
||
| ```esql | ||
| FORK ( <processing_commands> ) ( <processing_commands> ) ... ( <processing_commands> ) | ||
| ``` | ||
|
|
||
| **Description** | ||
|
|
||
| The `FORK` processing command feeds the input rows into multiple execution | ||
| branches and outputs the results into a single table, enhanced with a | ||
| discriminator column called `_fork`. | ||
ioanatia marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| The values of the discriminator column `_fork` are `fork1`, `fork2`, ... and | ||
| they designate which `FORK` branch the current row is coming from. | ||
| The values of the `_fork` column always start with `fork1`, which indicates that | ||
| the row is coming from the first branch. | ||
ioanatia marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| The `FORK` branches can output different columns as long as there exists no | ||
| column with the same name and different data types in two different `FORK` | ||
| branches. | ||
ioanatia marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| When a column does not exist in a `FORK` branch, but it exists in the output of | ||
| other branches, `FORK` will add `null` values to the rows that have missing | ||
| columns. | ||
|
|
||
| `FORK` preserves the order of the rows from each subset, but it does not | ||
| guarantee that the rows will follow the same order in which the `FORK` branches | ||
| are defined. The rows from the first branch can be interleaved with the rows | ||
| from subsequent branches. Use `SORT _fork` after `FORK` if you need to change | ||
| this behaviour. | ||
ioanatia marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| `FORK` branches receive an implicit `LIMIT 1000` if no `LIMIT` is provided. | ||
ioanatia marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ::::{note} | ||
leemthompo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| `FORK` supports at most 8 execution branches. | ||
| :::: | ||
|
|
||
| ::::{note} | ||
| Using remote cluster references and `FORK` is not supported. | ||
| :::: | ||
|
|
||
| ::::{note} | ||
| Using more than one `FORK` command in a query is not supported. | ||
| :::: | ||
|
|
||
| **Examples** | ||
|
|
||
| In the following example, each `FORK` branch returns one row. | ||
| Notice how `FORK` adds a `_fork` that indicates from which row the branch is | ||
ioanatia marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| coming: | ||
ioanatia marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| :::{include} ../examples/fork.csv-spec/simpleFork.md | ||
|
|
||
| The next example, returns total number of rows that match the query along with | ||
| the top five rows sorted by score. | ||
|
|
||
| :::{include} ../examples/fork.csv-spec/simpleForkWithStats.md | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.