Skip to main content

ColumnEncoder

Struct ColumnEncoder 

Source
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

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn encode_i64_nullable(values: &[Option<i64>]) -> Result<EncodedBlock>

Encode a nullable signed integer column.

§Errors

Returns an error if the input is empty.

Source

pub fn encode_u64_nullable(values: &[Option<u64>]) -> Result<EncodedBlock>

Encode a nullable unsigned integer column.

§Errors

Returns an error if the input is empty.

Source

pub fn encode_string_nullable(values: &[Option<&str>]) -> Result<EncodedBlock>

Encode a nullable string column.

§Errors

Returns an error if the input is empty.

Source

pub fn encode_decimal_nullable(values: &[Option<i128>]) -> Result<EncodedBlock>

Encode a nullable decimal column.

§Errors

Returns an error if the input is empty.

Source

pub fn encode_bool_nullable(values: &[Option<bool>]) -> Result<EncodedBlock>

Encode a nullable boolean column.

§Errors

Returns an error if the input is empty.

Trait Implementations§

Source§

impl Clone for ColumnEncoder

Source§

fn clone(&self) -> ColumnEncoder

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for ColumnEncoder

Source§

impl Debug for ColumnEncoder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more