Implementation:Apache Flink SplitsAddition
| Knowledge Sources | |
|---|---|
| Domains | Connectors, Table_API |
| Last Updated | 2026-02-09 00:00 GMT |
Overview
A concrete split change event representing the addition of new splits to a split reader.
Description
SplitsAddition is a concrete subclass of SplitsChange in the flink-connector-base module that represents the event of adding new source splits to a SplitReader. It is a simple generic class parameterized by SplitT, wrapping a list of splits that need to be assigned to the reader. The class is annotated with @PublicEvolving, indicating it is part of Flink's public but evolving API.
This class is used within Flink's SourceReaderBase split management pipeline. When the SplitEnumerator assigns new splits to a reader, the assignment is communicated to the SplitReader as a SplitsAddition event via the handleSplitsChanges() method. The class provides a toString() method for logging and debugging purposes.
Usage
Connector developers encounter this class when implementing SplitReader.handleSplitsChanges(). Inside that method, they check whether the incoming SplitsChange is an instance of SplitsAddition and, if so, register the new splits for reading. It can also be instantiated directly when testing split reader implementations.
Code Reference
Source Location
- Repository: Apache_Flink
- File: flink-connectors/flink-connector-base/src/main/java/org/apache/flink/connector/base/source/reader/splitreader/SplitsAddition.java
- Lines: 1-41
Signature
@PublicEvolving
public class SplitsAddition<SplitT> extends SplitsChange<SplitT>
Import
import org.apache.flink.connector.base.source.reader.splitreader.SplitsAddition;
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| splits | List<SplitT> | Yes | The list of splits to add to the reader. Passed via the constructor. |
Outputs
| Name | Type | Description |
|---|---|---|
| splits() | List<SplitT> | Returns an unmodifiable list of the splits to be added (inherited from SplitsChange). |
| toString() | String | Returns a formatted string representation: "SplitAddition:[<splits>]". |
Usage Examples
// Creating a SplitsAddition to assign new splits to a reader
List<MySourceSplit> newSplits = Arrays.asList(
new MySourceSplit("split-1", 0),
new MySourceSplit("split-2", 0)
);
SplitsAddition<MySourceSplit> addition = new SplitsAddition<>(newSplits);
// Handling splits changes inside a SplitReader implementation
@Override
public void handleSplitsChanges(SplitsChange<MySourceSplit> splitsChanges) {
if (splitsChanges instanceof SplitsAddition) {
// Register the newly assigned splits for reading
assignedSplits.addAll(splitsChanges.splits());
}
}
Related Pages
- Principle:Apache_Flink_Source_Connector_Framework
- Apache_Flink_SplitsChange - Parent abstract class
- Apache_Flink_SplitReader - Interface that consumes SplitsAddition events
- Apache_Flink_SplitsRemoval - Counterpart class for split removal