Support Questions

Find answers, ask questions, and share your expertise
Announcements
Check out our newest addition to the community, the Cloudera Data Analytics (CDA) group hub.

Nifi Attribute splitting

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

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

Super 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.

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

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

New Contributor

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

New Contributor

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

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

@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.

Take a Tour of the Community
Don't have an account?
Your experience may be limited. Sign in to explore more.