Andrea Bozzano
Andrea Bozzano

Reputation: 1

Apache NiFi - Loop over flowfile's attribute value

I'm fairly new to either Stack Overflow and Apache NiFi, but I can't find any solution to my problem. My incoming Flowfile has an integer value N in an attribute, let's call it myAttribute. What I'm trying to do, is to generate N FlowFiles looping on this attribute. To achieve this, I'm trying to use the ExecuteScript processor, v1.9.0, and a Python script:

    # Starting from the incoming flowFile
    flowFile = session.get()
        if flowFile != None: # if its not None
            myAttributes = int(flowFile.getAttribute("myAttributes")) # get the number N
            for i in range(myAttributes): # loop N times
                newFlowFile=session.create(flowFile) # create a new flowfile from the previous one
                session.putAttribute(newFlowFile, 'myAttribute', str(i))        
                session.transfer(newFlowFile, REL_SUCCESS)

The expected behavior of this should be: given N from the attribute myAttributes of the incoming flowfile, generate N new flowfiles, eachone with an incremental attribute myAttribute.

E.g. my incoming flowfile has myAttributes=10, I'd love to have 10 flowfiles in output of the processor, the first one with the attribyte myAttribute = 1, then the second with myAttribute=2, etc up to myAttribute=10.

Any help or hint it's appreciated, so i thank you and i hope you're doing good :)

Kind regards,

Andrea

Upvotes: 0

Views: 507

Answers (0)

Related Questions