Support Questions
Find answers, ask questions, and share your expertise

How to use ExecuteScript (with python as a script engine) for an exercise to add numbers? [Novice user trying to learn NiFi]

New Contributor

I am relatively new to NiFi and am not sure how to do the following correctly. I would like to use ExecuteScript processor (script engine: python) to do the following (only in python please):

1) There is a CSV file containing the following information (the first row is the header):



2) I would like to find the sum of individual rows and generate a final file with a modified header. The final file should look like this:



For the python script, I wrote:

def summation(first,second,third):
    numbers = first + second + third
    return numbers
flowFile = session.get()
if (flowFile != None):
    flowFile = session.write(flowFile, summation())

But it does not work and I am not sure how to fix this. Can anyone provide me an understanding on how to approach this problem?

The NiFi flow:



First, congrats on getting started with NiFi and not being afraid to tackle one of the harder processors: ExecuteScript.

My advice is to start small, get a working script that maybe doesnt do what you want, but does actually complete and return SUCCESS in your NiFi flow. From there you can start building it up and testing step by step. I also recommend that you tail the NIFI Log during all of your work so that you can see any errors or information from each test/step. My last peice of advice for an advanced script would be to manually execute your script to ensure that its logic is working outside of the execution from within NiFi.

You may find the following links very helpful:

If my answer is helpful, please choose ACCEPT.

; ;