否定 "every" 语句? WSO2 CEP / Siddhi
Negation for "every" statement? WSO2 CEP / Siddhi
有没有简单的方法可以否定"every"语句?我正在尝试实施一种检查传入采购订单和申请的控制工具。对于每个采购订单 (PO),必须先创建一个申请 (REQ)。以下代码检测 PO/REQ-pairs 匹配(正),但我需要所有没有相应 REQ(负)的采购订单。
from every a1 = PO -> b1 = REQ[a1.ITEM_ID == b1.ITEM_ID and a1.QUANTITY == b1.QUANTITY and a1.CREATED_BY == b1.CREATED_BY] within 1 day select 'No REQ created before' as ALERT_MESSAGE insert into ALERT;
可以参考sample on detecting non-occurrences with patterns。
但是,由于您要检查 REQ 事件是否在 PO 事件之前发生,您可能需要使用内存中的事件表来满足您的要求。请参考以下关于使用内存表实现相同目标的示例;
@Import('REQStream:1.0.0')
define stream REQ (ITEM_ID int, QUANTITY int, CREATED_BY string);
@Import('POStream:1.0.0')
define stream PO (ITEM_ID int, QUANTITY int, CREATED_BY string);
@Export('ALERTStream:1.0.0')
define stream ALERT (ITEM_ID int, ALERT string);
define table REQ_TABLE (ITEM_ID int, QUANTITY int, CREATED_BY string);
define trigger DAILY_TRIGGER at every 1 day;
from REQ
insert into REQ_TABLE;
-- check whether request exists before the purchase
from PO[not((REQ_TABLE.ITEM_ID == ITEM_ID and REQ_TABLE.QUANTITY == QUANTITY and REQ_TABLE.CREATED_BY == CREATED_BY) in REQ_TABLE)]
select ITEM_ID, 'No REQ created before' as ALERT
insert into ALERT;
-- purge reauests table daily
from DAILY_TRIGGER join REQ_TABLE
select REQ_TABLE.ITEM_ID, REQ_TABLE.QUANTITY, REQ_TABLE.CREATED_BY
insert into PURGE_STREAM;
-- if there's no matching purchase order came up for previous day
from PURGE_STREAM
select ITEM_ID, 'No purchase order came up for a day' as ALERT
insert into ALERT;
from PO
insert into DEL_STREAM;
from PURGE_STREAM
insert into DEL_STREAM;
-- delete corresponding request from table
from DEL_STREAM
delete REQ_TABLE
on REQ_TABLE.ITEM_ID == ITEM_ID and REQ_TABLE.QUANTITY == QUANTITY and REQ_TABLE.CREATED_BY == CREATED_BY;
有没有简单的方法可以否定"every"语句?我正在尝试实施一种检查传入采购订单和申请的控制工具。对于每个采购订单 (PO),必须先创建一个申请 (REQ)。以下代码检测 PO/REQ-pairs 匹配(正),但我需要所有没有相应 REQ(负)的采购订单。
from every a1 = PO -> b1 = REQ[a1.ITEM_ID == b1.ITEM_ID and a1.QUANTITY == b1.QUANTITY and a1.CREATED_BY == b1.CREATED_BY] within 1 day select 'No REQ created before' as ALERT_MESSAGE insert into ALERT;
可以参考sample on detecting non-occurrences with patterns。 但是,由于您要检查 REQ 事件是否在 PO 事件之前发生,您可能需要使用内存中的事件表来满足您的要求。请参考以下关于使用内存表实现相同目标的示例;
@Import('REQStream:1.0.0')
define stream REQ (ITEM_ID int, QUANTITY int, CREATED_BY string);
@Import('POStream:1.0.0')
define stream PO (ITEM_ID int, QUANTITY int, CREATED_BY string);
@Export('ALERTStream:1.0.0')
define stream ALERT (ITEM_ID int, ALERT string);
define table REQ_TABLE (ITEM_ID int, QUANTITY int, CREATED_BY string);
define trigger DAILY_TRIGGER at every 1 day;
from REQ
insert into REQ_TABLE;
-- check whether request exists before the purchase
from PO[not((REQ_TABLE.ITEM_ID == ITEM_ID and REQ_TABLE.QUANTITY == QUANTITY and REQ_TABLE.CREATED_BY == CREATED_BY) in REQ_TABLE)]
select ITEM_ID, 'No REQ created before' as ALERT
insert into ALERT;
-- purge reauests table daily
from DAILY_TRIGGER join REQ_TABLE
select REQ_TABLE.ITEM_ID, REQ_TABLE.QUANTITY, REQ_TABLE.CREATED_BY
insert into PURGE_STREAM;
-- if there's no matching purchase order came up for previous day
from PURGE_STREAM
select ITEM_ID, 'No purchase order came up for a day' as ALERT
insert into ALERT;
from PO
insert into DEL_STREAM;
from PURGE_STREAM
insert into DEL_STREAM;
-- delete corresponding request from table
from DEL_STREAM
delete REQ_TABLE
on REQ_TABLE.ITEM_ID == ITEM_ID and REQ_TABLE.QUANTITY == QUANTITY and REQ_TABLE.CREATED_BY == CREATED_BY;