public class FrontCodedIndexedWriter extends Object implements DictionaryWriter<byte[]>
DictionaryWriter for a FrontCodedIndexed, written to a SegmentWriteOutMedium. Values MUST
be added to this dictionary writer in sorted order, which is enforced.
Front coding is a type of delta encoding for byte arrays, where values are grouped into buckets. The first value of
the bucket is written entirely, and remaining values are stored as pairs of an integer which indicates how much
of the first byte array of the bucket to use as a prefix, followed by the remaining value bytes after the prefix.
This writer is designed for use with UTF-8 encoded strings that are written in an order compatible with
String.compareTo(String).for additional details.| Constructor and Description |
|---|
FrontCodedIndexedWriter(SegmentWriteOutMedium segmentWriteOutMedium,
ByteOrder byteOrder,
int bucketSize) |
| Modifier and Type | Method and Description |
|---|---|
byte[] |
get(int index) |
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. |
boolean |
isSorted() |
void |
open() |
void |
write(byte[] value) |
static int |
writeBucket(ByteBuffer buffer,
byte[][] values,
int numValues)
Write bucket of values to a
ByteBuffer. |
void |
writeTo(WritableByteChannel channel,
FileSmoosher smoosher)
Writes serialized form of this object to the given channel.
|
static int |
writeValue(ByteBuffer buffer,
byte[] bytes)
Write a variable length byte[] value to a
ByteBuffer, storing the length as a VByte encoded
integer followed by the value itself. |
public FrontCodedIndexedWriter(SegmentWriteOutMedium segmentWriteOutMedium, ByteOrder byteOrder, int bucketSize)
public void open()
throws IOException
open in interface DictionaryWriter<byte[]>IOExceptionpublic void write(@Nullable byte[] value) throws IOException
write in interface DictionaryWriter<byte[]>IOExceptionpublic long getSerializedSize()
throws IOException
SerializerSerializer.writeTo(java.nio.channels.WritableByteChannel, org.apache.druid.java.util.common.io.smoosh.FileSmoosher) call.getSerializedSize in interface SerializerIOExceptionpublic void writeTo(WritableByteChannel channel, FileSmoosher smoosher) throws IOException
SerializerwriteTo in interface SerializerIOExceptionpublic boolean isSorted()
isSorted in interface DictionaryWriter<byte[]>@Nullable public byte[] get(int index) throws IOException
get in interface DictionaryWriter<byte[]>IOExceptionpublic static int writeBucket(ByteBuffer buffer, byte[][] values, int numValues)
ByteBuffer. The first value is written completely, subsequent values are
written with an integer to indicate how much of the first value in the bucket is a prefix of the value, followed
by the remaining bytes of the value.
Uses VByte encoded integers to indicate prefix length and value length.public static int writeValue(ByteBuffer buffer, byte[] bytes)
ByteBuffer, storing the length as a VByte encoded
integer followed by the value itself. Returns the number of bytes written to the buffer. This method returns a
negative value if there is no room available in the buffer, so that it can be grown if needed.Copyright © 2011–2022 The Apache Software Foundation. All rights reserved.