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 support json_delete, append functions #971

Merged

Conversation

YANG-DB
Copy link
Member

@YANG-DB YANG-DB commented Dec 4, 2024

Description

Add PPL support for the following json functions

  • json_delete
  • json_append

Related Issues

#970

Check List

  • Updated documentation (docs/ppl-lang/README.md)
  • Implemented unit tests
  • Implemented tests for combination with other commands
  • New added source code should include a copyright header
  • Commits are signed per the DCO using --signoff

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

- json_delete
- json_append
- json_extend

Signed-off-by: YANGDB <[email protected]>
@YANG-DB YANG-DB added Lang:PPL Pipe Processing Language support 0.7 labels Dec 10, 2024
@YANG-DB YANG-DB marked this pull request as ready for review December 10, 2024 00:19
| {"a": "valueA" } |
+----------------------------------+

os> source=people | eval eval deleted = json_delete({"a":[{"b":1},{"b":2},{"c":3}]}, json_array("a.b"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

duplicated eval


Example:

os> source=people | eval deleted = json_delete({"a":"valueA", "b":"valueB"}, json_array("a"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the second parameter is a json_array, can we add an example to drop two elements?json_delete({"a":"valueA", "b":"valueB", "c": "valueC"}, json_array("a", "b"))

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I think here we should directly use array("a") instead of json_array("a"). We have supported array function. json_array("a") is to build a json_array type with item value "a".

+-------------------------------------------------------------+
| extend |
+-------------------------------------------------------------+
| {"a":["valueA", "valueB", {"b":"valueC"}, {"b":"valueD"}]} |
Copy link
Member

@LantaoJin LantaoJin Dec 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How did you achieve this? Only the same data type could be added in a Spark Array.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I see, you are handling json string instead of Spark named_struct and array

docs/ppl-lang/functions/ppl-json.md Outdated Show resolved Hide resolved
json_delete
json_append

Signed-off-by: YANGDB <[email protected]>
json_delete
json_append

Signed-off-by: YANGDB <[email protected]>
@YANG-DB YANG-DB changed the title PPL support json_delete, append, json_extend functions PPL support json_delete, append functions Dec 11, 2024
Signed-off-by: YANGDB <[email protected]>
@YANG-DB
Copy link
Member Author

YANG-DB commented Dec 11, 2024

@LantaoJin can u plz review again ?
I've removed the json_expend from this PR only to address:

  • json_delete
  • json_append

Signed-off-by: YANGDB <[email protected]>
| {"a":["valueC"]} |
+-----------------------------------------------+

os> source=people | eval append = json_append(`{"root":{ "a":["valueA", "valueB"]}}`, array('root', 'valueC')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing a ) in the end.


`json_delete(json, [keys list])` Deletes json elements from a json object based on json specific keys. Return the updated object after keys deletion .

**Argument type:** JSON, List<STRING>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems the input json should be jsonString and type here is STRING, List<STRING>?


Example:

os> source=people | eval deleted = json_delete({"a":"valueA", "b":"valueB"}, array("a"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this query work? Is it json_delete('{"a":"valueA", "b":"valueB"}', array("a"))?

Copy link
Member Author

@YANG-DB YANG-DB Dec 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated the documentation with the examples to match the actual test

Signed-off-by: YANGDB <[email protected]>
@YANG-DB YANG-DB requested a review from LantaoJin December 16, 2024 06:35
@YANG-DB YANG-DB merged commit d789848 into opensearch-project:main Dec 16, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0.7 Lang:PPL Pipe Processing Language support
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants