-1

我有一个具有(价格、交易时间)属性的市场数据事件流。

我想为每个新的市场数据事件计算过去时间窗口的简单平均值。简单平均 = 交易价格总和 / 事件数

然而,棘手的部分是我想从当前事件时间为多个子时间窗口计算这个。所以,说 [t-0 min, t-2 min] , [t-2 min, t-4 min], [t-4 min, t-6 min], ...

将为每个新事件重新计算这些时间窗口。

现在我只使用多个流并总结 [t-0 min, t-2 min], [t-0 min, t-4 min], t-0 min, t-6 min] 的价格和事件, ...并通过减法找到他们各自的简单平均值。必须有更好的方法来做到这一点,可能只使用一个或两个流?

4

1 回答 1

0

对于任何试图解决相同问题的人:

创建五个交错的时间窗口,其中离开一个窗口的事件进入下一个...

            create window W1.win:time(5 min) as select * from yourSource                
            create window W2.win:time(5 min) as select * from yourSource                 
            create window W3.win:time(5 min) as select * from yourSource
            create window W4.win:time(5 min) as select * from yourSource
            create window W5.win:time(5 min) as select * from yourSource

            insert into W1 select * from yourSource
            insert rstream into W2 select rstream * from W1
            insert rstream into W3 select rstream * from W2
            insert rstream into W4 select rstream * from W3
            insert rstream into W5 select rstream * from W4

            select sum(price)/count(*) as sma, symbol from W1
            GROUP BY symbol
            select sum(price)/count(*) as sma, symbol from W2
            GROUP BY symbol
            select sum(price)/count(*) as sma, symbol from W3
            GROUP BY symbol
       select sum(price)/count(*) as sma, symbol from W4
            GROUP BY symbol
            select sum(price)/count(*) as sma, symbol from W5
            GROUP BY symbol
于 2011-05-20T05:13:49.040 回答