Package org.apache.druid.segment.data
Class CompressedBlockReader
java.lang.Object
org.apache.druid.segment.data.CompressedBlockReader
- All Implemented Interfaces:
Closeable,AutoCloseable
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 by
getRange(long, int). The ByteBuffer provided by this method may or may not
be valid after additional calls to getRange(long, int) or calls to seekBlock(int).
For fixed width values which are aligned with the block size, callers may also use the method
getDecompressedDataBuffer() to have direct access to the current uncompressed block, and use the methods
loadBlock(long) to load the correct block and translate a virtual offset into the relative offset, or
seekBlock(int) to change which block is currently loaded.
getRange(long, int) uses these same mechanisms internally to supply data.- See Also:
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionCompressedBlockReader(CompressionStrategy compressionStrategy, int numBlocks, int blockSize, boolean copyValuesOnRead, IntBuffer endOffsetsBuffer, ByteBuffer compressedDataBuffer, ByteOrder compressionByteOrder, ByteOrder valueByteOrder) -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()static Supplier<CompressedBlockReader>fromByteBuffer(ByteBuffer buffer, ByteOrder compressionOrder, ByteOrder valueOrder, boolean copyValuesOnRead) intGet current block number of data loaded indecompressedDataBufferCurrent decompressed data buffer of the data located incurrentBlockNumbergetRange(long startOffset, int size) GetByteBuffercontaining data from starting offset of contiguous virtual address range of the specified size.longgetSize()Get size in bytes of virtual contiguous bufferintloadBlock(long startOffset) Load the block for the specified virtual offset, returning the relative offset intodecompressedDataBufferof thecurrentBlockNumber.voidseekBlock(int block) Swap the current data indecompressedDataBufferto the specified block
-
Field Details
-
VERSION
public static final byte VERSION- See Also:
-
-
Constructor Details
-
CompressedBlockReader
public CompressedBlockReader(CompressionStrategy compressionStrategy, int numBlocks, int blockSize, boolean copyValuesOnRead, IntBuffer endOffsetsBuffer, ByteBuffer compressedDataBuffer, ByteOrder compressionByteOrder, ByteOrder valueByteOrder)
-
-
Method Details
-
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
Current decompressed data buffer of the data located incurrentBlockNumber -
getRange
GetByteBuffercontaining 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 intodecompressedDataBufferof thecurrentBlockNumber. -
seekBlock
public void seekBlock(int block) Swap the current data indecompressedDataBufferto the specified block -
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-