Forked from ijokarumawak/read-flowfile-contents.py
Last active
February 1, 2017 13:14
-
-
Save ssummer3/311bc5b281efdbdbe14f2b29a03fa509 to your computer and use it in GitHub Desktop.
Example Python script to use from NiFi ExecuteScript processor which reads the first line from an incoming flow file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from org.python.core.util.FileUtil import wrap | |
from org.apache.nifi.processors.script import ExecuteScript | |
first_line = None | |
flow_file = session.get() | |
def read_first_line(input): | |
global first_line | |
with wrap(input) as f: | |
first_line = f.readline() | |
if flow_file: | |
session.read(flow_file, read_first_line) | |
if first_line: | |
flow_file = session.putAttribute(flow_file, 'from-content', first_line) | |
session.transfer(flow_file, ExecuteScript.REL_SUCCESS) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment