-
Notifications
You must be signed in to change notification settings - Fork 202
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
Conversation
Signed-off-by: Hai Yan <[email protected]>
Signed-off-by: Hai Yan <[email protected]>
Signed-off-by: Hai Yan <[email protected]>
@oeyh Please add README.md file with documentation and examples. |
} | ||
|
||
try { | ||
final Object sourceObject = recordEvent.get(config.getSource(), Object.class); |
There was a problem hiding this comment.
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);
There was a problem hiding this comment.
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)) { |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
Signed-off-by: Hai Yan <[email protected]>
Done. Also open this issue for documentation website: opensearch-project/documentation-website#6132 |
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()); | ||
} | ||
} |
There was a problem hiding this comment.
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()
));
}
There was a problem hiding this comment.
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]>
Description
This PR adds a new
map_to_list
processor.The config options are:
source
(required): the source map to perform the operationtarget
(required): the target listkey_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 listremove_processed_fields
: default is false; if true, will remove processed fields from source mapmap_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
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.