如何转换包含事件序列的流

时间:2016-05-12 05:08:04

标签: wso2 wso2cep siddhi

我编写了一个自定义的http接收器,它从另一个系统获取事件,并且json示例如:

{"tag":"A01","time":"10:01:00","value":"30.01"},
{"tag":"A01","time":"10:01:01","value":"35.01"},
{"tag":"A01","time":"10:01:02","value":"31.01"},
{"tag":"B01","time":"10:01:00","value":"105.017"},
{"tag":"B01","time":"10:01:01","value":"230.01"},
{"tag":"B01","time":"10:01:02","value":"117.01"}

比接收器逐个发送json到流名称“tag_input_stream”,其中包含字段:

tag string, time string, value double

现在我有另一个名称为format_tag_stream的流名称,其中包含字段:

time string, tag_A_val double, tag_B_val double

我想在tag_input_stream中将值插入format_tag_stream,如下所示:

10:01:00, 30.01 , 105.017
10:01:01, 35.01 , 230.01
10:01:02, 31.01 , 117.01

我使用Execustion Plan来编写siddhi脚本:

from every(e1=tag_input_stream)->e2=tag_input_stream[time==e1.time]
select e1.time as time, e1.value as v1, e2.value as v2
insert into format_tag_stream

但它不起作用。如何编写脚本,任何一个例子?感谢

1 个答案:

答案 0 :(得分:0)

在查询中:

from every(e1=tag_input_stream[tag=='A01'])-> e2=tag_input_stream[time==e1.time AND tag=='B01'] 

您认为事件A01首先出现,B01出现。但是,如果它们以相反的顺序排列,则不会执行查询。

因此,请编写下面给出的另一个查询,以应对逆序事件。

from every(e1=tag_input_stream[tag=='B01'])-> e2=tag_input_stream[time==e1.time AND tag=='A01']

谢谢,

Upul