TimeSeries: Support `LATEST` option in queries
- Dominant language
- C++
- Stars
- 4.4k
- Forks
- 658
- Avg merge
- 1d 20h
- Merged PRs (30d)
- 10
Description
### Search before asking
- [x] I had searched in the [issues](https://github.com/apache/kvrocks/issues) and found no similar issues.
### Motivation
When using `TS.GET/TS.RANGE` to query a compacted time series, the `LATEST` option can be specified. This causes `TS.GET/TS.RANGE` to return the compacted value of the latest bucket, which may be a partial bucket.
Redis reference:
https://redis.io/docs/latest/commands/ts.get/
### Solution
Modify [`rangeCommon`](https://github.com/apache/kvrocks/blob/e19164f032b43c9408a5a0badf53aebeb092d97c/src/types/redis_timeseries.h#L318-L319) and [`getCommon`](https://github.com/apache/kvrocks/blob/e19164f032b43c9408a5a0badf53aebeb092d97c/src/types/redis_timeseries.h#L322-L323) to retrieve the latest bucket of source series when the latest sample is requested.
Note: Since partial aggregations are stored in `DOWNSTREAM` sub keys, we only need to fetch the last chunk of the source series to retrieve the latest bucket's aggregated value.
Refer to [`DOWNSTREAM` sub keys](https://kvrocks.apache.org/community/data-structure-on-rocksdb#downstream-sub-keys)
Refer to https://github.com/apache/kvrocks/pull/3151
### Are you willing to submit a PR?
- [ ] I'm willing to submit a PR!
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.