Huginn.Clickhouse.Result (Huginn v0.4.0)

View Source

Parses and transforms ClickHouse gRPC Result messages.

Summary

Functions

Converts a gRPC Result message to a Huginn.Clickhouse.Result struct.

Merges multiple results from streaming responses.

Parses raw output bytes based on format.

Converts rows to a list of maps using column names as keys.

Types

column()

@type column() :: %{name: String.t(), type: String.t()}

log_entry()

@type log_entry() :: %{
  time: non_neg_integer(),
  level: atom(),
  source: String.t(),
  text: String.t()
}

progress()

@type progress() :: %{
  read_rows: non_neg_integer(),
  read_bytes: non_neg_integer(),
  total_rows_to_read: non_neg_integer(),
  written_rows: non_neg_integer(),
  written_bytes: non_neg_integer()
}

stats()

@type stats() :: %{
  rows: non_neg_integer(),
  blocks: non_neg_integer(),
  allocated_bytes: non_neg_integer(),
  rows_before_limit: non_neg_integer()
}

t()

@type t() :: %Huginn.Clickhouse.Result{
  columns: [column()],
  logs: [log_entry()],
  output_format: String.t(),
  progress: progress() | nil,
  query_id: String.t(),
  rows: [[String.t()]],
  stats: stats() | nil,
  time_zone: String.t()
}

Functions

from_grpc(grpc_result)

@spec from_grpc(struct()) :: {:ok, t()} | {:error, struct()}

Converts a gRPC Result message to a Huginn.Clickhouse.Result struct.

merge(results)

@spec merge([t()]) :: t()

Merges multiple results from streaming responses.

parse_output(output, format, columns \\ [])

@spec parse_output(binary() | nil, String.t(), [column()]) :: [[String.t()]]

Parses raw output bytes based on format.

columns is the list of column/0 maps parsed from the gRPC result. It is only consulted for JSONEachRow, where JSON object key order is not guaranteed to match the column order — values are extracted in column order so rows line up with columns. When columns is empty (the default, and the case for the 2-arity form), JSONEachRow falls back to the order returned by Jason.

to_maps(result)

@spec to_maps(t()) :: [map()]

Converts rows to a list of maps using column names as keys.