Skip to content

Commit

Permalink
fix errors
Browse files Browse the repository at this point in the history
Signed-off-by: Kat Shen <[email protected]>
  • Loading branch information
shenkw1 committed Aug 24, 2023
1 parent 4d8f218 commit c895037
Showing 1 changed file with 10 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ public KeyValueProcessor(final PluginMetrics pluginMetrics, final KeyValueProces

if (keyValueProcessorConfig.getRecursive()) {
if (fieldDelimiterPattern.matcher(delimiterBracketCheck).matches()) {
throw new IllegalArgumentException("While recursive is true,
the set field delimiter regex cannot contain brackets while you are trying to recurse.");
throw new IllegalArgumentException("While recursive is true, the set field delimiter regex cannot contain brackets while you are trying to recurse.");
}
}
} else {
Expand All @@ -86,8 +85,7 @@ public KeyValueProcessor(final PluginMetrics pluginMetrics, final KeyValueProces
} else {
if (keyValueProcessorConfig.getRecursive()
&& keyValueProcessorConfig.getFieldSplitCharacters().length() != 1) {
throw new IllegalArgumentException("While recursive is true,
the set field split characters is limited to one character only.");
throw new IllegalArgumentException("While recursive is true, the set field split characters is limited to one character only.");
}
regex = buildRegexFromCharacters(keyValueProcessorConfig.getFieldSplitCharacters());
}
Expand All @@ -96,8 +94,7 @@ public KeyValueProcessor(final PluginMetrics pluginMetrics, final KeyValueProces

if (keyValueProcessorConfig.getRecursive()) {
if (fieldDelimiterPattern.matcher(delimiterBracketCheck).matches()) {
throw new IllegalArgumentException("While recursive is true,
the set field split characters cannot contain brackets while you are trying to recurse.");
throw new IllegalArgumentException("While recursive is true, the set field split characters cannot contain brackets while you are trying to recurse.");
}
}
}
Expand All @@ -115,8 +112,7 @@ public KeyValueProcessor(final PluginMetrics pluginMetrics, final KeyValueProces

if (keyValueProcessorConfig.getRecursive()) {
if (keyValueDelimiterPattern.matcher(delimiterBracketCheck).matches()) {
throw new IllegalArgumentException("While recursive is true,
the set key value delimiter regex cannot contain brackets while you are trying to recurse.");
throw new IllegalArgumentException("While recursive is true, the set key value delimiter regex cannot contain brackets while you are trying to recurse.");
}
}
} else {
Expand All @@ -126,8 +122,7 @@ public KeyValueProcessor(final PluginMetrics pluginMetrics, final KeyValueProces
} else {
if (keyValueProcessorConfig.getRecursive()
&& keyValueProcessorConfig.getValueSplitCharacters().length() != 1) {
throw new IllegalArgumentException("While recursive is true,
the set value split characters is limited to one character only.");
throw new IllegalArgumentException("While recursive is true, the set value split characters is limited to one character only.");
}

regex = buildRegexFromCharacters(keyValueProcessorConfig.getValueSplitCharacters());
Expand All @@ -137,8 +132,7 @@ public KeyValueProcessor(final PluginMetrics pluginMetrics, final KeyValueProces

if (keyValueProcessorConfig.getRecursive()) {
if (keyValueDelimiterPattern.matcher(delimiterBracketCheck).matches()) {
throw new IllegalArgumentException("While recursive is true,
the set value split characters cannot contain brackets while you are trying to recurse.");
throw new IllegalArgumentException("While recursive is true, the set value split characters cannot contain brackets while you are trying to recurse.");
}
}
}
Expand Down Expand Up @@ -236,14 +230,15 @@ private void validateKeySets(final Set<String> includeSet, final Set<String> exc

@Override
public Collection<Record<Event>> doExecute(final Collection<Record<Event>> records) {
final ObjectMapper mapper = new ObjectMapper();

for(final Record<Event> record : records) {
final Map<String, Object> outputMap = new HashMap<>();
final Event recordEvent = record.getData();
final String groupsRaw = recordEvent.get(keyValueProcessorConfig.getSource(), String.class);
final String[] groups = fieldDelimiterPattern.split(groupsRaw, 0);

if (keyValueProcessorConfig.getRecursive()) {
private final ObjectMapper mapper = new ObjectMapper();
try {
JsonNode recursedTree = recurse(groupsRaw, mapper);
outputMap.putAll(createRecursedMap(recursedTree, mapper));
Expand Down Expand Up @@ -281,7 +276,7 @@ private ObjectNode recurse(String input, ObjectMapper mapper) {
}
}

if (bracketStack.isEmpty() && fieldDelimiterPattern.matcher(input.charAt(i).matches())) {
if (bracketStack.isEmpty() && fieldDelimiterPattern.matcher(String.valueOf(input.charAt(i))).matches()) {
String pair = input.substring(pairStart, i);
pairs.add(pair);
pairStart = i + 1;
Expand All @@ -302,7 +297,7 @@ private ObjectNode recurse(String input, ObjectMapper mapper) {
bracketStack.clear();

for (int i = 0; i < pair.length(); i++) {
if (bracketStack.isEmpty() && keyValueDelimiterPattern.matcher(pair.charAt(i).matches())) {
if (bracketStack.isEmpty() && keyValueDelimiterPattern.matcher(String.valueOf(pair.charAt(i))).matches()) {
keyString = pair.substring(keyStart, i).stripTrailing();
valueStart = i + 1;
while(pair.charAt(valueStart) == whitespaceChar) {
Expand Down

0 comments on commit c895037

Please sign in to comment.