Skip to main content

Aggregate Functions

All aggregate and window functions available in stats, eventstats, and streamstats stages.

Standard Aggregates

All standard aggregates support where clauses for conditional aggregation: count(where status >= 500).

FunctionParamsResultDescription
count(x: any?)intcount() counts rows; count(x) counts non-null x; count(where p) counts matching rows.
sum(x: number)numberNulls skipped; all-null group yields null.
avg(x: number)float-
min(x: any)any-
max(x: any)any-
dc(x: any)intDistinct count; exact below 10K, HLL above.
estdc(x: any)intAlways-HLL distinct count.
perc(x: number, p: number)floatT-digest percentile; p in [0, 100].
p50(x: number)floatAlias for perc(x, 50).
p75(x: number)floatAlias for perc(x, 75).
p90(x: number)floatAlias for perc(x, 90).
p95(x: number)floatAlias for perc(x, 95).
p99(x: number)floatAlias for perc(x, 99).
perc_weighted(x: number, weight: number, p: number)floatWeighted t-digest percentile; p in [0, 100].
stdev(x: number)floatSample standard deviation.
var(x: number)floatSample variance.
corr(x: number, y: number)floatPearson correlation over rows where both arguments are numeric.
covar(x: number, y: number)floatSample covariance over rows where both arguments are numeric.
linear_fit(x: number, y: number)objectLeast-squares fit as {slope, intercept, r2}.
sum_object(obj: object)objectPer-key sums for numeric object values.
skewness(x: number)floatBias-corrected sample skewness.
kurtosis(x: number)floatBias-corrected sample excess kurtosis.
mad(x: number)floatMedian absolute deviation over numeric values.
delta_sum(x: number)floatSum positive deltas between consecutive numeric values, ignoring counter resets.
histogram(x: number, bins: int)arrayExact fixed-width bins as {lo, hi, count}; returns null if the retained value cap is exceeded.
mode(x: any)any-
arg_max(value: any, order: any)anyValue from the row with the greatest order expression.
arg_min(value: any, order: any)anyValue from the row with the least order expression.
any_value(x: any)anyAn arbitrary non-null value from the group.
top_k(x: any, k: int)arrayTop k non-null values with counts.
top_k_weighted(x: any, weight: number, k: int)arrayTop k non-null values by summed positive weight.
value_counts(x: any, max: int?)arrayNon-null values with counts, sorted by frequency and optionally capped.
avg_weighted(x: number, weight: number)floatWeighted average as sum(x * weight) / sum(weight).
entropy(x: any)floatShannon entropy of non-null values, in bits.
max_n(x: any, n: int)arrayLargest n non-null values.
min_n(x: any, n: int)arraySmallest n non-null values.
first(x: any)anyFirst non-null in row order.
last(x: any)anyLast non-null in row order.
earliest(x: any)anyValue from the row with the smallest _time.
latest(x: any)anyValue from the row with the largest _time.
values(x: any, n: int?)arrayDistinct non-null values, optionally capped at n.
list(x: any, n: int?)arrayAll non-null values in row order, optionally capped at n.
rate()floatRow count divided by the group's time-bucket span.
per_second(x: number)floatsum(x) divided by the group's time-bucket span in seconds.

Window Functions (streamstats only)

FunctionParamsResultDescription
lag(x: any, n: int?)anyValue n rows back (default 1).
lead(x: any, n: int?)anyValue n rows ahead (default 1).
row_number()int1-based row index within the group.
rank()int1-based rank within the group using the preceding sort key, with gaps after ties.
dense_rank()int1-based rank within the group using the preceding sort key, without gaps after ties.
running_sum(x: number)number-
moving_avg(x: number, n: int)float-
delta(x: number)floatDifference between the current value and previous group value.
ema(x: number, n: int)floatExponential moving average with alpha = 2/(n+1).

Generated from the LynxFlow registry. See RFC-002 for the full specification.