NIFI-14363 - Add a replaceByPattern expression language function#9799
NIFI-14363 - Add a replaceByPattern expression language function#9799exceptionfactory merged 2 commits intoapache:mainfrom
Conversation
Signed-off-by: Pierre Villard <pierre.villard.fr@gmail.com>
exceptionfactory
left a comment
There was a problem hiding this comment.
Thanks for proposing this new function @pvillard31. The basic concept makes sense, but I think a different name would be more intuitive.
The mapTo name seems to imply the argument contains the destination, reminding me of the Kotlin mapTo functions. Just using map seems too generic, but something that incorporates that word is a good starting point.
Options such as mapKeyValue or mapKeyPatternValue come to mind, although the latter is more verbose. Even mapKeyValue isn't the most clear.
One other concern is the , separator, which could be problematic for matching , characters in the expression itself.
One that comes to mind is altering the approach to take only one pattern and one value at a time. This would require multiple function calls, but could be cleaner. Could the desired behavior accomplished using multiple replace or replaceFirst calls? Perhaps building on the replace naming would be a better way to go.
Those are some initial thoughts, glad to discuss this further to consider the best solution.
|
Thanks for the review @exceptionfactory - I pushed a commit to rename the function into Regarding the |
exceptionfactory
left a comment
There was a problem hiding this comment.
Thanks for making the adjustments @pvillard31. I think replaceByPattern is a good fit for the functionality, and I agree the , separator is somewhat of an edge case that could be addressed in the future with an additional optional argument providing an alternative delimiter if needed.
I plan to merge pending successful builds.
| // if the search string is a literal, we don't need to evaluate it each time; we can just | ||
| // pre-compile it. Otherwise, it must be compiled every time. | ||
| if (search instanceof StringLiteralEvaluator) { | ||
| this.compiledPatterns = compilePatterns(search.evaluate(new StandardEvaluationContext(Collections.emptyMap())).getValue()); |
There was a problem hiding this comment.
This maybe a little late but I do not think you need Collections.emptyMap() for this, couldn't you just use Map.of() ?
| this.compiledPatterns = compilePatterns(search.evaluate(new StandardEvaluationContext(Collections.emptyMap())).getValue()); | |
| this.compiledPatterns = compilePatterns(search.evaluate(new StandardEvaluationContext(Map.of())).getValue()); |
There was a problem hiding this comment.
Thanks @dan-s1, they are functionally equivalent, but I agree Map.of() is preferred. I just merged the PR, but good to keep in mind for the future.
Summary
NIFI-14363 - Add a replaceByPattern expression language function
Tracking
Please complete the following tracking steps prior to pull request creation.
Issue Tracking
Pull Request Tracking
NIFI-00000NIFI-00000Pull Request Formatting
mainbranchVerification
Please indicate the verification steps performed prior to pull request creation.
Build
mvn clean install -P contrib-checkLicensing
LICENSEandNOTICEfilesDocumentation