Skip to content
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

Move CsvMapper and Schema creation to constructor #4941

Merged
merged 2 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ public class CsvProcessor extends AbstractProcessor<Record<Event>, Record<Event>

private final ExpressionEvaluator expressionEvaluator;

private final CsvMapper mapper;
private final CsvSchema schema;

@DataPrepperPluginConstructor
public CsvProcessor(final PluginMetrics pluginMetrics,
final CsvProcessorConfig config,
Expand All @@ -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<Record<Event>> doExecute(final Collection<Record<Event>> records) {
final CsvMapper mapper = createCsvMapper();
final CsvSchema schema = createCsvSchema();

for (final Record<Event> record : records) {

final Event event = record.getData();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Event> eventUnderTest = createMessageEvent("1\t2\t3");
final List<Record<Event>> editedEvents = (List<Record<Event>>) csvProcessor.doExecute(Collections.singletonList(eventUnderTest));
Expand Down Expand Up @@ -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<Event> eventUnderTest = createMessageEvent("'1','2','3'");
final List<Record<Event>> editedEvents = (List<Record<Event>>) csvProcessor.doExecute(Collections.singletonList(eventUnderTest));
Expand Down
Loading