pipelinedb 滑动窗口
滑动窗口可以方便的让我们进行一段时间的数据分析
几个主要函数
- clock_timestamp
内置的函数,总是返回当前的时间戳
- arrival_timestamp
事件达到的时间
单滑动窗口
- 参考
CREATE CONTINUOUS VIEW recent_users WITH (sw = '1 minute') AS
SELECT user_id::integer FROM stream;
相应的pipelinedb 会转换为:
CREATE CONTINUOUS VIEW recent_users AS
SELECT user_id::integer FROM stream
WHERE (arrival_timestamp > clock_timestamp() - interval '1 minute');
多窗口
是一个基于单滑动窗口的view
- 参考例子
CREATE CONTINUOUS VIEW sw0 WITH (sw = '1 hour') AS SELECT COUNT(*) FROM event_stream;
CREATE VIEW sw1 WITH (sw = '5 minutes') AS SELECT * FROM sw0;
CREATE VIEW sw2 WITH (sw = '10 minutes') AS SELECT * FROM sw0;