Skip to content

Commit e8d2e97

Browse files
committed
Address PR comments
Signed-off-by: Taylor Gray <tylgry@amazon.com>
1 parent f9f8f1a commit e8d2e97

2 files changed

Lines changed: 27 additions & 12 deletions

File tree

data-prepper-plugins/mutate-event-processors/src/main/java/org/opensearch/dataprepper/plugins/processor/mutateevent/SelectEntriesProcessor.java

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,7 @@ public Collection<Record<Event>> doExecute(final Collection<Record<Event>> recor
5858
}
5959
// To handle nested case, just get the values and store
6060
// in a temporary map.
61-
Map<String, Object> outMap = new HashMap<>();
62-
if (keysToInclude != null) {
63-
for (String keyToInclude: keysToInclude) {
64-
Object value = recordEvent.get(keyToInclude, Object.class);
65-
if (value != null) {
66-
outMap.put(keyToInclude, value);
67-
}
68-
}
69-
}
61+
Map<String, Object> outMap = getIncludeKeysOutputMap(recordEvent);
7062

7163
Map<String, Object> regexOutMap = getIncludeKeysRegexOutputMap(recordEvent);
7264

@@ -98,6 +90,20 @@ public boolean isReadyForShutdown() {
9890
public void shutdown() {
9991
}
10092

93+
private Map<String, Object> getIncludeKeysOutputMap(final Event event) {
94+
Map<String, Object> outMap = new HashMap<>();
95+
if (keysToInclude != null) {
96+
for (String keyToInclude: keysToInclude) {
97+
Object value = event.get(keyToInclude, Object.class);
98+
if (value != null) {
99+
outMap.put(keyToInclude, value);
100+
}
101+
}
102+
}
103+
104+
return outMap;
105+
}
106+
101107
private Map<String, Object> getIncludeKeysRegexOutputMap(final Event event) {
102108
if (includeKeysRegex == null || includeKeysRegex.isEmpty()) {
103109
return Collections.emptyMap();
@@ -107,7 +113,7 @@ private Map<String, Object> getIncludeKeysRegexOutputMap(final Event event) {
107113

108114
Map<String, Object> eventMap;
109115

110-
if (includeKeysRegexPointer != null) {
116+
if (includeKeysRegexPointer != null && !includeKeysRegexPointer.equals("/")) {
111117
if (!event.containsKey(includeKeysRegexPointer)) {
112118
return Collections.emptyMap();
113119
}
@@ -124,7 +130,7 @@ private Map<String, Object> getIncludeKeysRegexOutputMap(final Event event) {
124130

125131
for (final Pattern includeKeyRegex : includeKeysRegex) {
126132
if (includeKeyRegex.matcher(entry.getKey()).matches()) {
127-
final String fullKey = includeKeysRegexPointer != null ? includeKeysRegexPointer + "/" + entry.getKey() : entry.getKey();
133+
final String fullKey = getFullKey(entry.getKey(), includeKeysRegexPointer);
128134
outputMap.put(fullKey, entry.getValue());
129135
break;
130136
}
@@ -133,5 +139,9 @@ private Map<String, Object> getIncludeKeysRegexOutputMap(final Event event) {
133139

134140
return outputMap;
135141
}
142+
143+
private String getFullKey(final String key, final String includeKeysRegexPointer) {
144+
return includeKeysRegexPointer != null ? includeKeysRegexPointer + "/" + key : key;
145+
}
136146
}
137147

data-prepper-plugins/mutate-event-processors/src/main/java/org/opensearch/dataprepper/plugins/processor/mutateevent/SelectEntriesProcessorConfig.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ public String getSelectWhen() {
6363
return selectWhen;
6464
}
6565

66+
private void setIncludeKeysRegex() {
67+
includeKeysRegexPatterns = includeKeysRegex.stream().map(Pattern::compile).collect(Collectors.toList());
68+
}
69+
70+
6671
@AssertTrue(message = "At least one of include_keys and include_keys_regex is required.")
6772
boolean isValidIncludeKeys() {
6873
return (includeKeys != null && !includeKeys.isEmpty()) || (includeKeysRegex != null && !includeKeysRegex.isEmpty());
@@ -72,7 +77,7 @@ boolean isValidIncludeKeys() {
7277
boolean isValidIncludeKeysRegex() {
7378
if (includeKeysRegex != null && !includeKeysRegex.isEmpty()) {
7479
try {
75-
includeKeysRegexPatterns = includeKeysRegex.stream().map(Pattern::compile).collect(Collectors.toList());
80+
setIncludeKeysRegex();
7681
} catch (final PatternSyntaxException e) {
7782
return false;
7883
}

0 commit comments

Comments
 (0)