Table and Store

Provides introduction to in-memory tables and database backed stores that can be used to store events.

For information on various types of stores, primary keys, indexes, and caching, refer examples related to Event Store Integration and Siddhi query guide.

define stream TemperatureStream (
        sensorId string, temperature double);

define table TemperatureLogTable (
        sensorId string, roomNo string, temperature double);

@store(type="rdbms",
       jdbc.url="jdbc:mysql://localhost:3306/sid",
       username="root", password="root",
       jdbc.driver.name="com.mysql.jdbc.Driver")
define table SensorIdInfoTable (
        sensorId string, roomNo string);

@info(name = 'Join-query')
from TemperatureStream as t join SensorIdInfoTable as s
     on t.sensorId == s.sensorId
select t.sensorId as sensorId, s.roomNo as roomNo
       t.temperature as temperature
insert into TemperatureLogTable;
define stream TemperatureStream (
        sensorId string, temperature double);

Defines TemperatureStream stream having sensorId and temperature attributes of types string and double.

define table TemperatureLogTable (
        sensorId string, roomNo string, temperature double);

Defines in-memory TemperatureLogTable having sensorId, roomNo, and temperature attributes of types string, string, and double.

@store(type="rdbms",
       jdbc.url="jdbc:mysql://localhost:3306/sid",
       username="root", password="root",
       jdbc.driver.name="com.mysql.jdbc.Driver")

Store annotation to back SensorIdInfoTable by a MySQL RDBMS with sid DB and SensorIdInfoTable table.

define table SensorIdInfoTable (
        sensorId string, roomNo string);

Defines SensorIdInfoTable table.

@info(name = 'Join-query')
from TemperatureStream as t join SensorIdInfoTable as s
     on t.sensorId == s.sensorId

TemperatureStream with alias t joins with SensorIdInfoTable with alias s based on sensorId.

select t.sensorId as sensorId, s.roomNo as roomNo
       t.temperature as temperature
insert into TemperatureLogTable;

Selects sensorId, roomNo, and temperature attributes from stream and table, and adds events to TemperatureLogTable.

Event at table and store

When SensorIdInfoTable table contains a recode ['aq-14', '789'], and when an event with values ['aq-14', 35.4] is sent to TemperatureStream stream.

The event will get converted and added to the TemperatureLogTable table as below.

['aq-14', '789', 35.4]

Retrieving values from tables and stores

The stored values can be retrieved by join tables and stores with the streams as in the Join-query depicted in the example, or using on-demand queries.

The data in TemperatureDetailsTable can be retrieved via on-demand queries as below, using the On Demand Query REST API or by calling query() method of SiddhiAppRuntime.

from TemperatureDetailsTable
select *
Top