timeSeriesLastTwoSamples
timeSeriesLastTwoSamples
Introduced in: v25.6
Aggregate function for re-sampling time series data for PromQL-like irate and idelta calculation.
Aggregate function that takes time series data as pairs of timestamps and values and stores only at most 2 recent samples. This aggregate function is intended to be used with a Materialized View and Aggregated table that stores re-sampled time series data for grid-aligned timestamps.
The aggregated table stores only last 2 values for each aligned timestamp. This allows to calculate PromQL-like irate and idelta by reading much less data then is stored in the raw table.
This function is experimental, enable it by setting allow_experimental_ts_to_grid_aggregate_function=true.
Syntax
Arguments
timestamp— Timestamp of the sample.DateTimeorDateTime64or(U)Int*orInt*value— Value of the time series corresponding to the timestamp.Float32orFloat64
Returned value
Returns a pair of arrays of equal length from 0 to 2. The first array contains the timestamps of sampled time series, the second array contains the corresponding values of the time series. Tuple(Array(DateTime), Array(Float64))
Examples
Example table for raw data, and a table for storing re-sampled data
Query the last 2 sample for timestamps '2024-12-12 12:00:15' and '2024-12-12 12:00:30'
Calculate idelta and irate from the raw data
Calculate idelta and irate from the re-sampled data