Skip to content
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

[FEATURE] Add PPL support to access values in array #675

Closed
A-Gray-Cat opened this issue Sep 17, 2024 · 4 comments
Closed

[FEATURE] Add PPL support to access values in array #675

A-Gray-Cat opened this issue Sep 17, 2024 · 4 comments
Assignees
Labels
0.6 enhancement New feature or request Lang:PPL Pipe Processing Language support

Comments

@A-Gray-Cat
Copy link

Is your feature request related to a problem?
Currently, PPL doesn't support accessing values inside an array. For example,

{
    "items": ["a", "b", "c"]
}

Users can't select value a, b, or c using PPL.

What solution would you like?
Users can access the first element of the array by using syntax like eval first_item = items[0], or it can be retrieved directly using the fields command, e.g. fields items[0].

@A-Gray-Cat A-Gray-Cat added enhancement New feature or request untriaged labels Sep 17, 2024
@YANG-DB YANG-DB added the Lang:PPL Pipe Processing Language support label Sep 17, 2024
@YANG-DB
Copy link
Member

YANG-DB commented Sep 17, 2024

@A-Gray-Cat thanks - we will review !

@dblock dblock removed the untriaged label Oct 7, 2024
@dblock
Copy link
Member

dblock commented Oct 7, 2024

[Catch All Triage - 1, 2, 3, 4]

@LantaoJin
Copy link
Member

With #780 , we can access the first element in a array by

| eval first_elem = json_extract('{"items": ["a", "b", "c"]}', '$.items[0]') // json object string

or

| eval first_elem = json_extract('["a", "b", "c"]', '$.[0]') // json array string

But it requires the input is a json string. If the input is json array (ArrayType), I think we need a new function such as array_get:

| eval first_elem = array_get(json_array("a", "b", "c"), 0)

But as a workaround, we could rewrite by

| eval first_elem = json_extract(to_json_string(json_array("a", "b", "c")), '$.[0]')

From the issue's description, it seems the input is a json string and json_extract should work as the solution. @A-Gray-Cat

@YANG-DB
Copy link
Member

YANG-DB commented Nov 28, 2024

@A-Gray-Cat we are closing this since we have a workaround as described above

@YANG-DB YANG-DB closed this as completed Nov 28, 2024
@github-project-automation github-project-automation bot moved this from Design to Done in PPL Commands Nov 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0.6 enhancement New feature or request Lang:PPL Pipe Processing Language support
Projects
Status: Done
Development

No branches or pull requests

4 participants