ChDriver.Protocol.NativeBlock (ch_driver v0.1.1)

Copy Markdown

Decodes ClickHouse's "Native" block format — the columns and rows of a query result, once any compression envelope has been stripped away.

This is internal to the driver's decoding pipeline. A block carries its column names, types, and row data; decode_block/1 turns that into %{columns: [{name, type}], rows: [[term]]}.

Only a pragmatic subset of ClickHouse's type system is supported — see ChDriver.Types.Registry for the scalar types and ChDriver.Protocol.Block.Wrappers for compound types like Array, Map, and Nullable. If you're adding support for a new ClickHouse type, ARCHITECTURE.md has the map of which module owns what.

Summary

Functions

Decodes a Native block (everything after the external table name): BlockInfo, column count, row count, and each column's name/type/data.

Decodes a Data or ProfileEvents packet body: the external table name, followed by a Native block.

Functions

decode_block(binary)

@spec decode_block(binary()) ::
  {:ok, map(), binary()} | {:incomplete, binary()} | {:error, term()}

Decodes a Native block (everything after the external table name): BlockInfo, column count, row count, and each column's name/type/data.

Returns {:ok, %{columns: [{name, type}], rows: [[term]]}, rest}, {:incomplete, binary}, or {:error, reason}.

decode_data_packet(binary, compression \\ :none)

@spec decode_data_packet(binary(), ChDriver.Protocol.Block.Compressed.method()) ::
  {:ok, map(), binary()} | {:incomplete, binary()} | {:error, term()}

Decodes a Data or ProfileEvents packet body: the external table name, followed by a Native block.

compression (:none (default) or :lz4) must match whatever was negotiated for this query — when :lz4, the block is decompressed before decoding.

Returns {:ok, %{table_name:, columns:, rows:}, rest}, {:incomplete, binary}, or {:error, reason}.