Stream Join

Provides examples on joining two stream based on a condition.

For more information on other join operations refer the Siddhi query guide.

define stream TemperatureStream
        (roomNo string, temperature double);

define stream HumidityStream
        (roomNo string, humidity double);

@info(name = 'Equi-join')
from TemperatureStream#window.unique:time(roomNo, 1 min) as t
    join HumidityStream#window.unique:time(roomNo, 1 min) as h
    on t.roomNo == h.roomNo
select t.roomNo, t.temperature, h.humidity
insert into TemperatureHumidityStream;

@info(name = 'Join-on-temperature')
from TemperatureStream as t
    left outer join HumidityStream#window.time(1 min) as h
    on t.roomNo == h.roomNo
select t.roomNo, t.temperature, h.humidity
insert into EnrichedTemperatureStream;
define stream TemperatureStream
        (roomNo string, temperature double);
define stream HumidityStream
        (roomNo string, humidity double);
@info(name = 'Equi-join')
from TemperatureStream#window.unique:time(roomNo, 1 min) as t
    join HumidityStream#window.unique:time(roomNo, 1 min) as h
    on t.roomNo == h.roomNo

Join latest temperature and humidity events arriving within 1 minute for each roomNo.

select t.roomNo, t.temperature, h.humidity
insert into TemperatureHumidityStream;
@info(name = 'Join-on-temperature')
from TemperatureStream as t

Join when events arrive in TemperatureStream.

    left outer join HumidityStream#window.time(1 min) as h
    on t.roomNo == h.roomNo

When events get matched in time() window, all matched events are emitted, else null is emitted.

select t.roomNo, t.temperature, h.humidity
insert into EnrichedTemperatureStream;

Join Behavior

When events are sent to TemperatureStream stream and HumidityStream stream, following events will get emitted at TemperatureHumidityStream stream via Equi-join query, and EnrichedTemperatureStream stream via Join-on-temperature query.

Time Input to TemperatureStream Input to HumidityStream Output at TemperatureHumidityStream Output at EnrichedTemperatureStream
9:00:00 ['1001', 18.0] - - ['1001', 18.0, null]
9:00:10 - ['1002', 72.0] - -
9:00:15 - ['1002', 73.0] - -
9:00:30 ['1002', 22.0] - ['1002', 22.0, 73.0] ['1002', 22.0, 72.0],
['1002', 22.0, 73.0]
9:00:50 - ['1001', 60.0] ['1001', 18.0, 60.0] -
9:01:10 - ['1001', 62.0] - -
9:01:20 ['1001', 17.0] - ['1001', 17.0, 62.0] ['1001', 17.0, 60.0],
['1001', 17.0, 62.0]
9:02:10 ['1002', 23.5] - - ['1002', 23.5, null]
Top