complex-event-processing - 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;
- 第一个查询将所有事件延迟 1 小时。
- 第二个查询过滤了 1 小时前发生的所有事件,并且没有找到更新的事件。
这有效,但我不明白这部分:
从每个 e = heartbeats -> e2 = heartbeats[deviceId == e.deviceId] 或 expired = delayedStream[deviceId == e.deviceId]
查询的第二部分(或 expired = ...)检查具有给定 deviceId 的事件是否在延迟流上。第一部分的目的是什么?它是如何组合在一起的,这个查询会找到超过 1 小时没有发送数据的设备?
解决方案
如果您想检查传感器在过去 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-发生事件,它会更简单
推荐阅读
- reactjs - 无法运行反应项目
- emacs - Doom emacs 在终端中显示各种主题
- javascript - Javascript 在移动浏览器中不起作用
- javascript - typeof a where var a = 2 + [] is string 的解释是什么?
- vb.net - 通过匹配文件名中的字符串将文件从一个文件夹复制到另一个文件夹,并通过将日期和时间附加到文件名来重命名复制的文件
- python - 非规范化公司名称的 DataFrame [第 1 部分]
- if-statement - ARRAYFORMULA 但仅在行中出现 EMPTY 单元格 - 不起作用
- algorithm - 计算数组的深度
- java - 什么算法可用于以最佳方式在 A1 尺寸的纸张上包装规则形状
- css - 将 CSS box-shadow 应用于 SVG 中的形状而不是矩形 SVG 画布