在Siddhi,我试图编写一个查询,检查在指定的时间段内满足的事件条件。 以下是要求: 对于带有温度的事件流,我需要温度在指定的时间段内始终大于20,以便将其推送到输出流,使用5分钟的批处理时间
我使用的查询是:
@Plan:name('TestExecutionPlan')
@PrimaryKey('sensorId')
define table stable1 (sensorId string, temperature float,count long);
define table stable2 (sensorId string, temperature float,count long);
define stream sensorStream (sensorId string, temperature float);
from sensorStream[sensorId=="tempID1"]#window.timeBatch (1 sec)
select timestamp() as messageID,sensorId ,temperature,count() as count
insert into test1;
@info(name = 'query1')
from sensorStream[sensorId=="tempID1"]#window.timeBatch (1 sec)
select sensorId ,temperature,count() as count
insert into stable1;
from sensorStream[sensorId=="tempID1" and temperature>20 ]#window.timeBatch (1 sec)
select timestamp() as messageID, sensorId as sensorId, temperature as temperature, count() as count
insert into test2;
from stable1 join test2 on test2.count==stable1.count
select test2.sensorId ,test2.temperature,test2.count
insert into finalStream;
对于事件流
sensorStream=[tempID1,190.8]
delay(500)
sensorStream=[tempID1,100]
delay(500)
sensorStream=[tempID1,38.8]
delay(200)
sensorStream=[tempID1,15.8]
delay(100)
sensorStream=[tempID1,45.8]
delay(700)
sensorStream=[tempID1,8.8]
delay(500)
sensorStream=[tempID1,18.8]
delay(500)
sensorStream=[tempID1,34.8]
delay(500)
sensorStream=[tempID1,18.8]
delay(500)
sensorStream=[tempID1,18.8]
delay(500)
sensorStream=[tempID1,18.8]
delay(500)
sensorStream=[tempID1,18.8]
delay(500)
sensorStream=[tempID1,18.8]
delay(500)
sensorStream=[tempID1,18.8]
delay(500)
sensorStream=[tempID1,18.8]
delay(500)
在上面的查询中,我获得了1分钟的特定tagId的计数,然后将其存储在表 stable1 中。 并且对于具有条件(> 20)的特定tagId计数时间批次1秒。然后我在他们两个上申请加入以检查匹配。所以这里的问题是因为没有我可以加入这两个的Id,加入没有正确发生。
任何人都可以指导我如何将时间戳添加到输出中,以便我可以加入同一时间,也让我知道是否有更简单的方法。
答案 0 :(得分:0)
我应该使用序列来实现此
解决问题的查询是:
@info(name = 'query2')
from e1=sensorStream[sensorId=="tempID1" and temperature>20],e2=out1[sensorId=="tempID1" and temperature>20] within 1 sec
select e1.sensorId,e1.temperature
insert into outstream;