-
Notifications
You must be signed in to change notification settings - Fork 33
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
Expand ppl command #868
Merged
LantaoJin
merged 15 commits into
opensearch-project:main
from
YANG-DB:expand-ppl-command
Nov 7, 2024
Merged
Expand ppl command #868
Changes from 11 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
35ea4d1
add expand command
YANG-DB 54abdbe
Merge branch 'main' into expand-ppl-command
YANG-DB a6e76ec
add expand command with visitor
YANG-DB f0335cc
create unit / integration tests
YANG-DB a54262e
Merge branch 'main' into expand-ppl-command
YANG-DB d8a003f
update expand tests
YANG-DB 7b50ffa
Merge branch 'main' into expand-ppl-command
YANG-DB 71b7497
add tests
YANG-DB ef1d890
update doc
YANG-DB 3db02ce
update docs with examples
YANG-DB 76baeee
update scala style
YANG-DB ff39d31
Merge branch 'main' into expand-ppl-command
YANG-DB a91a986
update with additional test case
YANG-DB 82f7135
update with additional test case
YANG-DB cdadb18
update documentation
YANG-DB 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
This file contains 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 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 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,92 @@ | ||
## PPL `expand` command | ||
|
||
### Description | ||
Using `expand` command to flatten a field of type: | ||
- `Array<Any>` | ||
- `Map<Any>` | ||
|
||
|
||
### Syntax | ||
`expand <field> [As alias]` | ||
|
||
* field: to be expanded (exploded). The field must be of supported type. | ||
* alias: Optional to be expanded as the name to be used instead of the original field name | ||
|
||
### Test table | ||
|
||
#### Schema | ||
| col\_name | data\_type | | ||
|-----------|----------------------------------------------| | ||
| \_time | string | | ||
| bridges | array\<struct\<length:bigint,name:string\>\> | | ||
| city | string | | ||
| country | string | | ||
|
||
#### Data | ||
| \_time | bridges | city | country | | ||
|---------------------|----------------------------------------------|---------|----------------| | ||
| 2024-09-13T12:00:00 | [{801, Tower Bridge}, {928, London Bridge}] | London | England | | ||
| 2024-09-13T12:00:00 | [{232, Pont Neuf}, {160, Pont Alexandre III}]| Paris | France | | ||
| 2024-09-13T12:00:00 | [{48, Rialto Bridge}, {11, Bridge of Sighs}] | Venice | Italy | | ||
| 2024-09-13T12:00:00 | [{516, Charles Bridge}, {343, Legion Bridge}]| Prague | Czech Republic | | ||
| 2024-09-13T12:00:00 | [{375, Chain Bridge}, {333, Liberty Bridge}] | Budapest| Hungary | | ||
| 1990-09-13T12:00:00 | NULL | Warsaw | Poland | | ||
|
||
|
||
|
||
### Example 1: expand struct | ||
This example shows how to expand an array of struct field. | ||
PPL query: | ||
- `source=table | expand bridges as britishBridge | fields britishBridge` | ||
|
||
| \_time | bridges | city | country | alt | lat | long | | ||
|---------------------|----------------------------------------------|---------|---------------|-----|--------|--------| | ||
| 2024-09-13T12:00:00 | [{801, Tower Bridge}, {928, London Bridge}] | London | England | 35 | 51.5074| -0.1278| | ||
| 2024-09-13T12:00:00 | [{232, Pont Neuf}, {160, Pont Alexandre III}]| Paris | France | 35 | 48.8566| 2.3522 | | ||
| 2024-09-13T12:00:00 | [{48, Rialto Bridge}, {11, Bridge of Sighs}] | Venice | Italy | 2 | 45.4408| 12.3155| | ||
| 2024-09-13T12:00:00 | [{516, Charles Bridge}, {343, Legion Bridge}]| Prague | Czech Republic| 200 | 50.0755| 14.4378| | ||
| 2024-09-13T12:00:00 | [{375, Chain Bridge}, {333, Liberty Bridge}] | Budapest| Hungary | 96 | 47.4979| 19.0402| | ||
| 1990-09-13T12:00:00 | NULL | Warsaw | Poland | NULL| NULL | NULL | | ||
|
||
|
||
|
||
### Example 2: expand array | ||
|
||
The example shows how to expand an array of struct fields. | ||
|
||
PPL query: | ||
- `source=table | expand bridges` | ||
|
||
| \_time | city | coor | country | length | name | | ||
|---------------------|---------|------------------------|---------------|--------|-------------------| | ||
| 2024-09-13T12:00:00 | London | {35, 51.5074, -0.1278} | England | 801 | Tower Bridge | | ||
| 2024-09-13T12:00:00 | London | {35, 51.5074, -0.1278} | England | 928 | London Bridge | | ||
| 2024-09-13T12:00:00 | Paris | {35, 48.8566, 2.3522} | France | 232 | Pont Neuf | | ||
| 2024-09-13T12:00:00 | Paris | {35, 48.8566, 2.3522} | France | 160 | Pont Alexandre III| | ||
| 2024-09-13T12:00:00 | Venice | {2, 45.4408, 12.3155} | Italy | 48 | Rialto Bridge | | ||
| 2024-09-13T12:00:00 | Venice | {2, 45.4408, 12.3155} | Italy | 11 | Bridge of Sighs | | ||
| 2024-09-13T12:00:00 | Prague | {200, 50.0755, 14.4378}| Czech Republic| 516 | Charles Bridge | | ||
| 2024-09-13T12:00:00 | Prague | {200, 50.0755, 14.4378}| Czech Republic| 343 | Legion Bridge | | ||
| 2024-09-13T12:00:00 | Budapest| {96, 47.4979, 19.0402} | Hungary | 375 | Chain Bridge | | ||
| 2024-09-13T12:00:00 | Budapest| {96, 47.4979, 19.0402} | Hungary | 333 | Liberty Bridge | | ||
| 1990-09-13T12:00:00 | Warsaw | NULL | Poland | NULL | NULL | | ||
|
||
|
||
### Example 3: expand array and struct | ||
This example shows how to expand multiple fields. | ||
PPL query: | ||
- `source=table | expand bridges | expand coor` | ||
|
||
| \_time | city | country | length | name | alt | lat | long | | ||
|---------------------|---------|---------------|--------|-------------------|------|--------|--------| | ||
| 2024-09-13T12:00:00 | London | England | 801 | Tower Bridge | 35 | 51.5074| -0.1278| | ||
| 2024-09-13T12:00:00 | London | England | 928 | London Bridge | 35 | 51.5074| -0.1278| | ||
| 2024-09-13T12:00:00 | Paris | France | 232 | Pont Neuf | 35 | 48.8566| 2.3522 | | ||
| 2024-09-13T12:00:00 | Paris | France | 160 | Pont Alexandre III| 35 | 48.8566| 2.3522 | | ||
| 2024-09-13T12:00:00 | Venice | Italy | 48 | Rialto Bridge | 2 | 45.4408| 12.3155| | ||
| 2024-09-13T12:00:00 | Venice | Italy | 11 | Bridge of Sighs | 2 | 45.4408| 12.3155| | ||
| 2024-09-13T12:00:00 | Prague | Czech Republic| 516 | Charles Bridge | 200 | 50.0755| 14.4378| | ||
| 2024-09-13T12:00:00 | Prague | Czech Republic| 343 | Legion Bridge | 200 | 50.0755| 14.4378| | ||
| 2024-09-13T12:00:00 | Budapest| Hungary | 375 | Chain Bridge | 96 | 47.4979| 19.0402| | ||
| 2024-09-13T12:00:00 | Budapest| Hungary | 333 | Liberty Bridge | 96 | 47.4979| 19.0402| | ||
| 1990-09-13T12:00:00 | Warsaw | Poland | NULL | NULL | NULL | NULL | NULL | |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we add this example here:
source= table | expand json_array(1, 2, 3) as uid | fields uid
(returns 3 rows with values 1, 2 and 3)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And add a similar test case in IT.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@LantaoJin question:
currently both flatten & expand only support
fieldExpression
Maybe using the next slightly different version of this expand array query ?
source = table | eval array=json_array(1, 2, 3) | expand array as uid | fields name, occupation, uid
would give a similar functional result without actually changing the grammar ?