0

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

2
  • What error(s) are you getting? If it says "flowfile not transferred or removed", don't forget to remove the flowFile from the session unless you are planning on transferring it Commented Jun 17, 2022 at 19:53
  • also putAttribute creates a modified file instance: newFlowFile = session.putAttribute(newFlowFile, 'myAttribute', str(i)) Commented Jun 18, 2022 at 7:45

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.