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

Add map_to_list processor #3945

Merged
merged 5 commits into from
Jan 11, 2024
Merged

Conversation

oeyh
Copy link
Collaborator

@oeyh oeyh commented Jan 10, 2024

Description

This PR adds a new map_to_list processor.

The config options are:
source(required): the source map to perform the operation
target(required): the target list
key_name: the key name of the field to hold the original key, default is "key"
value_name: the key name of the field to hold the original value, default is "value"
exclude_keys: the keys in source map that will be excluded from processing, default is empty list
remove_processed_fields: default is false; if true, will remove processed fields from source map
map_to_list_when: used to configure a condition for event processing based on certain property of the incoming event. Default is null (all events will be processed).

Issues Resolved

Resolves #3935

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.

@oeyh oeyh changed the title Adds map_to_list processor Add map_to_list processor Jan 10, 2024
@kkondaka
Copy link
Collaborator

@oeyh Please add README.md file with documentation and examples.

}

try {
final Object sourceObject = recordEvent.get(config.getSource(), Object.class);
Copy link
Member

Choose a reason for hiding this comment

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

Why can't we combine these two lines into:

final Map<String, Object> sourceObject = recordEvent.get(config.getSource(), Map.class);

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Combined.

for (final Record<Event> record : records) {
final Event recordEvent = record.getData();

if (Objects.nonNull(config.getMapToListWhen()) && !expressionEvaluator.evaluateConditional(config.getMapToListWhen(), recordEvent)) {
Copy link
Member

Choose a reason for hiding this comment

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

Let's use config.getMapToListWhen() != null instead of calling Objects.nonNull.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

@oeyh
Copy link
Collaborator Author

oeyh commented Jan 11, 2024

@oeyh Please add README.md file with documentation and examples.

Done. Also open this issue for documentation website: opensearch-project/documentation-website#6132

Comment on lines 72 to 78
if (config.getRemoveProcessedFields()) {
Map<String, Object> modifiedSourceMap = new HashMap<>();
for (final Map.Entry<String, Object> entry : sourceMap.entrySet()) {
if (excludeKeySet.contains(entry.getKey())) {
modifiedSourceMap.put(entry.getKey(), entry.getValue());
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

This code can be merged with the code in lines 62-70 like below, right?

          Map<String, Object> modifiedSourceMap = new HashMap<>();
          for (final Map.Entry<String, Object> entry : sourceMap.entrySet()) {
                    if (excludeKeySet.contains(entry.getKey())) {
                        modifiedSourceMap.put(entry.getKey(), 
                        continue;
                    }
                    targetList.add(Map.of(
                            config.getKeyName(), entry.getKey(),
                            config.getValueName(), entry.getValue()
                    ));
                }

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Merged the two for loops.

Signed-off-by: Hai Yan <[email protected]>
@dlvenable dlvenable merged commit 787064e into opensearch-project:main Jan 11, 2024
45 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.

MapToList processor
3 participants