我試圖讓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