ChDriver. Protocol. Block. Sparse
(ch_driver v0.1.1)
Copy Markdown
Decodes ClickHouse's "sparse" column serialization.
ClickHouse automatically switches a MergeTree column to sparse storage
once most of its values equal the type's default, whether or not anyone
asked for it — so this driver needs to understand the format for any
query against a real table, not just an opt-in feature. See
ARCHITECTURE.md for the full wire format if you're modifying this.
Only inner types with a known default value are supported; anything else
surfaces as {:error, {:unsupported_sparse_default, type}}.
Summary
Functions
Decodes a sparse-serialized column of inner_type with num_rows rows
from the front of binary.
Reads the SparseOffsets varint stream from the front of binary.
Rebuilds the full num_rows-length column from offsets (ascending
0-indexed positions of non-default rows) and values (the
correspondingly-ordered decoded non-default values), filling every
other position with default.
Functions
Decodes a sparse-serialized column of inner_type with num_rows rows
from the front of binary.
Returns {:ok, values, rest}, {:error, reason}, or {:incomplete, binary}.
Reads the SparseOffsets varint stream from the front of binary.
Returns {:ok, offsets, rest} where offsets is the 0-indexed row
position of every non-default value, in ascending order, or
{:incomplete, binary}.
Rebuilds the full num_rows-length column from offsets (ascending
0-indexed positions of non-default rows) and values (the
correspondingly-ordered decoded non-default values), filling every
other position with default.