Created 03-28-2018 07:47 AM
I am developing a JSON to CSV converter job in NIFI and I have to generate a UUID for each json element and add that generated UUID to the flowfile. I don't find any suitable processor for generating UUID ? My question is how can I generate a UUID for each incoming flowfile.
Created 03-28-2018 07:49 AM
UUID is associated with each flowfile so you can use expression language like
${UUID()}
to get the unique id associated with the flowfile.
Created 03-28-2018 07:53 AM
I want to generate manually. Should I go for execute script ?
Created on 03-28-2018 09:07 AM - edited 08-17-2019 09:54 PM
it's already randomly generated id in NiFi,
UUID Description:
Returns a randomly generated UUID.
Subject Type: No
Subject Arguments: No arguments
Return Type: String
Examples: ${UUID()} returns a value similar to de305d54-75b4-431b-adb2-eb6b9e546013
for more reference in this link
We cannot modify the "uuid" attribute associated with the flowfile using execute script also because it is fixed for a FlowFile, if the key is named "uuid", it will be ignored.
more details regarding execute scripts are in this link
How ever we can assaign new uuid that has been generated manually to new attribute and the new attribute name is something not "uuid"
just for reference sample groovy script to generate UUID
def flowFile = session.get() if(!flowFile) return def ruuid = UUID.randomUUID().toString() flowFile = session.putAttribute(flowFile, 'uuid2', ruuid) session.transfer(flowFile, REL_SUCCESS)in this script we are just adding new attribute called as uuid2 to the flowfile and assigning randomuuid value to it.
Output:-
For each flowfile we are going to have uuid which is assigned by NiFi and uuid2 assigned by the script.
Let us know if you are having any issues..!!
Created 04-02-2018 06:26 AM
Does the answer helped, then please Click on Accept button below to accept the answer, That would be great help to Community users to find solution quickly for these kind of issues.