public class CellWriter extends Object implements Serializer, Closeable
CellReader. Example usage:
StagedSerde<Fuu> fuuSerDe = new ...
// note that cellWriter.close() *must* be called before writeTo() in order to finalize the index
try (CellWriter cellWriter = new CellWriter.Builder(segmentWriteOutMedium).build()) {
fuuList.stream().map(fuuSerDe:serialize).forEach(cellWriter::write);
}
// at this point cellWriter contains the index and compressed data
// transfers the index and compressed data in the format specified below. This method is idempotent and copies
// the data each time.
cellWriter.writeTo(writableChannel, fileSmoosher); // 2nd argument currently unused, may be null
Note that for use with CellReader, the contents written to the writableChannel must be available as a ByteBuffer
serialized data is of the form:
[cell index]
[payload storage]
each of these items is stored in compressed streams of blocks with a block index.
A BlockCompressedPayloadWriter stores byte[] payloads. These may be accessed by creating a
BlockCompressedPayloadReader over the produced ByteBuffer. Reads may be done by giving a location in the
uncompressed stream and a size
NOTE: BlockCompressedPayloadBuffer does not store nulls on write(). However, the cellIndex stores an entry
with a size of 0 for nulls and CellReader will return null for any null written
[blockIndexSize:int]
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| block index
| compressed block # -> block start in compressed stream position (relative to data start)
|
| 0: [block position: int]
| 1: [block position: int]
| ...
| i: [block position: int]
| ...
| n: [block position: int]
| n+1: [total compressed size ] // stored to simplify invariant of n+1 - n = length(n)
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
[dataSize:int]
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| [compressed payload block 1]
| [compressed payload block 2]
| ...
| [compressed paylod block n]
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
the CellIndexWriter stores an array of longs using the BlockCompressedPayloadWriter
logically this an array of longs
| 0: start_0 : long
| 1: start_1 : long
| ...
| n: start_n : long
| n+1: start_n + length_n : long //ie, next position that would have been written to
| //used again for invariant of length_i = row_i+1 - row_i
|
| but this will be stored as block compressed. Reads are done by addressing it as a long array of bytes
|
| [block index size]
| [block index>
|
| [data stream size]
| [block compressed payload stream]
resulting in
| [cell index size]
| ----cell index------------------------
| [block index size]
| [block index]
| [data stream size]
| [block compressed payload stream]
| -------------------------------------
| [data stream size]
| ----data stream------------------------
| [block index size]
| [block index]
| [data stream size]
| [block compressed payload stream]
| -------------------------------------
| Modifier and Type | Class and Description |
|---|---|
static class |
CellWriter.Builder |
| Modifier and Type | Method and Description |
|---|---|
static CellWriter.Builder |
builder(SegmentWriteOutMedium segmentWriteOutMedium) |
void |
close() |
long |
getSerializedSize()
Returns the number of bytes, that this Serializer will write to the output _channel_ (not smoosher) on a
Serializer.writeTo(java.nio.channels.WritableByteChannel, org.apache.druid.java.util.common.io.smoosh.FileSmoosher) call. |
void |
write(byte[] cellBytes) |
void |
write(ByteBuffer cellByteBuffer) |
void |
writeTo(WritableByteChannel channel,
FileSmoosher smoosher)
Writes serialized form of this object to the given channel.
|
public void write(byte[] cellBytes)
throws IOException
IOExceptionpublic void write(ByteBuffer cellByteBuffer) throws IOException
IOExceptionpublic void writeTo(WritableByteChannel channel, @Nullable FileSmoosher smoosher) throws IOException
SerializerwriteTo in interface SerializerIOExceptionpublic void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableIOExceptionpublic long getSerializedSize()
SerializerSerializer.writeTo(java.nio.channels.WritableByteChannel, org.apache.druid.java.util.common.io.smoosh.FileSmoosher) call.getSerializedSize in interface Serializerpublic static CellWriter.Builder builder(SegmentWriteOutMedium segmentWriteOutMedium)
Copyright © 2011–2022 The Apache Software Foundation. All rights reserved.