Skip to main content

timeSeriesTopKMasks

Introduced in: v26.8.0 Selects the time series with the k greatest values at each time step of a time grid. Each input row is one time series: key identifies the series and values contains its values aligned to a common time grid, so the values arrays of all rows must have the same size. At each time step, the series with the k greatest non-NULL values at that step are selected (NaN is considered smaller than any other value). Value ties are broken by preferring the series with the smaller key. This function implements the topk() aggregation operator of PromQL and keeps only one bounded heap of size k per time step, so its state size does not depend on the number of aggregated series.
This function is in private preview, enable it by setting enable_time_series_aggregate_functions = 1.
Syntax
Arguments Returned value Returns the selected series in the order of ascending key, each together with its per-step mask: steps_mask[t] = 1 if the series is selected at time step t. Series which are selected at no time step are not returned. Array(Tuple(key UInt64, steps_mask Array(UInt8))) Examples Selecting the 2 greatest series per time step
Query
Response
Last modified on October 7, 2026