ChDriver.Types (ch_driver v0.1.0)

Copy Markdown

Parses ClickHouse's column type strings (e.g. "Nullable(String)", "Map(String, Decimal(10, 2))") into their component parts. Pure string parsing only -- no wire decoding happens here; see ChDriver.Types.Registry for the scalar codec table and ChDriver.Protocol.Block.Wrappers / ChDriver.Protocol.Block.Sparse for how these parsed types drive decoding of wrapper/compound column data.

Every wrapper/compound type ClickHouse's Native block format can send that this driver understands is recognized here:

Tuple(...) is not supported in its own right -- only as Map(K, V)'s implicit internal representation, not as a directly-selectable column type (see ChDriver.Protocol.Block.Wrappers's decode_map/4 moduledoc for why generalizing it is more work than it looks).

Summary

Functions

Parses ClickHouse's Array(T) wrapper syntax, returning the inner type string.

Parses Decimal(P, S) and the Decimal32(S)/Decimal64(S)/ Decimal128(S)/Decimal256(S) fixed-precision aliases, returning {:ok, precision, scale}.

Parses ClickHouse's FixedString(N) type, returning {:ok, n}.

Parses ClickHouse's LowCardinality(T) wrapper syntax, returning the inner type string.

Parses ClickHouse's Map(K, V) wrapper syntax, returning {:ok, key_type, value_type}. Splits on the top-level comma only (tracking paren depth so e.g. Map(String, Decimal(10, 2)) isn't split on the inner comma).

Parses ClickHouse's Nullable(T) wrapper syntax, returning the inner type string.

Splits inner on its top-level comma(s) only, tracking paren depth so a parameterized inner type's own comma (e.g. the Decimal(10, 2) inside Map(String, Decimal(10, 2))) is never mistaken for the wrapper's own separator. Returns the list of (untrimmed) parts, or :error if the parens are unbalanced.

Strips a Prefix(...) wrapper down to its inner contents, given the exact "Prefix(" (including the opening paren) to match against. Not a general parenthesis-balancer -- just strips the given prefix and the trailing ) -- but that's sufficient even for a parameterized inner type like Nullable(DateTime(3)), since the outer ) is always the last byte of the whole type string.

Functions

parse_array(type)

Parses ClickHouse's Array(T) wrapper syntax, returning the inner type string.

parse_decimal(arg1)

Parses Decimal(P, S) and the Decimal32(S)/Decimal64(S)/ Decimal128(S)/Decimal256(S) fixed-precision aliases, returning {:ok, precision, scale}.

parse_fixed_string(arg1)

Parses ClickHouse's FixedString(N) type, returning {:ok, n}.

parse_low_cardinality(type)

Parses ClickHouse's LowCardinality(T) wrapper syntax, returning the inner type string.

parse_map(type)

Parses ClickHouse's Map(K, V) wrapper syntax, returning {:ok, key_type, value_type}. Splits on the top-level comma only (tracking paren depth so e.g. Map(String, Decimal(10, 2)) isn't split on the inner comma).

parse_nullable(type)

Parses ClickHouse's Nullable(T) wrapper syntax, returning the inner type string.

split_top_level_comma(inner)

Splits inner on its top-level comma(s) only, tracking paren depth so a parameterized inner type's own comma (e.g. the Decimal(10, 2) inside Map(String, Decimal(10, 2))) is never mistaken for the wrapper's own separator. Returns the list of (untrimmed) parts, or :error if the parens are unbalanced.

strip_wrapper(type, prefix)

Strips a Prefix(...) wrapper down to its inner contents, given the exact "Prefix(" (including the opening paren) to match against. Not a general parenthesis-balancer -- just strips the given prefix and the trailing ) -- but that's sufficient even for a parameterized inner type like Nullable(DateTime(3)), since the outer ) is always the last byte of the whole type string.