Skip to content

Support extracting subLists from a list #5529

Open
@graytaylor0

Description

@graytaylor0

Is your feature request related to a problem? Please describe.
As a user with a field in my Events that is a List, I would like to be able to turn that list into a subList

my_list: [ 0, 1, 2, 3, 4, 5, 6]

to

my_list: [ 4, 5, 6]

or

my_list: [ 0, 1, 2 ]

or

my_list: [ 2, 3, 4]

Describe the solution you'd like
I would like a new function support in Data Prepper expressions to convert to a subList

subList(<key>, <start_index, inclusive>, <end_index, exclusive>)

An end index value of -1, could signal to extract from start_index to the end of the list.

This function could then be used in the add_entries processor like this

add_entries:
  entries:
    - key: "my_list"
      value_expression: '/subList(/my_list, 0, 2)'

Describe alternatives you've considered (Optional)
Truncate processor could support this instead

- truncate:
        entries:
          - source_keys: ["my_list"]
            length: 3
            start_at: 0

Additional context
Add any other context or screenshots about the feature request here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    • Status

      Unplanned

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions