Lotus.Result.Statistics (Lotus v0.16.5)

Copy Markdown View Source

Computes column-level statistics from in-memory query results.

Operates entirely on the data already present in a %Lotus.Result{} struct, requiring no additional database queries. Statistics are computed per-column and vary based on the detected column type (numeric, string, or temporal).

Summary

Functions

Computes statistics for a single column in the result set.

Computes statistics for all columns in the result set.

Detects the column type from its values.

Types

column_stats()

@type column_stats() :: map()

column_type()

@type column_type() :: :numeric | :string | :temporal | :unknown

Functions

compute(result, column_name)

@spec compute(Lotus.Result.t(), String.t()) ::
  {:ok, column_stats()} | {:error, String.t()}

Computes statistics for a single column in the result set.

Returns a map with :type and type-specific statistics keys. Returns {:error, reason} if the column is not found.

compute_all(result)

@spec compute_all(Lotus.Result.t()) :: %{required(String.t()) => column_stats()}

Computes statistics for all columns in the result set.

Returns a map of %{column_name => stats_map}.

detect_column_type(result, column_name)

@spec detect_column_type(Lotus.Result.t(), String.t()) ::
  column_type() | {:error, String.t()}

Detects the column type from its values.

Inspects non-nil values and returns :numeric, :string, :temporal, or :unknown.