Skip to main content

timeSeriesLastTwoSamples

Introduced in: v25.6.0 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 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
Response
Query the last 2 sample for timestamps ‘2024-12-12 12:00:15’ and ‘2024-12-12 12:00:30’
Query
Response
Calculate idelta and irate from the raw data
Query
Response
Calculate idelta and irate from the re-sampled data
Query
Response
Last modified on June 23, 2026