Support Questions

Find answers, ask questions, and share your expertise
Announcements
Celebrating as our community reaches 100,000 members! Thank you!

manipulate flowfile with executescript processor in nifi with python

avatar
Expert Contributor

Hello,

I want to do some stuff on my data while ingesting so i created a little python script to do that .

I am ingesting csv files and want to remove carriage return, linefeed etc in the columns. Also adding new column with timestamp

My script looks lige this

import csv
import sys  
flowFile = session.get()                 
 with open(flowFile, 'rb') as csvfile:
        spamreader = csv.reader(csvfile, delimiter='    ', quotechar='|')
        for row in spamreader:
                for col in row:
                        col.rstrip('\n\r ')


                print ', '.join(row)


14890-executescript1.png

Right now i got this error when running it

2017-04-27 12:40:13,463 ERROR [Timer-Driven Process Thread-8] o.a.nifi.processors.script.ExecuteScript ExecuteScript[id=af58777c-015b-1000-ffff-ffff972978f8] Failed to process session due to org.apache.nifi.processor.exception.ProcessException: javax.script.ScriptException: NameError: name 'flowfile' is not defined in <script> at line number 3: org.apache.nifi.processor.exception.ProcessException: javax.script.ScriptException: NameError: name 'flowfile' is not defined in <script> at line number 3


What should i add to this script in order to output the manipulated flowfiles to the next process. Do i need to rewrite them like

session.write(flowfile).

I am not a python programmer so please be kind and supply small example

Thank you

1 ACCEPTED SOLUTION

avatar
Expert Contributor

I found that the replacetext processor could do this for me with a very little effort. So i did not use executeScript for this.

View solution in original post

4 REPLIES 4

avatar
@Simon Jespersen

Does the script have to be written using Python? There is a three part article written by @Matt Burgess that has some great examples: ExecuteScript Cookbook

avatar
Explorer

Hi,

Have you been able to make it work? Could you please share your script here?

Thanks

avatar
Expert Contributor

I found that the replacetext processor could do this for me with a very little effort. So i did not use executeScript for this.

avatar
Master Guru

Looks like it might just have been a typo between "flowFile" and "flowfile"