Skip to content

Conversation

@srikanthjg
Copy link
Collaborator

@srikanthjg srikanthjg commented Feb 21, 2024

Description

Adds split event processor as described in #4089

Issues Resolved

Resolves #4089

Check List

  • [ X] New functionality includes testing.
  • New functionality has a documentation issue. Please link to it in this PR.
    • New functionality has javadoc added
  • [X ] 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: srigovs <srigovs@amazon.com>
* SPDX-License-Identifier: Apache-2.0
*/

plugins {
Copy link
Member

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 {
Copy link
Member

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);
Copy link
Member

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);
Copy link
Member

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);
Copy link
Member

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);

dlvenable
dlvenable previously approved these changes Feb 21, 2024
Copy link
Member

@dlvenable dlvenable left a 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;
Copy link
Member

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.

kkondaka
kkondaka previously approved these changes Feb 26, 2024
@kkondaka
Copy link
Collaborator

@srikanthjg please resolve the conflicts, then we can merge the PR

Signed-off-by: Srikanth Govindarajan <srikanthjg123@gmail.com>
@srikanthjg srikanthjg dismissed stale reviews from kkondaka and dlvenable via 17b477f February 26, 2024 20:44
Copy link
Collaborator

@oeyh oeyh left a comment

Choose a reason for hiding this comment

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

Looks good!

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.

Create a split event processor

4 participants