跳到主要内容
跳到主要内容

timeSeriesLastTwoSamples

Aggregate function that takes time series data as pairs of timestamps and values and stores only at most 2 recent samples.

Arguments:

  • timestamp - timestamp of the sample
  • value - value of the time series corresponding to the timestamp Also it is possible to pass multiple samples of timestamps and values as Arrays of equal size.

Return value: A Tuple(Array(DateTime), Array(Float64)) - 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.

Example: 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. Consider the following example table for raw data, and a table for storing re-sampled data:

Insert some test data and read the data between '2024-12-12 12:00:12' and '2024-12-12 12:00:30'

Query last 2 sample for timestamps '2024-12-12 12:00:15' and '2024-12-12 12:00:30':

The aggregated table stores only last 2 values for each 15-second 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.