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

[PPL-Lang] PPL support json_set, json_extend functions #996

Open
acarbonetto opened this issue Dec 19, 2024 · 0 comments
Open

[PPL-Lang] PPL support json_set, json_extend functions #996

acarbonetto opened this issue Dec 19, 2024 · 0 comments
Labels
0.7 enhancement New feature or request Lang:PPL Pipe Processing Language support

Comments

@acarbonetto
Copy link

Is your feature request related to a problem?

As follow-up to #780, continue Supporting the PPL Json grammar with adding the next functions:

  • json_set(object, [(path key, value) list])
Inserts or updates one or more keys and their corresponding values from the specified JSON object: 

objects: the Json object is the field being evaluated
[path key, value]: the list of key-value pairs to add/update in the document
  • json_extend(object, [(path key, value) list])
Appends values to a JSON array element with provided values and returns the updated JSON object.

objects: the Json object is the field being evaluated
[path key, value]: the list of key-value pairs to extend arrays with values in the document.

What solution would you like?

Support the following json_set

Example:

    os> source=people | eval updated = json_set('{"a":[{"b":1},{"b":2}]}', '$.a[*].b', 3) | head 1 | fields updated 
    fetched rows / total rows = 1/1
    +-------------------------+
    | updated                 |
    +-------------------------+
    | {"a":[{"b":3},{"b":3}]} |
    +-------------------------+

Support the following json_extend

Note that json_extend is identical to json_append function except that it flattens the arrays before appending them to the json value at path.

Example:

    os> source=people | eval extend = json_extend(`{"teacher":["Alice"],"student":[{"name":"Bob","rank":1},{"name":"Charlie","rank":2}]}`, 'student', '{"name":"Tommy","rank":5}') | head 1 | fields extend
    fetched rows / total rows = 1/1
    +-----------------------------------------------------------------------------------------------------------------------------------+
    | extend                                                                                                                            |
    +-----------------------------------------------------------------------------------------------------------------------------------+
    |{"teacher":["Alice"],"student":[{"name":"Bob","rank":1},{"name":"Charlie","rank":2},{"name":"Tommy","rank":5}]}                     |
    +-----------------------------------------------------------------------------------------------------------------------------------+

    os> source=people | eval extend = json_extend(`{"teacher":["Alice"],"student":[{"name":"Bob","rank":1},{"name":"Charlie","rank":2}]}`, 'teacher', array('Tom', 'Walt')) | head 1 | fields extend
    fetched rows / total rows = 1/1
    +-----------------------------------------------------------------------------------------------------------------------------------+
    | extend                                                                                                                            |
    +-----------------------------------------------------------------------------------------------------------------------------------+
    |{"teacher":["Alice","Tom","Walt"],"student":[{"name":"Bob","rank":1},{"name":"Charlie","rank":2}]}                                 |
    +-----------------------------------------------------------------------------------------------------------------------------------+


    os> source=people | eval extend = json_extend(`{"school":{"teacher":["Alice"],"student":[{"name":"Bob","rank":1},{"name":"Charlie","rank":2}]}}`, 'school.teacher', array('Tom', 'Walt')) | head 1 | fields extend
    fetched rows / total rows = 1/1
    +-------------------------------------------------------------------------------------------------------------------------+
    | extend                                                                                                                  |
    +-------------------------------------------------------------------------------------------------------------------------+
    |{"school":{"teacher":["Alice","Tom","Walt"],"student":[{"name":"Bob","rank":1},{"name":"Charlie","rank":2}]}}            |
    +-------------------------------------------------------------------------------------------------------------------------+

What alternatives have you considered?

N/A

Do you have any additional context?

@acarbonetto acarbonetto added enhancement New feature or request untriaged labels Dec 19, 2024
@YANG-DB YANG-DB added Lang:PPL Pipe Processing Language support 0.7 and removed untriaged labels Dec 19, 2024
@YANG-DB YANG-DB moved this to Todo in PPL Commands Dec 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0.7 enhancement New feature or request Lang:PPL Pipe Processing Language support
Projects
Status: Todo
Development

No branches or pull requests

2 participants