Reputation: 406
i am planning to write python code in executescript processor. As this is my first time, i am finding difficult to start.
basically, i want to read flowfile (csv) and do some manipulation and write it to flowfile.
is there a way where we can write the code beforehand, say suppose jupyter and then replicate the same in the processor?
also, is there any syntax documentation for writing the code?
EXECUTESTREAMCOMMAND:
import org.apache.commons.io.IOUtils
import java.io
import csv
# Get flowFile Session
flowFile = session.get()
# Open data.json file and parse json values
readFile = csv.reader(sys.stdin)
for row in readFile:
new_value = row[0]
if (flowFile != None):
flowFile = session.putAttribute(flowFile, "from_python_string", "python string example")
flowFile = session.putAttribute(flowFile, "from_python_number", str(new_value))
session.transfer(flowFile, REL_SUCCESS)
session.commit()
Command Arguments: C:\Users\Desktop\samp1.py
Command Path: C:\Users\AppData\Local\Programs\Python\Python37-32\python
when i execute it, it throws error on the import statement saying no module found.
tia
Upvotes: 0
Views: 1288
Reputation: 14194
Matt Burgess wrote a script tester tool which can accept a Jython script and test it. Not quite the interactive environment you're looking for, but probably as close as exists out of the box.
The code you write when using ExecuteScript
and ExecuteStreamCommand
will be very different; the core logic may be the same, but the way your code accesses and generates flowfile attributes and content will differ because when run outside of the NiFi runtime, Python has no awareness of the NiFi-specific features. See this answer for more details on how to write for ExecuteStreamCommand
and this answer for ExecuteScript
.
Upvotes: 1