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

flatten processor: option for keys wihout brackets #4616

Closed
timo-mue opened this issue Jun 11, 2024 · 5 comments · Fixed by #4653
Closed

flatten processor: option for keys wihout brackets #4616

timo-mue opened this issue Jun 11, 2024 · 5 comments · Fixed by #4653
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@timo-mue
Copy link
Contributor

Is your feature request related to a problem? Please describe.
Currently the flatten processor adds empty squared brackets to the keys of list elements, even when the remove_list_indices option is set to true. So something like

{
  "key1": {
    "key2": [
      {
        "key3": "value1",
        "key4": "value2"
      },
      {
        "key3": "value3",
        "key4": "value4"
      }
    ]
  }
}

turns into

{
  "key1.key2[].key3": ["value1", "value3"],
  "key1.key2[].key4": ["value2", "value4"]
}

When the mentioned option is set to false the brackets are needed to reference list indices but in this case they could easily be ommited. It would be nice if the keys would keep their original names and the output would be this instead:

{
  "key1.key2.key3": ["value1", "value3"],
  "key1.key2.key4": ["value2", "value4"]
}

Describe the solution you'd like
Either remove the brackets from keys when remove_list_indices is set to true, or add an option (original_key or remove_brackets) that has the same effect when used together with remove_list_indices set to true.
Additional context
For some automated processes (e.g. creating mappings via index templates before writing documents) it could be valuable to retain the original key names.

@oeyh
Copy link
Collaborator

oeyh commented Jun 11, 2024

This is a reasonable ask and should be a small change.

@oeyh
Copy link
Collaborator

oeyh commented Jun 11, 2024

@timo-mue would you like contribute to Data Prepper and make the changes for this issue? I can also help.

The related code is here:

private Map<String, Object> removeListIndicesInKeys(final Map<String, Object> inputMap) {

The configs are set up in FlattenProcessorConfig.java

@oeyh
Copy link
Collaborator

oeyh commented Jun 11, 2024

There is a use case (#3965) to keep the brackets after removing list indices, so we want to retain that option.

We can add an option for removing the indices along with the brackets. Either through:

remove_list_indices: true
remove_brackets: true

or just:

remove_list_indices_and_brackets: true

@timo-mue
Copy link
Contributor Author

@timo-mue would you like contribute to Data Prepper and make the changes for this issue? I can also help.

Sure, I will try to make the changes.

We can add an option for removing the indices along with the brackets. Either through:

remove_list_indices: true
remove_brackets: true

What would be the behavior for using remove_list_indices: false together with remove_brackets: true? Should that turn something like "key1.key2[0].key3": "value1" into "key1.key20.key3": "value1" or just get ignored?

@oeyh
Copy link
Collaborator

oeyh commented Jun 13, 2024

Thanks @timo-mue!

We should probably disallow that case by adding a validation (see an example here) so that when remove_list_indices is false, remove_brackets cannot be true.

Or, we add the option named remove_list_indices_and_brackets to bind them together.

timo-mue added a commit to timo-mue/data-prepper that referenced this issue Jun 21, 2024
)

Signed-off-by: Timo Mueller <timo.mueller@tower.telekom-cloudcenter.de>
timo-mue added a commit to timo-mue/data-prepper that referenced this issue Jun 21, 2024
)

Signed-off-by: Timo Mueller <timo.mueller@tower.telekom-cloudcenter.de>
timo-mue added a commit to timo-mue/data-prepper that referenced this issue Jun 21, 2024
)

Signed-off-by: Timo Mueller <timo.mueller@tower.telekom-cloudcenter.de>
oeyh pushed a commit that referenced this issue Jun 21, 2024
Signed-off-by: Timo Mueller <timo.mueller@tower.telekom-cloudcenter.de>
@github-project-automation github-project-automation bot moved this from Unplanned to Done in Data Prepper Tracking Board Jun 21, 2024
@dlvenable dlvenable added this to the v2.9 milestone Jun 21, 2024
kkondaka pushed a commit to kkondaka/kk-data-prepper-f2 that referenced this issue Jul 23, 2024
) (opensearch-project#4653)

Signed-off-by: Timo Mueller <timo.mueller@tower.telekom-cloudcenter.de>
Signed-off-by: Krishna Kondaka <krishkdk@dev-dsk-krishkdk-2c-bd29c437.us-west-2.amazon.com>
kkondaka pushed a commit to kkondaka/kk-data-prepper-f2 that referenced this issue Jul 23, 2024
) (opensearch-project#4653)

Signed-off-by: Timo Mueller <timo.mueller@tower.telekom-cloudcenter.de>
Signed-off-by: Krishna Kondaka <krishkdk@dev-dsk-krishkdk-2c-bd29c437.us-west-2.amazon.com>
kkondaka pushed a commit to kkondaka/kk-data-prepper-f2 that referenced this issue Jul 30, 2024
) (opensearch-project#4653)

Signed-off-by: Timo Mueller <timo.mueller@tower.telekom-cloudcenter.de>
Signed-off-by: Krishna Kondaka <krishkdk@dev-dsk-krishkdk-2c-bd29c437.us-west-2.amazon.com>
kkondaka pushed a commit to kkondaka/kk-data-prepper-f2 that referenced this issue Aug 8, 2024
) (opensearch-project#4653)

Signed-off-by: Timo Mueller <timo.mueller@tower.telekom-cloudcenter.de>
Signed-off-by: Krishna Kondaka <krishkdk@dev-dsk-krishkdk-2c-bd29c437.us-west-2.amazon.com>
kkondaka pushed a commit to kkondaka/kk-data-prepper-f2 that referenced this issue Aug 12, 2024
) (opensearch-project#4653)

Signed-off-by: Timo Mueller <timo.mueller@tower.telekom-cloudcenter.de>
Signed-off-by: Krishna Kondaka <krishkdk@dev-dsk-krishkdk-2c-bd29c437.us-west-2.amazon.com>
kkondaka pushed a commit to kkondaka/kk-data-prepper-f2 that referenced this issue Aug 14, 2024
) (opensearch-project#4653)

Signed-off-by: Timo Mueller <timo.mueller@tower.telekom-cloudcenter.de>
Signed-off-by: Krishna Kondaka <krishkdk@dev-dsk-krishkdk-2c-bd29c437.us-west-2.amazon.com>
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
Development

Successfully merging a pull request may close this issue.

3 participants