diff --git a/data-prepper-plugins/split-event-processor/build.gradle b/data-prepper-plugins/split-event-processor/build.gradle index 7b6c9c934b..0271acc1a3 100644 --- a/data-prepper-plugins/split-event-processor/build.gradle +++ b/data-prepper-plugins/split-event-processor/build.gradle @@ -3,10 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ -plugins { - id 'java' -} - jacocoTestCoverageVerification { dependsOn jacocoTestReport violationRules { @@ -23,8 +19,4 @@ dependencies { implementation project(':data-prepper-api') implementation project(':data-prepper-plugins:common') implementation 'com.fasterxml.jackson.core:jackson-databind' -} - -test { - useJUnitPlatform() } \ No newline at end of file diff --git a/data-prepper-plugins/split-event-processor/src/main/java/org/opensearch/dataprepper/plugins/processor/splitevent/SplitEventProcessor.java b/data-prepper-plugins/split-event-processor/src/main/java/org/opensearch/dataprepper/plugins/processor/splitevent/SplitEventProcessor.java index 9c41943010..cadd463ae9 100644 --- a/data-prepper-plugins/split-event-processor/src/main/java/org/opensearch/dataprepper/plugins/processor/splitevent/SplitEventProcessor.java +++ b/data-prepper-plugins/split-event-processor/src/main/java/org/opensearch/dataprepper/plugins/processor/splitevent/SplitEventProcessor.java @@ -22,15 +22,17 @@ import java.util.ArrayList; import java.util.Collection; +import java.util.function.Function; import java.util.regex.Pattern; @DataPrepperPlugin(name = "split_event", pluginType = Processor.class, pluginConfigurationType = SplitEventProcessorConfig.class) public class SplitEventProcessor extends AbstractProcessor, Record>{ - final Pattern pattern; final String delimiter; final String delimiterRegex; final String field; + final Pattern pattern; + private final Function splitter; @DataPrepperPluginConstructor public SplitEventProcessor(final PluginMetrics pluginMetrics, final SplitEventProcessorConfig config) { @@ -49,8 +51,10 @@ public SplitEventProcessor(final PluginMetrics pluginMetrics, final SplitEventPr if(delimiterRegex != null && !delimiterRegex.isEmpty()) { pattern = Pattern.compile(delimiterRegex); + splitter = pattern::split; } else { - pattern = Pattern.compile(Pattern.quote(delimiter)); + splitter = inputString -> inputString.split(delimiter); + pattern = null; } } @@ -61,20 +65,18 @@ public Collection> doExecute(final Collection> recor final Event recordEvent = record.getData(); if (!recordEvent.containsKey(field)) { - Record newRecord = new Record<>(recordEvent); - newRecords.add(newRecord); + newRecords.add(record); continue; } final Object value = recordEvent.get(field, Object.class); //split record according to delimiter - final String[] splitValues = pattern.split((String) value); + final String[] splitValues = splitter.apply((String) value); - // when no splits or empty value modify the original event + // when no splits or empty value use the original record if(splitValues.length <= 1) { - Record newRecord = new Record<>(recordEvent); - newRecords.add(newRecord); + newRecords.add(record); continue; } @@ -87,8 +89,7 @@ public Collection> doExecute(final Collection> recor // Modify original event to hold the last split recordEvent.put(field, splitValues[splitValues.length-1]); - Record newRecord = new Record<>(recordEvent); - newRecords.add(newRecord); + newRecords.add(record); } return newRecords; }