redis_ts icon indicating copy to clipboard operation
redis_ts copied to clipboard

Additional aggregation options: EMPTY and BUCKETTIMESTAMP

Open avaziman opened this issue 2 years ago • 0 comments

This pull request adds support to the new aggregation options introduced in RedisTimeSeries 1.8: EMPTY - retrieves empty gaps from a timeseries BUCKETTIMESTAMP - controls how bucket timestamps are reported

The PR introduces a new interface TsAggregationOptions made idiomatic to the existing library interfaces such as TsOptions. The TsAggregationOptions can be passed to all the range functions as an alternative to TsAggregationType and it contains a TsAggregationType, an optional TsBucketTimestamp, and empty flag to denote the new aggregation features.

Additionally, minimal testing was added to check the basic use of the features. In terms of backward compatibility, TsAggregationType can still be passed as an aggregation argument to the range functions, however, when aggregation is passed as None, an explicit type of Aggregatable needs to be passed (i.e None::<TsAggregationOptions> or None::<TsAggregationType>)

Finally, an example to illustrate the change in the interface:

// old
let first_three_avg:TsRange<u64,f64> = con.ts_range(
    "my_engine", "-", "+", Some(3), Some(TsAggregationType::Avg(5000))
)?;

// new
let first_three_avg_empty_bucket_mid:TsRange<u64,f64> = con.ts_range(
    "my_engine", "-", "+", Some(3), Some(
            TsAggregationOptions::new(TsAggregationType::Avg(5000))
                .empty(true)
                .bucket_timestamp(Some(TsBucketTimestamp::Mid))
       ))?;

avaziman avatar Nov 19 '22 16:11 avaziman