Add support for convering keys to lowercase/uppercase in RenameKeyProcessor#5810
Conversation
…cessor Signed-off-by: Krishna Kondaka <krishkdk@amazon.com>
dab2e10 to
09d6495
Compare
| boolean entriesProvided = config.getEntries() != null; | ||
| boolean transformOptionProvided = (transformOption != null && transformOption != TransformOption.NONE); | ||
| if ((!entriesProvided ^ transformOptionProvided)) { | ||
| throw new InvalidPluginConfigurationException("Only one of 'entries' or 'transform_key' should be specified."); | ||
| } |
There was a problem hiding this comment.
I think, it is Ok to have this logic here but we should also have this validation in the RenameKeyProcessorConfig so that it gets caught early on.
|
|
||
| boolean entriesProvided = config.getEntries() != null; | ||
| boolean transformOptionProvided = (transformOption != null && transformOption != TransformOption.NONE); | ||
| if ((!entriesProvided ^ transformOptionProvided)) { |
There was a problem hiding this comment.
Let's be consistent by adding the assertions in the config files.
e.g.
| throw new InvalidPluginConfigurationException("Only one of 'entries' or 'transform_key' should be specified."); | ||
| } | ||
| if (config.getEntries() == null || config.getEntries().size() == 0) { | ||
| return; |
There was a problem hiding this comment.
This could be error prone. It is assuming that no code below does anything else of importance.
Instead:
if(config.getEntries != null) {
config.getEntries().forEach(...
I do think short-circuit returns are good for functions. But, not for constructors which operate differently.
|
|
||
| private void transformEvent(final Event event, Map<String, Object> map, final String keyPrefix) { | ||
| for (Map.Entry<String, Object> entry : map.entrySet()) { | ||
| Object result = null; |
| assertThat(editedRecords.get(0).getData().containsKey("key2"), is(true)); | ||
| assertThat(editedRecords.get(0).getData().containsKey("key2/key3"), is(true)); | ||
| assertThat(editedRecords.get(0).getData().containsKey("key2/key3/key4"), is(true)); | ||
| assertThat(editedRecords.get(0).getData().containsKey("key2/key3/key5"), is(true)); |
There was a problem hiding this comment.
Also assert that the old keys are not present.
There was a problem hiding this comment.
Can we have one more test case to validate the logic in (!entriesProvided ^ transformOptionProvided) Like to test this validation part
Signed-off-by: Krishna Kondaka <krishkdk@amazon.com>
|
|
||
| ReflectivelySetField.setField(RenameKeyProcessorConfig.class, renameKeyProcessorConfig, "entries", entries); | ||
| ReflectivelySetField.setField(RenameKeyProcessorConfig.class, renameKeyProcessorConfig, "transformOption", TransformOption.LOWERCASE); | ||
| assertFalse(renameKeyProcessorConfig.isValidConfig()); |
There was a problem hiding this comment.
These should all be separate @Test methods because they are different tests.
Signed-off-by: Krishna Kondaka <krishkdk@amazon.com>
…cessor (opensearch-project#5810) * Add support for convering keys to lowercase/uppercase in RenameKeyProcessor Signed-off-by: Krishna Kondaka <krishkdk@amazon.com> * Addressed review comments Signed-off-by: Krishna Kondaka <krishkdk@amazon.com> * Addressed review comments Signed-off-by: Krishna Kondaka <krishkdk@amazon.com> --------- Signed-off-by: Krishna Kondaka <krishkdk@amazon.com> Signed-off-by: Jonah Calvo <caljonah@amazon.com>
Description
Add support for convering keys to lowercase/uppercase in RenameKeyProcessor.
Reused existing TransformOption in KeyValue processor in RenameKeyProcessor.
Addresses part of the issue #5757
Issues Resolved
Check List
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.