我试图让Siddhi在事件检测到飞机进入Geofence时触发事件,但无法完全弄清楚正确的查询。Siddhi查询地理栅栏入口检测
我有以下的输入流定义:
define stream GeofenceMulticasterConsumerStream (journeyId string, geofenceId string, withinGeofence bool, timestamp long)
每次我得到一个飞行的位置更新,我得到这个流genereated为系统中的每个地理围栏(事件有大约10个地理围栏等等以为西提将能够处理位置更新事件的10 *号)
这是我开始与查询:
define partition geofencePartition by GeofenceMulticasterConsumerStream.geofenceId;
from every a = GeofenceMulticasterConsumerStream[withinGeofence == false] ->
b = GeofenceMulticasterConsumerStream[a.journeyId == b.journeyId and b.withinGeofence == true]
within 300000
select b.journeyId, b.geofenceId, b.timestamp as timeEntered
insert into EnteredGeofenceStream
partition by geofencePartition
但是,这给了我重复的Geofence Entry事件,因为它针对每个匹配的“b”事件评估每个“a”事件(如果我有5个事件不在地理围栏中,那么后面是5个地理围栏入境事件)
所以我尝试添加一些重复的事件检测,以避免这种情况:
from every a = GeofenceMulticasterConsumerStream[withinGeofence == false] ->
b = GeofenceMulticasterConsumerStream[a.journeyId == b.journeyId and b.withinGeofence == true]
within 300000
select b.journeyId, b.geofenceId, b.timestamp as timeEntered, geofences:hashEntry(b.journeyId, b.geofenceId, b.timestamp) as entryHash
insert into DuplicateEnteredGeofenceStream
partition by geofencePartition
from DuplicateEnteredGeofenceStream#window.firstUnique(entryHash)
select journeyId, geofenceId, timeEntered
insert into EnteredGeofenceStream
地理围栏:hashEntry是我创建的生成项事件的唯一哈希码的功能。
但是,我并不热衷于这样做,因为您必须记录firstUnique窗口中的所有独特哈希值,并担心这会造成内存泄漏。看起来有点过于顶端,因为哈希将仅适用于该时间点,因此我只需要一个firstUnique窗口,该窗口最多有效几秒钟以检查重复项。
我认为我遇到的一个重大问题是我有一个流有多个航班和多个地理栅栏被追踪,因为我见过的所有例子都更简单我想知道如果我试图实现一些不可能的事情。
我非常感谢任何意见,因为我现在已经没有想法了!
在此先感谢!
如果我通过journeyId进行分区,那么是否仍然存在不同地理栅栏的事件将通过分区的问题,因此序列仍然不匹配?旅程(航班)可以同时处于多个地理围栏中。 – foyst 2014-10-30 08:38:54
我也在文档中看过,不要对高基数属性进行分区(我最终会拥有数十万个航班),尽管它们只会在标准飞行期间处于活动状态(Siddhi会如何知道关闭分区不再使用?) 理想情况下,我会通过journeyId和geofenceId分区,然后序列将是完美的:) – foyst 2014-10-30 09:07:44