Skip to content

Commit

Permalink
NiFi: updated flowfile->attr script.
Browse files Browse the repository at this point in the history
  • Loading branch information
vladd-bit committed Dec 1, 2023
1 parent 93f8b77 commit 10788ba
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions nifi/user-scripts/flowfile_to_attribute_with_content.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import traceback
import io
import json
import avro
import copy

# jython packages
Expand Down Expand Up @@ -57,14 +56,14 @@ def process(self, inputStream, outputStream):
for record in records:
metadata = copy.deepcopy(records.meta)
schema_from_file = json.loads(metadata["avro.schema"])

#with open("/opt/nifi/user-scripts/tmp/test_schmea.avsc", "w+") as f:
# f.write(str(record))

new_flow_file = session.create(flowFile)

new_flow_file = session.putAttribute(new_flow_file, "attribute_list", str(list(record.keys())))
new_flow_file = session.putAttribute(new_flow_file, "avro_schema", json.dumps(schema_from_file))

for k, v in record.iteritems():
new_flow_file = session.putAttribute(new_flow_file, k, str(v))
if k != FIELD_NAMES_TO_KEEP_AS_CONTENT:
new_flow_file = session.putAttribute(new_flow_file, k, str(v))
if FIELD_NAMES_TO_KEEP_AS_CONTENT is not "" and k == FIELD_NAMES_TO_KEEP_AS_CONTENT:
new_flow_file = session.write(new_flow_file, WriteContentCallback(str(v).encode("UTF-8")))
output_flowFiles.append(new_flow_file)
Expand Down

0 comments on commit 10788ba

Please sign in to comment.