Class FileSourceSplit
- All Implemented Interfaces:
Serializable,org.apache.flink.api.connector.source.SourceSplit
SourceSplit that represents a file, or a region of a file.
The split has an offset and an end, which defines the region of the file represented by the split. For splits representing the while file, the offset is zero and the length is the file size.
The split may furthermore have a "reader position", which is the checkpointed position from a reader previously reading this split. This position is typically null when the split is assigned from the enumerator to the readers, and is non-null when the readers checkpoint their state in a file source split.
This class is Serializable for convenience. For Flink's internal serialization (both
for RPC and for checkpoints), the FileSourceSplitSerializer is used.
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionFileSourceSplit(String id, org.apache.flink.core.fs.Path filePath, long offset, long length, long fileModificationTime, long fileSize) Constructs a split with host information.FileSourceSplit(String id, org.apache.flink.core.fs.Path filePath, long offset, long length, long fileModificationTime, long fileSize, String... hostnames) Constructs a split with host information.FileSourceSplit(String id, org.apache.flink.core.fs.Path filePath, long offset, long length, long fileModificationTime, long fileSize, String[] hostnames, CheckpointedPosition readerPosition) Constructs a split with host information. -
Method Summary
Modifier and TypeMethodDescriptionlongReturns the modification time of the file, fromFileStatus.getModificationTime().longfileSize()Returns the full file size in bytes, fromFileStatus.getLen().Gets the (checkpointed) position of the reader, if set.String[]Gets the hostnames of the nodes storing the file range described by this split.longlength()Returns the number of bytes in the file region described by this source split.longoffset()Returns the start of the file region referenced by this source split.org.apache.flink.core.fs.Pathpath()Gets the file's path.splitId()toString()Creates a copy of this split where the checkpointed position is replaced by the given new position.
-
Constructor Details
-
FileSourceSplit
public FileSourceSplit(String id, org.apache.flink.core.fs.Path filePath, long offset, long length, long fileModificationTime, long fileSize) Constructs a split with host information.- Parameters:
id- The unique ID of this source split.filePath- The path to the file.offset- The start (inclusive) of the split's rage in the file.length- The number of bytes in the split (starting from the offset)fileModificationTime- The modification time of the filefileSize- The size of the full file
-
FileSourceSplit
public FileSourceSplit(String id, org.apache.flink.core.fs.Path filePath, long offset, long length, long fileModificationTime, long fileSize, String... hostnames) Constructs a split with host information.- Parameters:
filePath- The path to the file.offset- The start (inclusive) of the split's rage in the file.length- The number of bytes in the split (starting from the offset)fileModificationTime- The modification time of the filefileSize- The size of the full filehostnames- The hostnames of the nodes storing the split's file range.
-
FileSourceSplit
public FileSourceSplit(String id, org.apache.flink.core.fs.Path filePath, long offset, long length, long fileModificationTime, long fileSize, String[] hostnames, @Nullable CheckpointedPosition readerPosition) Constructs a split with host information.- Parameters:
filePath- The path to the file.offset- The start (inclusive) of the split's rage in the file.length- The number of bytes in the split (starting from the offset)fileModificationTime- The modification time of the filefileSize- The size of the full filehostnames- The hostnames of the nodes storing the split's file range.
-
-
Method Details
-
splitId
- Specified by:
splitIdin interfaceorg.apache.flink.api.connector.source.SourceSplit
-
path
public org.apache.flink.core.fs.Path path()Gets the file's path. -
offset
public long offset()Returns the start of the file region referenced by this source split. The position is inclusive, the value indicates the first byte that is part of the split. -
length
public long length()Returns the number of bytes in the file region described by this source split. -
fileModificationTime
public long fileModificationTime()Returns the modification time of the file, fromFileStatus.getModificationTime(). -
fileSize
public long fileSize()Returns the full file size in bytes, fromFileStatus.getLen(). -
hostnames
Gets the hostnames of the nodes storing the file range described by this split. The returned array is empty, if no host information is available.Host information is typically only available on specific file systems, like HDFS.
-
getReaderPosition
Gets the (checkpointed) position of the reader, if set. This value is typically absent for splits when assigned from the enumerator to the readers, and present when the splits are recovered from a checkpoint. -
updateWithCheckpointedPosition
Creates a copy of this split where the checkpointed position is replaced by the given new position.IMPORTANT: Subclasses that add additional information to the split must override this method to return that subclass type. This contract is enforced by checks in the file source implementation. We did not try to enforce this contract via generics in this split class, because it leads to very ugly and verbose use of generics.
-
toString
-