Interface Transformer<K,V,R>
-
- Type Parameters:
K- key typeV- value typeR-KeyValuereturn type (both key and value type can be set arbitrarily)
public interface Transformer<K,V,R>TheTransformerinterface is for stateful mapping of an input record to zero, one, or multiple new output records (both key and value type can be altered arbitrarily). This is a stateful record-by-record operation, i.e,transform(Object, Object)is invoked individually for each record of a stream and can access and modify a state that is available beyond a single call oftransform(Object, Object)(cf.KeyValueMapperfor stateless record transformation). Additionally, thisTransformercanschedulea method to becalled periodicallywith the provided context.Use
TransformerSupplierto provide new instances ofTransformerto Kafka Stream's runtime.If only a record's value should be modified
ValueTransformercan be used.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Deprecated Methods Modifier and Type Method Description voidclose()Close this processor and clean up any resources.voidinit(ProcessorContext context)Initialize this transformer.Rpunctuate(long timestamp)Deprecated.Please usePunctuatorfunctional interface instead.Rtransform(K key, V value)Transform the record with the given key and value.
-
-
-
Method Detail
-
init
void init(ProcessorContext context)
Initialize this transformer. This is called once per instance when the topology gets initialized.The provided
contextcan be used to access topology and record meta data, toschedulea method to becalled periodicallyand to access attachedStateStores.Note, that
ProcessorContextis updated in the background with the current record's meta data. Thus, it only contains valid record meta data when accessed withintransform(Object, Object).- Parameters:
context- the context
-
transform
R transform(K key, V value)
Transform the record with the given key and value. Additionally, anystatethat isattachedto this operator can be accessed and modified arbitrarily (cf.ProcessorContext.getStateStore(String)).If more than one output record should be forwarded downstream
ProcessorContext.forward(Object, Object),ProcessorContext.forward(Object, Object, int), andProcessorContext.forward(Object, Object, String)can be used. If not record should be forwarded downstream,transformcan returnnull.- Parameters:
key- the key for the recordvalue- the value for the record- Returns:
- new
KeyValuepair—ifnullno key-value pair will be forwarded to down stream
-
punctuate
@Deprecated R punctuate(long timestamp)
Deprecated.Please usePunctuatorfunctional interface instead.Perform any periodic operations and possibly generate newKeyValuepairs if this processorschedules itselfwith the context duringinitialization.To generate new
KeyValuepairsProcessorContext.forward(Object, Object),ProcessorContext.forward(Object, Object, int), andProcessorContext.forward(Object, Object, String)can be used.Note that
punctuateis called based onstream time (i.e., time progresses with regard to timestamps return by the usedTimestampExtractor) and not based on wall-clock time.- Parameters:
timestamp- the stream time whenpunctuateis being called- Returns:
- new
KeyValuepair to be forwarded to down stream—ifnullwill not be forwarded
-
close
void close()
Close this processor and clean up any resources.To generate new
KeyValuepairsProcessorContext.forward(Object, Object),ProcessorContext.forward(Object, Object, int), andProcessorContext.forward(Object, Object, String)can be used.
-
-