Created 06-13-2016 07:42 PM
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.
Created 06-13-2016 07:45 PM
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
Created 06-13-2016 07:44 PM
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.
Created 06-14-2016 01:13 PM
The question is regarding splitting the attributes of the FlowFile. ReplaceText and ReplaceTextWithMapping both work on the content of the FlowFile, not the attributes.
Created 06-13-2016 07:45 PM
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
Created 06-13-2016 08:05 PM
Perfect, that got me moving forward in the right direction !
Created 08-16-2018 09:00 PM
You can use this custom processor for your problem. (and you can contribute if you want )
https://github.com/guvencenanguvenal/nifi-splitcreateattribute
Created 08-17-2018 11:52 AM
@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.