Implementation:Apache Flink RecordEmitter
| Knowledge Sources | |
|---|---|
| Domains | Connectors, Source_Framework |
| Last Updated | 2026-02-09 00:00 GMT |
Overview
A functional interface that defines how raw records from a split reader are processed, transformed, and emitted downstream to a SourceOutput.
Description
RecordEmitter is a core interface in Flink's source connector base framework. It acts as the bridge between the raw record type (E) read by a SplitReader and the final output type (T) that is emitted to the downstream Flink pipeline via a SourceOutput. The interface is parameterized with three type parameters: the raw element type from the SplitReader, the final emitted record type, and the mutable split state type. During record emission, the implementor has access to the split state, which enables updating checkpoint-relevant information such as offsets or positions as records are processed. The interface is annotated with @PublicEvolving, indicating it is part of Flink's public API but may evolve across minor versions.
Usage
Connector developers implement this interface when building a new source connector based on the SourceReaderBase framework. The RecordEmitter is typically responsible for three things: (1) deserializing or transforming the raw record into its final form, (2) updating the mutable split state with checkpoint information (e.g., Kafka offsets, file positions), and (3) emitting the transformed record to the SourceOutput. For example, a Kafka connector implementation would take a ConsumerRecord, extract offset information into the split state, apply the user's deserialization schema, and emit the resulting record.
Code Reference
Source Location
- Repository: Apache_Flink
- File: flink-connectors/flink-connector-base/src/main/java/org/apache/flink/connector/base/source/reader/RecordEmitter.java
- Lines: 1-52
Signature
@PublicEvolving
public interface RecordEmitter<E, T, SplitStateT> {
/**
* Process and emit the records to the SourceOutput.
*
* @param element The intermediate element read by the SplitReader.
* @param output The output to which the final records are emit to.
* @param splitState The state of the split.
*/
void emitRecord(E element, SourceOutput<T> output, SplitStateT splitState) throws Exception;
}
Import
import org.apache.flink.connector.base.source.reader.RecordEmitter;
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| element | E | Yes | The raw intermediate element read by the SplitReader from the external source system. |
| output | SourceOutput<T> | Yes | The output collector to which transformed final records are emitted for downstream processing. |
| splitState | SplitStateT | Yes | The mutable state of the split, used to track checkpoint-relevant information such as offsets or positions. |
Outputs
| Name | Type | Description |
|---|---|---|
| (side effect) | void | Records are emitted to the provided SourceOutput. Split state is mutated in place with updated checkpoint information. |
Usage Examples
// Example: A simple RecordEmitter that converts a raw String record
// to a Long value and updates the split state offset.
public class MyRecordEmitter
implements RecordEmitter<String, Long, MySplitState> {
@Override
public void emitRecord(
String element,
SourceOutput<Long> output,
MySplitState splitState) throws Exception {
// Parse the raw record into the final type
long value = Long.parseLong(element);
// Emit the record with an event timestamp
output.collect(value, System.currentTimeMillis());
// Update the mutable split state for checkpointing
splitState.setCurrentOffset(splitState.getCurrentOffset() + 1);
}
}