Search code examples
postgresqlwso2complex-event-processingsiddhi

Run Time of the Trigger in Siddhi


I want read the postgres table from siddhi, and I am using a Trigger:

@From(eventtable='rdbms', jdbc.url='jdbc:postgresql://localhost:5432/pruebabg', username='postgres', password='Easysoft16', driver.name='org.postgresql.Driver', table.name='Trazablack')
define table Trazablack (sensorValue double);

define trigger FiveMinTriggerStream at every 10 min;

from FiveMinTriggerStream join Trazablack as t
select t.sensorValue as sensorValue
insert into StreamBlack;

But, I have a problem, the query is run every 10 minutes, I need to run when a new event arrives.

is this possible?

from sensorStream#window.length(2) 
JOIN StreamBlack#window.length(1)
   on sensorStream.sensorValue==StreamBlack.sensorValue
select sensorStream.meta_timestamp, sensorStream.meta_sensorName, sensorStream.correlation_longitude, 
       sensorStream.correlation_latitude, sensorStream.sensorValue as valor1, StreamBlack.sensorValue as valor2
insert INTO StreamPaso;


from sensorStream#window.length(2) 
LEFT OUTER JOIN StreamBlack#window.length(1)
   on sensorStream.sensorValue==StreamBlack.sensorValue
select sensorStream.meta_timestamp, sensorStream.meta_sensorName, sensorStream.correlation_longitude, 
       sensorStream.correlation_latitude, sensorStream.sensorValue as valor1, StreamBlack.sensorValue as valor2
insert INTO StreamPaso;

Solution

  • In this case you can simply do the join with the input stream instead of trigger stream using a window. We can use a 0 length window since we don't need to store anything in the window and we need the query to trigger when an event arrives through the stream. Also we can use the 'current events' (i.e. incoming events) clause to make sure that the 'expired events' (i.e. events kept and emitted by the window) of the window are not considered (refer Siddhi QL documentation on windows for more information).

    eg (assuming sensorStream is the input stream):

    from sensorStream#window.length(0) join Trazablack as t
    select t.sensorValue as sensorValue
    insert current events into StreamBlack;