我一直在尝试与Siddhi进行复杂的关联,在这种情况下,我有两个输入流,Web客户端咨询和发送给客户访问的通知,如果每个客户端的第一个流重复多次,我想生成警报只要第二个流不是它在两个窗口下发生并且取决于这个事件的状态。
define stream consults (idClient string,dniClient string,codProduct string,codSubProduct string,chanel string,time string )
define stream comercialActions(idClient string, idAccionComercial string,codProduct string,codSubProduct string,chanel string,time string,status string)
from consults[codProduct=='Fondos']#window.time(50 seconds) select idClient,codProduct, codSubProduct, chanel, time, count(idClient) as visitCount group by idClient insert into consultsAvg for current-events
from consultsAvg[visitCount==1] select idClient, '' as idAccionComercial,codProduct, codSubProduct ,chanel, time, 'temp' as status insert into comercialActions for all-events
from comercialActions[status=='temp' or status == 'Lanzada' ]#window.time(5 seconds) select idClient as idClient, codProduct, codSubProduct, chanel, status, count(idClient) as num_status group by idClient insert into acciones_generadas for all-events
from comercialActions[status=='temp' or status=='Aceptada' or status =='Rechazada'or status=='Caduca']#window.time(3 seconds) select idClient as idClient, codProduct, codSubProduct, chanel, status, count(idClient) as num_status group by idClient insert into acciones_realizadas for all-events
from consultsAvg[visitCount>=2]#window.time(50 seconds) as c join acciones_realizadas[num_status>=1]#window.time(5 seconds) as ag on c.idClient == ag.idClient and c.codProduct==ag.codProduct select c.idClient,c.codProduct,c.codSubProduct,c.chanel, c.time, count(c.idClient) as conteo insert into posible_ac for all-events
from posible_ac#window.time(5 seconds) as pac join acciones_generadas[num_status>=1]#window.time(1 seconds) as ar on pac.idClient == ar.idClient select pac.idClient,pac.codProduct,pac.codSubProduct,pac.chanel,pac.time,conteo, count(ar.idClient) as conteo2 insert into enviar_Ac
from enviar_Ac[conteo==1 and conteo2==1] select idClient, codProduct,codSubProduct, chanel, time insert into generar_accion_comercial
我尝试做的是使用中间流来计算网站点击次数,当它大于或等于2时,我看看它是否已经通过各种连接为该客户做出了商业行为...... 我想我变得非常复杂,不知道是否会有更简单的解决方案??? ,考虑到它没有Siddhi NOT Happened或其他连接功能(左连接)
答案 0 :(得分:1)
您可以使用模式完成此操作。在这种情况下,我假设我们必须等待1分钟来处理来自第二个流的事件,如果没有,并且第一个事件中有多个事件,我们将发出一个输出。
{{1}}
这些是草稿查询,因此可能需要进行一些修改才能使它们正常工作。 filteredConsultsStream包含在最后一分钟内发生多于1次的咨询事件。 在上一个查询中,我们得到的条件如下: nonOccurringEvent = commercialActions [firstEvent.idClient == idClient] 要么 triggerEvent = filteredConsultsStream [firstEvent.idClient == idClient]
因此查询将由上述事件之一触发。但是,我们需要找出条件是否由commercialActions触发。为此我们使用'having'子句并检查id是否为null(id为null意味着事件为null,不存在)。最后我们发出输出。
你可以找到一个更好的描述,有点类似的查询here(这是新的4.0.0版本顺便说一句,并且有很小的语法更改)