简体   繁体   English

表上的 SiddhiQL 复杂过滤条件

[英]SiddhiQL complex filter condition on table

I have a table T(name string,id string) and i receive events from a stream X(name string,id string).我有一个表 T(name string,id string),我从流 X(name string,id string) 接收事件。 When i receive an event, if the name does not exist in table T, I want to insert the name and id into table and send that event to output stream.当我收到一个事件时,如果表 T 中不存在名称,我想将名称和 ID 插入表中并将该事件发送到输出流。 If the name exists in the table, i want to send that event to output stream only if the id against the name in the table matches to that of the id received in event.如果名称存在于表中,我想仅当表中名称的 id 与事件中收到的 id 匹配时,才将该事件发送到输出流。 Ex -前任 -

Table Data
name     |id
qwerty   |12345

Event 1 = {qwerty,123}
Event 2 = {qwerty,12345}
Event 3 = {asdf,12}

In the above scenario, I want to ignore event 1 , send event2 to output stream and add event3 name and id in table and then send it to output stream.在上面的场景中,我想忽略 event 1 ,将 event2 发送到输出流并在 table 中添加 event3 name 和 id 然后将其发送到输出流。

Is this possible in siddhiql?这在 siddhiql 中可能吗?

You can use siddhi table joins especially left outer join with name as the condition and filter out other cases along the way您可以使用 siddhi表连接,尤其是左外连接,以 name 作为条件,并在此过程中过滤掉其他情况

  1. Inner joins for case 1 and 2, This will only return event if the name and id match.情况 1 和 2 的内部连接,如果名称和 ID 匹配,这只会返回事件。
from XStream left outer join ATable 
  on XStream.name == ATable.name 
select Xstream.name, XStream.id, ATable.name as tableName, ATable.id as tableId 
insert into OutputStream;

from Outputstream[tableName is null] 
select name, id 
insert into ATable;

-- Here if the table name is not null it will be equal to XStream.name based on the first query
from Outputstream[not(tableName is null) and (tableId == id)] 
select name, id 
insert into FilteredStream;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM