1

我想使用 aws timestream 来跟踪用户对我们 API 的请求。在第一步中,我只是将每个请求的用户 ID 存储到 API。对于图表,我想获取用户在特定时间间隔内的请求数。此 SQL 每隔 10 分钟从用户 2 获取最近两小时内的请求:

SELECT user_id, COUNT(user_id) AS n, bin(time, 10m) AS btime
FROM db_api.t_access
WHERE time > ago(2h) AND user_id IN ('2')
GROUP BY user_id, bin(time, 10m)
ORDER BY btime DESC

结果是:

2021-03-06 00:20:00.000000000 user_id:2 Count:1
2021-03-06 00:10:00.000000000 user_id:2 Count:4
2021-03-05 23:40:00.000000000 user_id:2 Count:2

没有请求的时间间隔不会返回,这里是 00:00 和 23:50。有没有办法在 SQL 中使用 Count = 0 来获得这个空间隔?还是我必须编写自己的代码才能从结果集中获取所有间隔(我使用 aws PHP API)?

4

1 回答 1

0

您可以使用:

 interpolate_fill(timeseries, array[timestamp], double) 

参考链接:https ://docs.aws.amazon.com/timestream/latest/developerguide/timeseries-specific-constructs.functions.interpolation.html

于 2021-08-15T08:05:22.430 回答