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:
Nullable(T)-- decoded inChDriver.Protocol.Block.Wrappers, whose moduledoc documents the null-map wire format.Array(T)-- decoded inChDriver.Protocol.Block.Wrappers, whose moduledoc documents the offsets wire format.Map(K, V)-- decoded inChDriver.Protocol.Block.Wrappers. Parsing it here requires finding the top-level comma only (tracking paren depth viasplit_top_level_comma/1), so e.g.Map(String, Decimal(10, 2))isn't split on the inner comma.LowCardinality(T)-- decoded inChDriver.Protocol.Block.Wrappers.Decimal(P, S)and its fixed-precision aliasesDecimal32(S)/Decimal64(S)/Decimal128(S)/Decimal256(S)-- decoded inChDriver.Protocol.Block.Wrappers.FixedString(N)-- decoded via the genericChDriver.Types.Registry.decode_fixed_width/4with an identity unpack function (see the call site inChDriver.Protocol.NativeBlock'sdecode_column_data/3).
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
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.