Support Questions

Find answers, ask questions, and share your expertise

How are mapping files formatted for the NiFi ReplaceTextWithMapping processor?

avatar
Contributor

I am looking for a simple example of how to use the NiFi ReplaceTextWithMapping to parse file contents. Are templates available including a mapping file? Please share.

1 ACCEPTED SOLUTION

avatar
Guru

@Kausha Simpson

ReplaceTextWithMapping works exactly like ReplaceText with the exception that the ReplaceText property "Replacement Value" is defined in an external file. Unfortunately the format of that file is not very well documented. I have attached an example of that file and a sample workflow but for a high level overview the mapping file format is newline delimited per mapping defined with a \t character separator the mapping key to the desired replacement value. Good luck and hope this information helps.

View solution in original post

5 REPLIES 5

avatar
Master Mentor
@Kausha Simpson

quick search on the templates github repo shows 0 results. @jpercivall any help?

avatar
Guru

@Kausha Simpson

ReplaceTextWithMapping works exactly like ReplaceText with the exception that the ReplaceText property "Replacement Value" is defined in an external file. Unfortunately the format of that file is not very well documented. I have attached an example of that file and a sample workflow but for a high level overview the mapping file format is newline delimited per mapping defined with a \t character separator the mapping key to the desired replacement value. Good luck and hope this information helps.

avatar
Contributor

@Jeremy Dyer, thanks again!

This is a good starting point. It seems that the mapping requires a 1-to-1 relationship and might not permit more dynamic programming. I'll continue to research this processor as well as options for ExecuteProcess.

avatar

Hey Jeremy, just a heads up I just added your template and mapping file to the HWX NiFi Template repo @Artem Ervits mentioned (https://github.com/hortonworks-gallery/nifi-templates)

avatar
Explorer

@Jeremy Dyer I understand how a global replacement works, but am struggling when I just want to replace certain occurrences.

Let's say my Flowfile looks like this:

xyz key=AABBBBCC foo bar AABBBBCC

Another one looks like this:

xyz key=DDEEEEFF foo bar DDEEEEFF

I only want to replace the values that are prepended by key=

I tried with Regular Expression key=(\S+) and Matching Group 1 , which didn't work.

What did work was setting the Regex to key=(AABBBBCC|DDEEEEFF), but this unfortunately makes the regex static.