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

Enhance copy_values processor to selectively copy entries from lists #4085

Merged
merged 4 commits into from
Feb 9, 2024

Conversation

oeyh
Copy link
Collaborator

@oeyh oeyh commented Feb 6, 2024

Description

The configurations are like this:

  processor:
    - copy_values:
        from_list: mylist
        to_list: newlist
        entries:
          - from_key: name
            to_key: fruit_name

Example input:

{
  "mylist": [
    {"name": "apple", "color": "red"},
    {"name": "orange", "color": "orange"}
  ]
}

Example output:

{
  "newlist": [
    {"fruit_name": "apple"},
    {"fruit_name": "orange"}
  ]
}

Issues Resolved

Resolves #3962

Check List

  • New functionality includes testing.
  • New functionality has a documentation issue. Please link to it in this PR.
    • New functionality has javadoc added
  • Commits are signed with a real name per the DCO

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.

Signed-off-by: Hai Yan <oeyh@amazon.com>
Signed-off-by: Hai Yan <oeyh@amazon.com>
Signed-off-by: Hai Yan <oeyh@amazon.com>
Copy link
Collaborator

@chenqi0805 chenqi0805 left a comment

Choose a reason for hiding this comment

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

Minor changes. I suppose there will be certain metrics added but can be in a separate PR

if (!recordEvent.containsKey(entry.getToKey()) || entry.getOverwriteIfToKeyExists()) {
final Object source = recordEvent.get(entry.getFromKey(), Object.class);
recordEvent.put(entry.getToKey(), source);
if (!recordEvent.containsKey(entry.getToKey()) || entry.getOverwriteIfToKeyExists()) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggest refactor L77-85 into a private method shouldCopyEntry or skipCopyEntry

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good one. Made the change.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Also opened an issue for adding metrics: #4088

Signed-off-by: Hai Yan <oeyh@amazon.com>
Copy link
Collaborator

@kkondaka kkondaka left a comment

Choose a reason for hiding this comment

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

Please make necessary changes to README.md file as well.

}
try {
final Event recordEvent = record.getData();
if (config.getFromList() != null || config.getToList() != null) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this check correct? What is the expected behavior if getFromList() returns null but getToList() is not null?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I have a validation in CopyValueProcessorConfig that checks from_list and to_list should be both null or both non-null. So I assume this situation that getFromList() returns null but getToList() is not null won't happen.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Regarding documentation, since we are adopting the new process to use the documentation website and remove readme (see #2740). I have this issue created to update over there: opensearch-project/documentation-website#6390

@oeyh oeyh merged commit bd9ae27 into opensearch-project:main Feb 9, 2024
46 of 47 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature Request] Mapping Records within a Record Array
3 participants