首页 > 解决方案 > Siddhi延迟查询

问题描述

我很难理解这个查询:

from heartbeats#window.time(1 hour) insert expired events into delayedStream;

from every e = heartbeats -> e2 = heartbeats[deviceId == e.deviceId]
  or expired = delayedStream[deviceId == e.deviceId]
within 1 hour 10 minutes 
select e.deviceId, e2.deviceId as id2, expired.deviceId as id3
insert into tmpStream;

这有效,但我不明白这部分:

从每个 e = heartbeats -> e2 = heartbeats[deviceId == e.deviceId] 或 expired = delayedStream[deviceId == e.deviceId]

查询的第二部分(或 expired = ...)检查具有给定 deviceId 的事件是否在延迟流上。第一部分的目的是什么?它是如何组合在一起的,这个查询会找到超过 1 小时没有发送数据的设备?

标签: complex-event-processingsiddhiwso2sp

解决方案


如果您想检查传感器在过去 1 小时内是否没有发送读数,我认为上述查询并不准确。我将窗口调整为 1 分钟并发送了 2 个事件,

[2019-07-19 16:48:23,774] heartbeats : Event{timestamp=1563535103772, data=[1], isExpired=false}
[2019-07-19 16:48:24,696] tmpStream : Event{timestamp=1563535104694, data=[1, 1, null], isExpired=false}
[2019-07-19 16:48:24,697] heartbeats : Event{timestamp=1563535104694, data=[1], isExpired=false}
[2019-07-19 16:49:23,774] tmpStream : Event{timestamp=1563535163772, data=[1, null, 1], isExpired=false}

假设事件在 10 和 10.15 到达,tmpStream 的输出将在 10.15(第一部分)和 11(由于延迟流)。第二个匹配不正确,因为它必须根据用例在 11.15 匹配。

但是,如果您想改进查询,您可以为您的用例使用 Siddhi 检测非出现模式功能,https://siddhi.io/en/v5.0/docs/query-guide/#detecting-non-发生事件,它会更简单


推荐阅读