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_array_length function to PPL #3218

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

[FEATURE] Add json_array_length function to PPL #3218

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

Comments

@acarbonetto
Copy link
Collaborator

Is your feature request related to a problem?

As part of the RFC to add JSON functions, the json_array function would be useful to construct json objects with arrays.

What solution would you like?

### `JSON_ARRAY_LENGTH`

**Description**

`json_array_length(doc[, path])` Returns the number of elements in array at path in the JSON document. By default, path is the root of the document. Returns NULL if the element at path is not an array. 

**Argument type:** JSON_OBJECT, STRING

**Return type:** INTEGER | NULL

Example:

    os> source=people | eval `length1` = json_array_length(json('[1,2,3,4]'), '{}'), `length2` = json_array_length(json('[1,2,3,{"f1":1,"f2":[5,6]},4]', '{}[3].f2'), `not_array` = json_array_length(json('{"key": 1}', '{}')
    fetched rows / total rows = 1/1
    +-----------+-----------+-------------+
    | lenght1   | lenght2   | not_array   |
    +-----------+-----------+-------------+
    | 4         | 2         | null        |
    +-----------+-----------+-------------+

What alternatives have you considered?

N/A

Do you have any additional context?

opensearch-project/opensearch-spark#870 - PR to add feature to opensearch-spark PPL

@acarbonetto acarbonetto added enhancement New feature or request untriaged labels Dec 20, 2024
@acarbonetto acarbonetto changed the title [FEATURE] Add json_array_length function to PPL [FEATURE] Add json_array_length function to PPL Dec 20, 2024
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

1 participant