- Subscribe to RSS Feed
- Mark Question as New
- Mark Question as Read
- Float this Question for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page
NIFI Python filtering JSON
- Labels:
-
Apache NiFi
Created ‎03-17-2023 01:18 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I'm working on a custom Python script to execute inside 'ExecuteScript' processor in NIFI.
This processor receives input JSON flowfiles and only those that are present in variable filter inside script, should pass through. So the idea is filter JSON based on one column.
My current script looks like this:
import json
flowFile = session.get()
if flowFile is not None:
filter = ['1000007', '1000008']
json_content = json.loads(flowFile.read().decode('utf-8'))
if json_content['Customer_AccountID'] in patata:
filtered_content = json.dumps(json_content)
flowFile.write(bytearray(filtered_content, 'utf-8'))
session.transfer(flowFile, REL_SUCCESS)
else:
session.remove(flowFile)
session.transfer(flowFile, REL_FAILURE)
For now is not filtering anything, no output at all. Any idea why?
Created ‎03-17-2023 06:08 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@anton123 Please check these references, there is important information here that everyone needs to master in order to work with ExecuteScript:
https://community.hortonworks.com/articles/75032/executescript-cookbook-part-1.html
https://community.hortonworks.com/articles/75545/executescript-cookbook-part-2.html
https://community.hortonworks.com/articles/77739/executescript-cookbook-part-3.html
Some suggestions:
- Make sure you have all the imports you need
- Make sure you are using the correct variable names for "filter". You have this defined but its not used.
