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 constructor function to PPL #3217

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

[FEATURE] Add json_array constructor function to PPL #3217

acarbonetto opened this issue Dec 19, 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?

Tasks to complete:

  • Add json_array(scalar_value) that returns an ARRAY object with scalars.
  • Add json_array(field) that returns an ARRAY object with values from the field, where field can be a multi-value.
  • Add json_array(json_object) that returns an ARRAY object with JSON_OBJECTs.
  • Add json_array(json_array) that returns a mult-dimensional ARRAY object.
  • Add json_array as part of the json_object construction; json_object(key, value [, key, value]*) -> json_object function, where value can also be a `json_array. see: [FEATURE] Add json_object constructor function to PPL #3208.
### `JSON_ARRAY`

**Description**

`json_array(<value>...)` Creates a JSON ARRAY flattening a list of multi-valued fields.

**Argument type:**
- A \<value\> can be any kind of value such as string, number, boolean, array, or json_object. 

**Return type:** ARRAY (Spark ArrayType)

An array of any supported data type for a valid JSON array.

Example:

    os> source=people | eval `json_array` = json_array(1, 2, 0, -1, 1.1, -0.11)
    fetched rows / total rows = 1/1

    +------------------------------+
    | json_array                   |
    +------------------------------+
    | [1.0,2.0,0.0,-1.0,1.1,-0.11] |
    +------------------------------+

    os> source=people | eval `json_array_object` = json_object("array", json_array(1, 2, 0, -1, 1.1, -0.11))

    fetched rows / total rows = 1/1
    +----------------------------------------+
    | json_array_object                      |
    +----------------------------------------+
    | {"array":[1.0,2.0,0.0,-1.0,1.1,-0.11]} |
    +----------------------------------------+

What alternatives have you considered?

N/A

Do you have any additional context?

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

@acarbonetto acarbonetto added enhancement New feature or request untriaged labels Dec 19, 2024
@Swiddis Swiddis removed the untriaged label Dec 19, 2024
@acarbonetto acarbonetto changed the title [FEATURE] Add json_array constructor function to PPL [FEATURE] Add json_array constructor 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

2 participants