About FlowFileTransformResult
Class
nifiapi.flowfiletransform.FlowFileTransformResult
The FlowFileTransformResult
class provides an interface for extending and modifying attributes and content of a FlowFile, as well as define the outgoing relationship.
Parameters
Name | Type | Description |
---|---|---|
relationship | String | Name of the relationship the FlowFile should be routed to |
attributes | Dictionary; Default None | A key-value pairs representing modified FlowFile attributes |
contents | Byte Array or String; Default None | Content of the FlowFile |
e.g:
return FlowFileTransformResult(
'success',
attributes={},
contents=None
)
Modifying FlowFile attributes
The FlowFileTransformResult
provides an interface to add or modify existing FlowFile attributes.
important
Note that all attributes must be represented as strings.
from nifiapi.flowfiletransform import (
FlowFileTransform,
FlowFileTransformResult,
)
from nifiapi.properties import ProcessContext
class Processor(FlowFileTransform):
(...)
def transform(
self, context: ProcessContext, flow_file
) -> FlowFileTransformResult:
'''
Parameters:
context (ProcessContext)
flow_file
Returns:
FlowFileTransformResult
'''
return FlowFileTransformResult('success', attributes={
"new_attribute": str(1234)
})
Modifying FlowFile content
You can modify the contents of a FlowFile through the FlowFileTransformResult
. Simply pass a new value in the contents
parameter:
important
Note that the new content must be either a Byte Array or String type.
from nifiapi.flowfiletransform import (
FlowFileTransform,
FlowFileTransformResult,
)
from nifiapi.properties import ProcessContext
class Processor(FlowFileTransform):
(...)
def transform(
self, context: ProcessContext, flow_file
) -> FlowFileTransformResult:
'''
Parameters:
context (ProcessContext)
flow_file
Returns:
FlowFileTransformResult
'''
return FlowFileTransformResult('success', contents="New content")