@Experimental(value=SOURCE_SINK) protected abstract static class BlockBasedSource.BlockBasedReader<T> extends FileBasedSource.FileBasedReader<T>
Readerthat reads records from a
BlockBasedSource. If the source is a subrange of a file, the blocks that will be read by this reader are those such that the first byte of the block is within the range
|Modifier||Constructor and Description|
|Modifier and Type||Method and Description|
Returns the value of the data item that was read by the last
Returns the current block (the block that was read by the last successful call to
Returns the largest offset such that starting to read from that offset includes the current block.
Returns the size of the current block in bytes as it is represented in the underlying file, if possible.
Returns the starting offset of the
Returns a value in [0, 1] representing approximately what fraction of the
Returns true if the reader is at a split point.
Read the next block from the input.
Reads the next record from the
advanceImpl, allowsDynamicSplitting, close, getCurrentSource, startImpl, startReading
advance, getSplitPointsConsumed, getSplitPointsRemaining, isDone, isStarted, splitAtFraction, start
protected BlockBasedReader(BlockBasedSource<T> source)
public abstract boolean readNextBlock() throws java.io.IOException
@Nullable public abstract BlockBasedSource.Block<T> getCurrentBlock()
readNextBlock()). May return null initially, or if no block has been successfully read.
public abstract long getCurrentBlockSize()
0if the size of the current block is unknown.
The size returned by this method must be such that for two successive blocks A and B,
offset(A) + size(A) <= offset(B). If this is not satisfied, the progress reported by
BlockBasedReader will be non-monotonic and will interfere with the quality (but
not correctness) of dynamic work rebalancing.
This method and
BlockBasedSource.Block.getFractionOfBlockConsumed() are used to provide an estimate
of progress within a block (
getCurrentBlockSize()). It is acceptable for the result of this computation to be
but progress estimation will be inaccurate.
public abstract long getCurrentBlockOffset()
public final T getCurrent() throws java.util.NoSuchElementException
Source.Reader.advance()call. The returned value must be effectively immutable and remain valid indefinitely.
Multiple calls to this method without an intervening call to
return the same result.
Source.Reader.start()was never called, or if the last
protected boolean isAtSplitPoint()
BlockBasedReaderis at a split point if the current record is the first record in a block. In other words, split points are block boundaries.
protected final boolean readNextRecord() throws java.io.IOException
current blockif possible. Will call
readNextBlock()to advance to the next block if not.
The first record read from a block is treated as a split point.
trueif a record was successfully read,
falseif the end of the channel was reached before successfully reading a new record.
@Nullable public java.lang.Double getFractionConsumed()
current sourcethis reader has read so far, or
nullif such an estimate is not available.
It is recommended that this method should satisfy the following properties:
Source.Reader.advance()call that returns false.
By default, returns null to indicate that this cannot be estimated.
BoundedSource.BoundedReader.splitAtFraction(double)is implemented, this method can be called concurrently to other methods (including itself), and it is therefore critical for it to be implemented in a thread-safe way.
protected long getCurrentOffset()
current record, which has been read by the last successful
If no such call has been made yet, the return value is unspecified.
RangeTracker for description of offset semantics.