K - key typeV - value typeR - KeyValue return type (both key and value type can be set
arbitrarily)@InterfaceStability.Unstable
public interface Transformer<K,V,R>
Transformer interface 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 of
transform(Object, Object) (cf. KeyValueMapper for stateless record transformation).
Additionally, the interface can be called in regular intervals based on the processing progress
(cf. punctuate(long).
Use TransformerSupplier to provide new instances of Transformer to Kafka Stream's runtime.
If only a record's value should be modified ValueTransformer can be used.
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Close this processor and clean up any resources.
|
void |
init(ProcessorContext context)
Initialize this transformer.
|
R |
punctuate(long timestamp)
Perform any periodic operations and possibly generate new
KeyValue pairs if this processor
schedules itself with the context during
initialization. |
R |
transform(K key,
V value)
Transform the record with the given key and value.
|
void init(ProcessorContext context)
The provided context can be used to access topology and record meta data, to
schedule itself for periodical calls (cf. punctuate(long)), and
to access attached StateStores.
Note, that ProcessorContext is updated in the background with the current record's meta data.
Thus, it only contains valid record meta data when accessed within transform(Object, Object).
context - the contextR transform(K key, V value)
state that is attached to 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), and
ProcessorContext.forward(Object, Object, String) can be used.
If not record should be forwarded downstream, transform can return null.
key - the key for the recordvalue - the value for the recordKeyValue pair—if null no key-value pair will
be forwarded to down streamR punctuate(long timestamp)
KeyValue pairs if this processor
schedules itself with the context during
initialization.
To generate new KeyValue pairs ProcessorContext.forward(Object, Object),
ProcessorContext.forward(Object, Object, int), and
ProcessorContext.forward(Object, Object, String) can be used.
Note that punctuate is called based on TimestampExtractor)
and not based on wall-clock time.
timestamp - the stream time when punctuate is being callednull—otherwise, a exception will be thrownvoid close()
To generate new KeyValue pairs ProcessorContext.forward(Object, Object),
ProcessorContext.forward(Object, Object, int), and
ProcessorContext.forward(Object, Object, String) can be used.