diff --git a/data-prepper-plugins/csv-processor/src/main/java/org/opensearch/dataprepper/plugins/processor/csv/CsvProcessor.java b/data-prepper-plugins/csv-processor/src/main/java/org/opensearch/dataprepper/plugins/processor/csv/CsvProcessor.java index 3e8780a417..405b165ac5 100644 --- a/data-prepper-plugins/csv-processor/src/main/java/org/opensearch/dataprepper/plugins/processor/csv/CsvProcessor.java +++ b/data-prepper-plugins/csv-processor/src/main/java/org/opensearch/dataprepper/plugins/processor/csv/CsvProcessor.java @@ -46,6 +46,9 @@ public class CsvProcessor extends AbstractProcessor, Record private final ExpressionEvaluator expressionEvaluator; + private final CsvMapper mapper; + private final CsvSchema schema; + @DataPrepperPluginConstructor public CsvProcessor(final PluginMetrics pluginMetrics, final CsvProcessorConfig config, @@ -61,13 +64,12 @@ public CsvProcessor(final PluginMetrics pluginMetrics, String.format("csv_when value of %s is not a valid expression statement. " + "See https://opensearch.org/docs/latest/data-prepper/pipelines/expression-syntax/ for valid expression syntax.", config.getCsvWhen())); } + this.mapper = createCsvMapper(); + this.schema = createCsvSchema(); } @Override public Collection> doExecute(final Collection> records) { - final CsvMapper mapper = createCsvMapper(); - final CsvSchema schema = createCsvSchema(); - for (final Record record : records) { final Event event = record.getData(); diff --git a/data-prepper-plugins/csv-processor/src/test/java/org/opensearch/dataprepper/plugins/processor/csv/CsvProcessorTest.java b/data-prepper-plugins/csv-processor/src/test/java/org/opensearch/dataprepper/plugins/processor/csv/CsvProcessorTest.java index cacfedb609..0e36d8ebea 100644 --- a/data-prepper-plugins/csv-processor/src/test/java/org/opensearch/dataprepper/plugins/processor/csv/CsvProcessorTest.java +++ b/data-prepper-plugins/csv-processor/src/test/java/org/opensearch/dataprepper/plugins/processor/csv/CsvProcessorTest.java @@ -117,6 +117,7 @@ void test_when_messageIsEmpty_then_notParsed() { @Test void test_when_delimiterIsTab_then_parsedCorrectly() { when(processorConfig.getDelimiter()).thenReturn("\t"); + csvProcessor = createObjectUnderTest(); Record eventUnderTest = createMessageEvent("1\t2\t3"); final List> editedEvents = (List>) csvProcessor.doExecute(Collections.singletonList(eventUnderTest)); @@ -293,6 +294,7 @@ void test_when_twoEventsAndNoHeaderSourceOnOne_then_ChooseUserColumns() { @Test void test_when_differentQuoteCharacter_then_parsesCorrectly() { when(processorConfig.getQuoteCharacter()).thenReturn("\'"); + csvProcessor = createObjectUnderTest(); final Record eventUnderTest = createMessageEvent("'1','2','3'"); final List> editedEvents = (List>) csvProcessor.doExecute(Collections.singletonList(eventUnderTest));