Skip to content

Commit

Permalink
Fix KeyValue Processor value grouping bug (opensearch-project#4606)
Browse files Browse the repository at this point in the history
Signed-off-by: Krishna Kondaka <krishkdk@dev-dsk-krishkdk-2c-bd29c437.us-west-2.amazon.com>
Co-authored-by: Krishna Kondaka <krishkdk@dev-dsk-krishkdk-2c-bd29c437.us-west-2.amazon.com>
  • Loading branch information
kkondaka and Krishna Kondaka authored Jun 6, 2024
1 parent 2180a69 commit 5cf0927
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ private List<String> 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,24 @@ private static Stream<Arguments> 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<Event> record = getMessage(message);
keyValueProcessor = createObjectUnderTest();
final List<Record<Event>> editedRecords = (List<Record<Event>>) 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) {
Expand Down

0 comments on commit 5cf0927

Please sign in to comment.