diff --git a/data-prepper-plugins/key-value-processor/src/main/java/org/opensearch/dataprepper/plugins/processor/keyvalue/KeyValueProcessor.java b/data-prepper-plugins/key-value-processor/src/main/java/org/opensearch/dataprepper/plugins/processor/keyvalue/KeyValueProcessor.java index 9f1cd56f20..ea3a7accdb 100644 --- a/data-prepper-plugins/key-value-processor/src/main/java/org/opensearch/dataprepper/plugins/processor/keyvalue/KeyValueProcessor.java +++ b/data-prepper-plugins/key-value-processor/src/main/java/org/opensearch/dataprepper/plugins/processor/keyvalue/KeyValueProcessor.java @@ -321,7 +321,7 @@ private List parseWithValueGrouping(String str) { if (groupIndex >= 0) { String[] s = keyValueDelimiterPattern.split(str.substring(start,i+1)); // Only handle Grouping patterns in the values, not keys - if (s.length > 1 || startGroupStrings[groupIndex].charAt(0) == stringLiteralCharacter) { + if (s.length > 1 || (stringLiteralCharacter != null && startGroupStrings[groupIndex].charAt(0) == stringLiteralCharacter)) { i = skipGroup(str, i+1, endGroupChars[groupIndex]); skippedGroup = true; } diff --git a/data-prepper-plugins/key-value-processor/src/test/java/org/opensearch/dataprepper/plugins/processor/keyvalue/KeyValueProcessorTests.java b/data-prepper-plugins/key-value-processor/src/test/java/org/opensearch/dataprepper/plugins/processor/keyvalue/KeyValueProcessorTests.java index 2adfc37884..505e236ea9 100644 --- a/data-prepper-plugins/key-value-processor/src/test/java/org/opensearch/dataprepper/plugins/processor/keyvalue/KeyValueProcessorTests.java +++ b/data-prepper-plugins/key-value-processor/src/test/java/org/opensearch/dataprepper/plugins/processor/keyvalue/KeyValueProcessorTests.java @@ -250,6 +250,24 @@ private static Stream getKeyValueGroupingTestdata() { ); } + @Test + void testValueGroupingWithOutStringLiterals() { + when(mockConfig.getDestination()).thenReturn(null); + String message = "text1 text2 [ key1=value1 value2"; + lenient().when(mockConfig.getStringLiteralCharacter()).thenReturn(null); + lenient().when(mockConfig.getFieldSplitCharacters()).thenReturn(" ,"); + lenient().when(mockConfig.getValueGrouping()).thenReturn(true); + final Record record = getMessage(message); + keyValueProcessor = createObjectUnderTest(); + final List> editedRecords = (List>) keyValueProcessor.doExecute(Collections.singletonList(record)); + + final Event event = editedRecords.get(0).getData(); + assertThat(event.containsKey("parsed_message"), is(false)); + + assertThat(event.containsKey("key1"), is(true)); + assertThat(event.get("key1", Object.class), is("value1")); + } + @ParameterizedTest @ValueSource(strings = {"\"", "'"}) void testStringLiteralCharacter(String literalString) {