Support Questions
Find answers, ask questions, and share your expertise
Announcements
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.

How to generate UUID in apache NIFI ?

Highlighted

How to generate UUID in apache NIFI ?

Explorer

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.

4 REPLIES 4
Highlighted

Re: How to generate UUID in apache NIFI ?

Super Guru
@Vivek Singh

UUID is associated with each flowfile so you can use expression language like

${UUID()} 

to get the unique id associated with the flowfile.

Re: How to generate UUID in apache NIFI ?

Explorer

I want to generate manually. Should I go for execute script ?

Highlighted

Re: How to generate UUID in apache NIFI ?

Super Guru

@Vivek Singh

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:-

67406-uuid.png

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

Highlighted

Re: How to generate UUID in apache NIFI ?

Super Guru
@Vivek Singh

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.

Don't have an account?
Coming from Hortonworks? Activate your account here