pub struct ColumnEncoder;Expand description
Unified column encoder that auto-selects the best encoding per column type.
Each encode_* method tries the specialised encoder for the column type
(delta-of-delta for timestamps, Chimp/Gorilla for floats, delta+ZigZag
for integers, dictionary for strings, bitmap for booleans) and
transparently falls back to PlainEncoder when
compression does not reach the minimum ratio threshold.
All methods return an EncodedBlock containing the encoding tag and
the raw payload. Nullable variants wrap a validity bitmap around the
inner encoded payload.
Implementations§
Source§impl ColumnEncoder
impl ColumnEncoder
Sourcepub fn encode_timestamps(values: &[i64]) -> Result<EncodedBlock>
pub fn encode_timestamps(values: &[i64]) -> Result<EncodedBlock>
Encode a timestamp column (sorted i64 nanoseconds).
Defaults to TimestampEncoding::Auto: pco leads, delta-of-delta is
tried as a second opinion, and the smaller block wins. See
encode_timestamps_with for why.
§Errors
Returns an error if the input is empty.
Sourcepub fn encode_timestamps_with(
values: &[i64],
strategy: TimestampEncoding,
) -> Result<EncodedBlock>
pub fn encode_timestamps_with( values: &[i64], strategy: TimestampEncoding, ) -> Result<EncodedBlock>
Encode a timestamp column with an explicit codec choice.
§Why pco leads
Delta-of-delta was the default here for as long as this crate has
existed, on the strength of its behaviour on a metronome: a perfectly
regular cadence makes every second difference zero and DoD reaches
~63× (and the raw codec, without the block tag, over 1000×). Real
gateways do not produce metronomes. A userspace sampler on a 1 s
cadence jitters by milliseconds, and DoD costs a varint for every
non-zero second difference — on ±5 ms jitter it reaches 0.9×,
i.e. it makes the column larger than storing the raw i64s.
pco entropy-codes the deltas against learned bins and reaches 2.7×
on the same data, which is within 2% of the Shannon bound for that
jitter (uniform over 10 ms of nanoseconds is 23.25 bits of genuine
information per sample; pco spends 23.7).
pco is not merely better on the ragged shapes — it wins on all four
measured shapes, including the metronome (1092× against DoD’s 63×),
so there is no shape for which DoD is kept as the default. It stays
selectable because a decoder for it must exist for as long as any
segment on disk contains a DoD block, and because a codec that can
be re-selected is a codec whose replacement can be measured.
tests/timestamp_codec_check.rs is the table.
Auto still trial-encodes both and keeps
the smaller: pco winning every shape we thought to measure is not the
same as pco winning every shape, and one extra encode of a column we
are already encoding is cheap insurance against a shape we did not
think of.
§Errors
Returns an error if the input is empty.
Sourcepub fn encode_f64(
values: &[f64],
strategy: FloatEncoding,
) -> Result<EncodedBlock>
pub fn encode_f64( values: &[f64], strategy: FloatEncoding, ) -> Result<EncodedBlock>
Encode a float column using the specified encoding strategy.
Uses sample-based adaptive selection to avoid wasting CPU on triple-encoding: analyzes the first 1024 values to pick the best encoder, then encodes the full column once.
§Errors
Returns an error if the input is empty.
Sourcepub fn encode_i64(values: &[i64]) -> Result<EncodedBlock>
pub fn encode_i64(values: &[i64]) -> Result<EncodedBlock>
Encode a signed integer column.
Tries RLE (constant), then both fixed-bit-width and varint delta encoding, picking the smallest result. Falls back to plain if neither specialised encoding achieves sufficient compression.
§Errors
Returns an error if the input is empty.
Sourcepub fn encode_u64(values: &[u64]) -> Result<EncodedBlock>
pub fn encode_u64(values: &[u64]) -> Result<EncodedBlock>
Encode an unsigned integer column.
Tries RLE (constant), then both fixed-bit-width and varint delta encoding, picking the smallest result. Falls back to plain if neither specialised encoding achieves sufficient compression.
§Errors
Returns an error if the input is empty.
Sourcepub fn encode_string(values: &[&str]) -> Result<EncodedBlock>
pub fn encode_string(values: &[&str]) -> Result<EncodedBlock>
Encode a string/tag column.
Uses dictionary encoding, falls back to plain if compression is poor or the dictionary overflows.
§Errors
Returns an error if the input is empty.
Sourcepub fn encode_bool(values: &[bool]) -> Result<EncodedBlock>
pub fn encode_bool(values: &[bool]) -> Result<EncodedBlock>
Encode a boolean column using 1-bit bitmap encoding.
Always uses bitmap encoding (1 bit per value is optimal).
§Errors
Returns an error if the input is empty.
Sourcepub fn encode_decimal(values: &[i128]) -> Result<EncodedBlock>
pub fn encode_decimal(values: &[i128]) -> Result<EncodedBlock>
Encode a column of decimal mantissas.
The scale is not encoded here: it belongs to the column, is stored once in the segment’s column metadata, and is the same for every value in the column by construction — the write path rescales each value to its column’s declared scale before it reaches the memtable. What is left is a column of integers, which is exactly what the integer codecs are best at.
§Errors
Returns an error if the input is empty.
Sourcepub fn encode_f64_nullable(
values: &[Option<f64>],
strategy: FloatEncoding,
) -> Result<EncodedBlock>
pub fn encode_f64_nullable( values: &[Option<f64>], strategy: FloatEncoding, ) -> Result<EncodedBlock>
Encode a nullable float column.
Separates non-null values, encodes them normally, then wraps with a validity bitmap so null positions are preserved on decode.
§Errors
Returns an error if all values are null (no data to encode) or the input is empty.
Sourcepub fn encode_i64_nullable(values: &[Option<i64>]) -> Result<EncodedBlock>
pub fn encode_i64_nullable(values: &[Option<i64>]) -> Result<EncodedBlock>
Sourcepub fn encode_u64_nullable(values: &[Option<u64>]) -> Result<EncodedBlock>
pub fn encode_u64_nullable(values: &[Option<u64>]) -> Result<EncodedBlock>
Sourcepub fn encode_string_nullable(values: &[Option<&str>]) -> Result<EncodedBlock>
pub fn encode_string_nullable(values: &[Option<&str>]) -> Result<EncodedBlock>
Sourcepub fn encode_decimal_nullable(values: &[Option<i128>]) -> Result<EncodedBlock>
pub fn encode_decimal_nullable(values: &[Option<i128>]) -> Result<EncodedBlock>
Sourcepub fn encode_bool_nullable(values: &[Option<bool>]) -> Result<EncodedBlock>
pub fn encode_bool_nullable(values: &[Option<bool>]) -> Result<EncodedBlock>
Trait Implementations§
Source§impl Clone for ColumnEncoder
impl Clone for ColumnEncoder
Source§fn clone(&self) -> ColumnEncoder
fn clone(&self) -> ColumnEncoder
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more