Implementation:Apache Flink RecordEvaluator
| Knowledge Sources | |
|---|---|
| Domains | Connectors, Source_Framework |
| Last Updated | 2026-02-09 00:00 GMT |
Overview
A functional interface that evaluates whether a deserialized record should trigger end-of-stream for its split.
Description
RecordEvaluator is a @FunctionalInterface in Flink's source connector base framework that provides a mechanism to evaluate records and trigger control-flow operations such as signaling the end of a stream for a particular split. It extends Serializable, allowing it to be shipped across the cluster as part of the source configuration. The primary use case is to inspect each deserialized record and determine whether it represents a logical end-of-stream marker. When the evaluator returns true for a given record, that record is not emitted from the source, and the corresponding split is treated as finished. This interface is annotated with @PublicEvolving, meaning it is part of Flink's public API but subject to evolution across minor versions.
Usage
Connector developers use this interface when they need to define a dynamic stopping condition for a split based on the content of the records being read. This is particularly useful for bounded or semi-bounded sources where the end condition depends on record content rather than external metadata. For example, a connector might use a RecordEvaluator to stop reading from a Kafka partition once a record with a specific sentinel value is encountered, or to implement time-bounded reads that stop when records exceed a certain timestamp.
Code Reference
Source Location
- Repository: Apache_Flink
- File: flink-connectors/flink-connector-base/src/main/java/org/apache/flink/connector/base/source/reader/RecordEvaluator.java
- Lines: 1-41
Signature
@PublicEvolving
@FunctionalInterface
public interface RecordEvaluator<T> extends Serializable {
/**
* Determines whether a record should trigger the end of stream for its split.
* The given record wouldn't be emitted from the source if the returned result is true.
*
* @param record a de-serialized record from the split.
* @return a boolean indicating whether the split has reached end of stream.
*/
boolean isEndOfStream(T record);
}
Import
import org.apache.flink.connector.base.source.reader.RecordEvaluator;
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| record | T | Yes | A deserialized record from the split to be evaluated for an end-of-stream condition. |
Outputs
| Name | Type | Description |
|---|---|---|
| (return value) | boolean | Returns true if the record indicates end-of-stream for the split (the record will not be emitted); false otherwise. |
Usage Examples
// Example: A RecordEvaluator that stops reading a split when a
// record with a timestamp beyond a specified bound is encountered.
RecordEvaluator<MyRecord> evaluator = record -> {
// Stop reading once records exceed the upper bound timestamp
return record.getTimestamp() > upperBoundTimestamp;
};
// Pass the evaluator to a SourceReaderBase constructor
SingleThreadMultiplexSourceReaderBase<RawRecord, MyRecord, MySplit, MySplitState> reader =
new MySourceReader(
splitFetcherManager,
recordEmitter,
evaluator, // end-of-stream evaluator
config,
context);