AshClickhouse.DataLayer.Aggregate (AshClickhouse v0.6.2)

Copy Markdown View Source

SQL construction, execution, and in-memory attachment of Ash aggregates.

Extracted from AshClickhouse.DataLayer so the aggregate behaviour (native COUNT/SUM/AVG/MIN/MAX queries plus batched relationship aggregates) lives in one focused module. Relationship aggregates are computed with one grouped query per aggregate across the whole result set rather than one query per record.

Summary

Functions

Attaches relationship-aggregate values onto decoded records, using one batched query per aggregate instead of one per (record, aggregate) pair.

Runs one query per aggregate and folds the results into a map (aggregate.name => value).

Functions

attach(records, aggregates, resource, repo, opts)

@spec attach([map()], [term()], module(), module(), keyword()) :: [map()]

Attaches relationship-aggregate values onto decoded records, using one batched query per aggregate instead of one per (record, aggregate) pair.

run(aggregates, resource, repo, qualified, where_clause, where_params)

@spec run(Enumerable.t(), Ash.Resource.t(), module(), String.t(), String.t(), list()) ::
  {:ok, map()} | {:error, term()}

Runs one query per aggregate and folds the results into a map (aggregate.name => value).