Support Questions

Find answers, ask questions, and share your expertise
Announcements
Celebrating as our community reaches 100,000 members! Thank you!

Nifi Attribute splitting

avatar
New Contributor

I've worked out how to pull down information from online json and parse the basics into attributes and write those out to a file. I would like to split one of those attributes from 1 to two different attributes....This seems basic to me, but for the life of me I can't seem to work out the logic in NiFi

For example:

attribute1 = 2016-06-13T11:52:19-05:00

I'd like to split that on the T into two attributes like the following:

attribute2: 2016-06-13

attributes3: 11:52:19-05:00

In Python this is just date, time = timestamp.split('T', 1), but alas Nifi is eluding me with the end goal is to write this out into a flat file or Hive, but either way there are a bunch of needs I'll have for something like the above split.

1 ACCEPTED SOLUTION

avatar

Hi @Todd Wilkinson,

I'd use an UpdateAttribute processor by adding two dynamic properties and using expression language as follow:

attribute2 => ${attribute1:substringBefore('T')}

attribute3 => ${attribute1:substringAfter('T')}

Hope this helps.

Expression language guide : https://nifi.apache.org/docs/nifi-docs/html/expression-language-guide.html

View solution in original post

6 REPLIES 6

avatar
Master Guru

@Todd Wilkinson

I would use replacetext processor. more info here.

Updates the content of a FlowFile by evaluating a Regular Expression (regex) against it and replacing the section of the content that matches the Regular Expression with some alternate value.

you would search for the value and replace with output $1, $2, etc.

You can also use replaceTextWithMapping.

Updates the content of a FlowFile by evaluating a Regular Expression against it and replacing the section of the content that matches the Regular Expression with some alternate value provided in a mapping file.

avatar

The question is regarding splitting the attributes of the FlowFile. ReplaceText and ReplaceTextWithMapping both work on the content of the FlowFile, not the attributes.

avatar

Hi @Todd Wilkinson,

I'd use an UpdateAttribute processor by adding two dynamic properties and using expression language as follow:

attribute2 => ${attribute1:substringBefore('T')}

attribute3 => ${attribute1:substringAfter('T')}

Hope this helps.

Expression language guide : https://nifi.apache.org/docs/nifi-docs/html/expression-language-guide.html

avatar
New Contributor

Perfect, that got me moving forward in the right direction !

avatar
New Contributor

You can use this custom processor for your problem. (and you can contribute if you want )

https://github.com/guvencenanguvenal/nifi-splitcreateattribute

avatar
Super Guru

@Guven Guvenal this is a great custom processor, you should create a HOWTO Article here about how to use it and or create one about how to make Custom Processors.