RecordTransformResult
Class
nifiapi.recordtransform.RecordTransformResult
Parameters
Name | Type | Description |
---|---|---|
relationship | String; Default 'success' | Name of the relationship the FlowFile should be routed to |
record | Dictionary | A JSON-serializable dictionary representing the transformed record. |
schema | RecordSchema ; Default None | An instance of Java class implementing the org.apache.nifi.serialization.record.RecordSchema interface |
partition | Map<String, Object> | An instance of HashMap<partition-name, transformed-record> |
partition
The partition
parameter is used to define how records are grouped when writing to an output destination. This parameter allows users to specify a partitioning strategy, such as by a specific field or set of fields, which can help organize data into separate files based on the partitioning criteria.
info
Note that the expected value of the partition
parameter is an instance of a Java HashMap.
e.g.:
from nifiapi.__jvm__ import JvmHolder
from nifiapi.recordtransform import (
RecordTransform,
RecordTransformResult
)
from nifiapi.properties import ProcessContext
from random import randint
class Processor(RecordTransform):
(...)
def __init__(self, *args, **kwargs):
super().__init__()
self.hash_map = JvmHolder.jvm.java.util.HashMap
def transform(
self, context: ProcessContext, record, schema, attribute_map
) -> RecordTransformResult:
'''
The following example will randomly partition incoming records
into two sets: 'partition-0' and 'partition-1'.
Parameters:
context (ProcessContext)
record (Mixed)
schema (org.apache.nifi.serialization.record.RecordSchema)
attribute_map (CachingAttributeMap)
Returns:
RecordTransformResult
'''
partition = self.hash_map()
n = randint(0, 1)
# Add a partitioning criterion 'random'
partition["random"] = f"partition-{n}"
return RecordTransformResult(
relationship="success",
record=record,
partition=partition
)