Implementation:Apache Flink SplitsChange
| Knowledge Sources | |
|---|---|
| Domains | Connectors, Table_API |
| Last Updated | 2026-02-09 00:00 GMT |
Overview
An abstract base class representing a change to the set of splits assigned to a split reader.
Description
SplitsChange is an abstract generic class in the flink-connector-base module that serves as the base type for all split change events dispatched to a SplitReader. It is parameterized by SplitT, the type of source split. The class holds an immutable list of splits and provides a single accessor method splits() that returns an unmodifiable view of that list.
This class is part of Flink's SourceReaderBase architecture, acting as the polymorphic message type for communicating split assignment changes. The two concrete subclasses are SplitsAddition (for assigning new splits) and SplitsRemoval (for removing splits). The class is annotated @PublicEvolving and uses package-private constructor visibility, meaning only classes within the same package can extend it.
Usage
Connector developers interact with SplitsChange primarily in the SplitReader.handleSplitsChanges() method, where they receive a SplitsChange instance and use instanceof checks to determine whether it is an addition or removal. The splits() method provides access to the affected splits.
Code Reference
Source Location
- Repository: Apache_Flink
- File: flink-connectors/flink-connector-base/src/main/java/org/apache/flink/connector/base/source/reader/splitreader/SplitsChange.java
- Lines: 1-41
Signature
@PublicEvolving
public abstract class SplitsChange<SplitT>
Import
import org.apache.flink.connector.base.source.reader.splitreader.SplitsChange;
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| splits | List<SplitT> | Yes | The list of splits involved in the change. Passed via the package-private constructor. |
Outputs
| Name | Type | Description |
|---|---|---|
| splits() | List<SplitT> | Returns an unmodifiable view of the splits involved in the change via Collections.unmodifiableList(). |
Usage Examples
// Handling SplitsChange in a SplitReader implementation
@Override
public void handleSplitsChanges(SplitsChange<MySourceSplit> splitsChanges) {
// Access the list of affected splits
List<MySourceSplit> affectedSplits = splitsChanges.splits();
if (splitsChanges instanceof SplitsAddition) {
// New splits have been assigned - register them for reading
for (MySourceSplit split : affectedSplits) {
registerSplit(split);
}
} else if (splitsChanges instanceof SplitsRemoval) {
// Splits have been removed - clean up resources
for (MySourceSplit split : affectedSplits) {
deregisterSplit(split);
}
}
}
Related Pages
- Principle:Apache_Flink_Source_Connector_Framework
- Apache_Flink_SplitsAddition - Concrete subclass for split additions
- Apache_Flink_SplitsRemoval - Concrete subclass for split removals
- Apache_Flink_SplitReader - Interface that consumes SplitsChange events