从 Esper 示例中,我只编写了这样的简单 EPL:
select symbol, avg(price) as avgprice,count(*) as count,
current_timestamp() as time from StockTick.win:time(0.4 sec)
group by symbol
每隔 100 毫秒,我就会将数据输入 Esper,如下所示:
StockTick={symbol='YHOO', price=100}
t=t.plus(0.1 seconds)
StockTick={symbol='YHOO', price=65}
t=t.plus(0.1 seconds)
StockTick={symbol='YHOO', price=75}
t=t.plus(0.1 seconds)
StockTick={symbol='YHOO', price=65}
t=t.plus(0.1 seconds)
StockTick={symbol='YHOO', price=100}
t=t.plus(0.1 seconds)
StockTick={symbol='YHOO', price=15}
但是我收到的输出让我感到困惑
Statement: AVGTABLE
Insert
AVGTABLE-output={symbol='YHOO', avgprice=76.25, count=4, time=300}
At: 1970-01-01 00:00:00.400
Statement: AVGTABLE
Insert
AVGTABLE-output={symbol='YHOO',avgprice=68.33333333333333, count=3,
time=400}
At: 1970-01-01 00:00:00.400
Statement: AVGTABLE
Insert
AVGTABLE-output={symbol='YHOO', avgprice=76.25, count=4, time=400}
At: 1970-01-01 00:00:00.500
Statement: AVGTABLE
Insert
AVGTABLE-output={symbol='YHOO', avgprice=80.0, count=3, time=500}
At: 1970-01-01 00:00:00.500
Statement: AVGTABLE
Insert
AVGTABLE-output={symbol='YHOO', avgprice=63.75, count=4, time=500}
At: 1970-01-01 00:00:00.600
Statement: AVGTABLE
Insert
AVGTABLE-output={symbol='YHOO', avgprice=60.0, count=3, time=600}
在时间 400 和 500 处,这里有 2 个输出,我想它的出现是由于 1 个事件在另一个出现之前离开窗口。为什么它们出现在这里,因为我没有选择irstream
,我如何在UpdateEventListener
中避免它?
当事件从时间窗口过期时,平均值会发生变化,因此侦听器会看到新的平均值,因为旧的平均值不再正确。通过不使用时间窗口来避免它,例如... from StockTick group by ...