Package org.apache.druid.segment.data
Class CompressedBlockReader
- java.lang.Object
-
- org.apache.druid.segment.data.CompressedBlockReader
-
- All Implemented Interfaces:
Closeable
,AutoCloseable
public final class CompressedBlockReader extends Object implements Closeable
Reader for a virtual contiguous address range backed by compressed blocks of data. Format: | version (byte) | compression (byte) | block size (int) | num blocks (int) | end offsets | compressed data | This mechanism supports two modes of use, the first where callers may ask for a range of data from the underlying blocks, provided bygetRange(long, int)
. TheByteBuffer
provided by this method may or may not be valid after additional calls togetRange(long, int)
or calls toseekBlock(int)
. For fixed width values which are aligned with the block size, callers may also use the methodgetDecompressedDataBuffer()
to have direct access to the current uncompressed block, and use the methodsloadBlock(long)
to load the correct block and translate a virtual offset into the relative offset, orseekBlock(int)
to change which block is currently loaded.getRange(long, int)
uses these same mechanisms internally to supply data.- See Also:
for writer
-
-
Field Summary
Fields Modifier and Type Field Description static byte
VERSION
-
Constructor Summary
Constructors Constructor Description CompressedBlockReader(CompressionStrategy compressionStrategy, int numBlocks, int blockSize, boolean copyValuesOnRead, IntBuffer endOffsetsBuffer, ByteBuffer compressedDataBuffer, ByteOrder compressionByteOrder, ByteOrder valueByteOrder)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
static Supplier<CompressedBlockReader>
fromByteBuffer(ByteBuffer buffer, ByteOrder compressionOrder, ByteOrder valueOrder, boolean copyValuesOnRead)
int
getCurrentBlockNumber()
Get current block number of data loaded indecompressedDataBuffer
ByteBuffer
getDecompressedDataBuffer()
Current decompressed data buffer of the data located incurrentBlockNumber
ByteBuffer
getRange(long startOffset, int size)
GetByteBuffer
containing data from starting offset of contiguous virtual address range of the specified size.long
getSize()
Get size in bytes of virtual contiguous bufferint
loadBlock(long startOffset)
Load the block for the specified virtual offset, returning the relative offset intodecompressedDataBuffer
of thecurrentBlockNumber
.void
seekBlock(int block)
Swap the current data indecompressedDataBuffer
to the specified block
-
-
-
Field Detail
-
VERSION
public static final byte VERSION
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
CompressedBlockReader
public CompressedBlockReader(CompressionStrategy compressionStrategy, int numBlocks, int blockSize, boolean copyValuesOnRead, IntBuffer endOffsetsBuffer, ByteBuffer compressedDataBuffer, ByteOrder compressionByteOrder, ByteOrder valueByteOrder)
-
-
Method Detail
-
fromByteBuffer
public static Supplier<CompressedBlockReader> fromByteBuffer(ByteBuffer buffer, ByteOrder compressionOrder, ByteOrder valueOrder, boolean copyValuesOnRead)
-
getSize
public long getSize()
Get size in bytes of virtual contiguous buffer
-
getCurrentBlockNumber
public int getCurrentBlockNumber()
Get current block number of data loaded indecompressedDataBuffer
-
getDecompressedDataBuffer
public ByteBuffer getDecompressedDataBuffer()
Current decompressed data buffer of the data located incurrentBlockNumber
-
getRange
public ByteBuffer getRange(long startOffset, int size)
GetByteBuffer
containing data from starting offset of contiguous virtual address range of the specified size. If this data spans more than a single block, it will be copied on heap, but if not, will be a view intodecompressedDataBuffer
. The data returned by this method is not guaranteed to still be readable after another call togetRange(long, int)
or a call toseekBlock(int)
.
-
loadBlock
public int loadBlock(long startOffset)
Load the block for the specified virtual offset, returning the relative offset intodecompressedDataBuffer
of thecurrentBlockNumber
.
-
seekBlock
public void seekBlock(int block)
Swap the current data indecompressedDataBuffer
to the specified block
-
close
public void close() throws IOException
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
-
-