-
Couldn't load subscription status.
- Fork 270
Add support for spilt event processor #4166
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
Conversation
Signed-off-by: srigovs <srigovs@amazon.com>
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| plugins { |
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.
You don't need this block. It is already applied.
| implementation 'com.fasterxml.jackson.core:jackson-databind' | ||
| } | ||
|
|
||
| test { |
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.
You don't need this block. It is already applied.
|
|
||
| // when no splits or empty value modify the original event | ||
| if(splitValues.length <= 1) { | ||
| Record newRecord = new Record<>(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.
I don't think we need a new Record. Just re-use the existing one.
|
|
||
| // Modify original event to hold the last split | ||
| recordEvent.put(field, splitValues[splitValues.length-1]); | ||
| Record newRecord = new Record<>(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.
You can re-use the existing Record here as well.
| final Object value = recordEvent.get(field, Object.class); | ||
|
|
||
| //split record according to delimiter | ||
| final String[] splitValues = pattern.split((String) value); |
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.
Rather than create a Pattern for both regex and delimiter, I think you could make a Function. Then you can avoid a regex.
private final Function<String, String[]> splitter;
...
@DataPrepperPluginConstructor
public SplitEventProcessor(final PluginMetrics pluginMetrics, final SplitEventProcessorConfig config) {
...
if(delimiterRegex != null && !delimiterRegex.isEmpty()) {
Pattern pattern = Pattern.compile(delimiterRegex);
splitter = inputString -> pattern.split(inputString);
} else {
splitter = inputString -> inputString.split(delimiter);
}
}
Then this line becomes:
final String[] splitValues = splitter.apply((String) value);
Signed-off-by: srigovs <srigovs@amazon.com>
Signed-off-by: srigovs <srigovs@amazon.com>
Signed-off-by: srigovs <srigovs@amazon.com>
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.
I have one small suggestion, but this is good.
| final String delimiter; | ||
| final String delimiterRegex; | ||
| final String field; | ||
| final Pattern pattern; |
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.
I don't think you need to retain this as a field. The lambda will hold a reference to the Pattern.
|
@srikanthjg please resolve the conflicts, then we can merge the PR |
Signed-off-by: Srikanth Govindarajan <srikanthjg123@gmail.com>
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.
Looks good!
Description
Adds split event processor as described in #4089
Issues Resolved
Resolves #4089
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.