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 json_delete function to PPL #3213

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

[FEATURE] Add json_delete function to PPL #3213

acarbonetto opened this issue Dec 18, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@acarbonetto
Copy link
Collaborator

acarbonetto commented Dec 18, 2024

Is your feature request related to a problem?

As part of the RFC to add JSON functions, the json_delete function would be useful to remove elements from json documents by key.

What solution would you like?

### `JSON_DELETE`

**Description**

`json_delete(doc, path [, path]...)` Deletes json elements from a json document at the specified path(s). Returns the updated document.

**Arguments type:** JSON_OBJECT, STRING

**Return type:** JSON_OBJECT

`json_delete(doc, paths)` Deletes json elements from a json document at the specified paths. Returns the updated document.

**Arguments type:** JSON_OBJECT, ARRAY

**Return type:** JSON_OBJECT

Example:

    os> source=people | eval deleted = json_delete(json('{"account_number":1,"balance":39225,"age":32,"gender":"M"}'), array('age','gender')) | head 1 | fields deleted 
    fetched rows / total rows = 1/1
    +------------------------------------------+
    | deleted                                  |
    +-----------------------------------------+
    |{"account_number":1,"balance":39225}     |
    +-----------------------------------------+

    os> source=people | eval deleted = json_delete(json('{"f1":"abc","f2":{"f3":"a","f4":"b"}}'), 'f2.f3') | head 1 | fields deleted
    fetched rows / total rows = 1/1
    +-----------------------------------------------------------+
    | deleted                                                   |
    +-----------------------------------------------------------+
    | {"f1":"abc","f2":{"f4":"b"}}                              |
    +-----------------------------------------------------------+

    os> source=people | eval deleted =  json_delete(json('{"teacher":"Alice","student":[{"name":"Bob","rank":1},{"name":"Charlie","rank":2}]}'), 'teacher', 'student.rank') | head 1 | fields deleted
    fetched rows / total rows = 1/1
    +--------------------------------------------------+
    | deleted                                          |
    +--------------------------------------------------+
    |{"student":[{"name":"Bob"},{"name":"Charlie"}]}   |
    +--------------------------------------------------+

What alternatives have you considered?

N/A

Do you have any additional context?

opensearch-project/opensearch-spark#780 - PR to add json functions to spark ppl

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants