Stream and Query

Provides introduction to streams, queries, and how queries can be chained to one another.

There are multiple type of queries such as window query, join query, pattern query, etc. But this example only explains how pass-through and selection queries work. For more info refer the Siddhi query guide.

define stream InputTemperatureStream (
                  sensorId string, temperature double);

@info(name = 'Pass-through')
from InputTemperatureStream
select *
insert into TemperatureAndSensorStream;

@info(name = 'Simple-selection')
from TemperatureAndSensorStream
select temperature
insert into TemperatureOnlyStream;
define stream InputTemperatureStream (
                  sensorId string, temperature double);

Defines InputTemperatureStream stream to pass events having sensorId and temperature attributes of types string and double.

@info(name = 'Pass-through')

Optional @info annotation to name the query.

from InputTemperatureStream
select *
insert into TemperatureAndSensorStream;

Query to consume events from InputTemperatureStream, produce new events by selecting all the attributes from the incoming events, and outputs them to TemperatureStream.

@info(name = 'Simple-selection')
from TemperatureAndSensorStream

Consumes events from TemperatureAndSensorStream. The schema of the stream is inferred from the previous query, hence no need to be defined.

select temperature
insert into TemperatureOnlyStream;

Selects only the temperature attribute from events, and outputs to TemperatureOnlyStream.

Events at each stream

When an event with values ['aq-14', 35.4] is sent to InputTemperatureStream stream it will get converted and travel through the streams as below.

  • InputTemperatureStream : ['aq-14', 35.4]
  • TemperatureAndSensorStream : ['aq-14', 35.4]
  • TemperatureOnlyStream : [35.4]
Top