forked from opensearch-project/data-prepper
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updates rename_keys to use EventKey and creates a duplicate of the ol…
…d implementation named rename_keys_old to do a performance evaluation between the two. Signed-off-by: David Venable <[email protected]>
- Loading branch information
Showing
4 changed files
with
127 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
.../java/org/opensearch/dataprepper/plugins/processor/mutateevent/RenameKeyOldProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.dataprepper.plugins.processor.mutateevent; | ||
|
||
import org.opensearch.dataprepper.expression.ExpressionEvaluator; | ||
import org.opensearch.dataprepper.metrics.PluginMetrics; | ||
import org.opensearch.dataprepper.model.annotations.DataPrepperPlugin; | ||
import org.opensearch.dataprepper.model.annotations.DataPrepperPluginConstructor; | ||
import org.opensearch.dataprepper.model.event.Event; | ||
import org.opensearch.dataprepper.model.processor.AbstractProcessor; | ||
import org.opensearch.dataprepper.model.processor.Processor; | ||
import org.opensearch.dataprepper.model.record.Record; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
import static org.opensearch.dataprepper.logging.DataPrepperMarkers.EVENT; | ||
|
||
@DataPrepperPlugin(name = "rename_keys_old", pluginType = Processor.class, pluginConfigurationType = RenameKeyProcessorConfig.class) | ||
public class RenameKeyOldProcessor extends AbstractProcessor<Record<Event>, Record<Event>> { | ||
|
||
private static final Logger LOG = LoggerFactory.getLogger(RenameKeyProcessor.class); | ||
private final List<RenameKeyProcessorConfig.Entry> entries; | ||
|
||
private final ExpressionEvaluator expressionEvaluator; | ||
|
||
@DataPrepperPluginConstructor | ||
public RenameKeyOldProcessor(final PluginMetrics pluginMetrics, final RenameKeyProcessorConfig config, final ExpressionEvaluator expressionEvaluator) { | ||
super(pluginMetrics); | ||
this.entries = config.getEntries(); | ||
this.expressionEvaluator = expressionEvaluator; | ||
} | ||
|
||
@Override | ||
public Collection<Record<Event>> doExecute(final Collection<Record<Event>> records) { | ||
for(final Record<Event> record : records) { | ||
final Event recordEvent = record.getData(); | ||
|
||
try { | ||
|
||
for (RenameKeyProcessorConfig.Entry entry : entries) { | ||
if (Objects.nonNull(entry.getRenameWhen()) && !expressionEvaluator.evaluateConditional(entry.getRenameWhen(), recordEvent)) { | ||
continue; | ||
} | ||
|
||
if (entry.getFromKey().equals(entry.getToKey()) || !recordEvent.containsKey(entry.getFromKey())) { | ||
continue; | ||
} | ||
|
||
if (!recordEvent.containsKey(entry.getToKey()) || entry.getOverwriteIfToKeyExists()) { | ||
final Object source = recordEvent.get(entry.getFromKey(), Object.class); | ||
recordEvent.put(entry.getToKey(), source); | ||
recordEvent.delete(entry.getFromKey()); | ||
} | ||
} | ||
} catch (final Exception e) { | ||
LOG.error(EVENT, "There was an exception while processing Event [{}]", recordEvent, e); | ||
} | ||
} | ||
|
||
return records; | ||
} | ||
|
||
@Override | ||
public void prepareForShutdown() { | ||
} | ||
|
||
@Override | ||
public boolean isReadyForShutdown() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public void shutdown() { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters