Berserk Docs
Aggregate Functions

Introduction to Aggregate Functions

Aggregate function overview and categories

Aggregate functions combine multiple rows into a single summary value. They are used inside the summarize operator:

logs
| summarize
    total = count(),
    error_rate = countif(severity_number >= 17) * 1.0 / count(),
    p95 = percentile(duration_ms, 95)
  by service, bin(timestamp, 5m)

Each aggregate collapses the rows in a group into one output row. The by clause defines the grouping keys. For a full introduction to writing queries, see Writing Queries.

Memory budget and sampling

summarize holds aggregate state in memory and merges it before producing results, so wide group-by keys, long time ranges, or heavy per-group state (percentiles, make_set/make_list, histograms) can grow it without bound. To stay safe under load, each summarize runs under a per-operator memory budget. When a query exceeds it, the engine degrades instead of failing or running the cluster out of memory: it keeps a representative subset of series — dropping whole series, never punching holes in a timechart — and returns a coverage warning telling you what fraction was retained. If there is no series axis to drop (for example grouping by bin(timestamp, …) alone), the query fails with an actionable error rather than a silently wrong result. Tune it per query with hint.budget=<size> and hint.sample={sample | heaviest}.

Statistical

FunctionDescription
avgCalculates the average of values in the group.
avgifCalculates the average of values in the group for which the predicate evaluates to true.
countReturns a count of the records in the input record set.
countifReturns a count of the records for which a predicate is true.
dcountReturns an estimate for the number of distinct values of the expression in the group.
dcountifReturns an estimate for the number of distinct values of the expression in the group, for which the predicate evaluates to true.
maxReturns the maximum value across the group.
minReturns the minimum value across the group.
stdevCalculates the sample standard deviation of values in the group.
stdevifCalculates the sample standard deviation of values for which the predicate is true.
stdevpCalculates the population standard deviation of values in the group.
sumCalculates the sum of values in the group.
sumifCalculates the sum of values in the group for which the predicate evaluates to true.
take_anyReturns an arbitrary non-null value from the group.
take_anyifReturns an arbitrary non-null value from the group for which the predicate is true.

Arg

FunctionDescription
arg_maxReturns both the maximum value and the corresponding return expression from the row where the first expression is maximum.
arg_minReturns both the minimum value and the corresponding return expression from the row where the first expression is minimum.

Make / Collect

FunctionDescription
firstReturns the value of the expression from the row with the earliest timestamp.
lastReturns the value of the expression from the row with the latest timestamp.
make_listReturns a dynamic (JSON) array of all values of Expr in the group.
make_list_ifReturns a dynamic (JSON) array of values of expr for the rows in the group where predicate is true.
make_setReturns a dynamic (JSON) array of all distinct values of Expr in the group.
make_set_ifReturns a dynamic (JSON) array of distinct values of expr for the rows in the group where predicate is true.

Percentile & Sketch

FunctionDescription
hllCreates a HyperLogLog sketch.
hll_ifCreates a HyperLogLog sketch for records where the predicate evaluates to true.
hll_mergeMerges multiple HyperLogLog sketches.
merge_tdigestMerges multiple T-Digest sketches.
otel_histogram_mergeMerges OpenTelemetry histogram data points (explicit-boundary or exponential).
otel_histogram_percentileAggregate that merges OpenTelemetry histogram data points and extracts one or more percentiles from the merged result.
percentileCalculates the specified percentile of a numeric column using DDSketch.
tdigestCreates a T-Digest sketch from numeric values.

Metrics

FunctionDescription
derivComputes the derivative (rate of change) for a gauge metric.
otel_histogram_ratePer-second rate of observation count for an OpenTelemetry histogram metric.
otel_rateComputes the per-second rate from an OpenTelemetry type=sum metric.
rateComputes the per-second rate of change for a counter metric, handling counter resets.

Other

FunctionDescription
describe_schemaInfers JSON Schema from column values.

On this page