Skip to main content

Partitions

Partitions divide streams and queries into isolated groups in order to process them in parallel and in isolation. A partition can contain one or more queries and there can be multiple instances where the same queries and streams are replicated for each partition.

Each partition is tagged with a partition key. Those partitions only process the events that match the corresponding partition key.

Purpose

Partitions allow you to process the events groups in isolation so that event processing can be performed using the same set of queries for each group.

Generate Partition Key

A partition key can be generated by value or by range.

Partition by Value

This is created by generating unique values using input stream attributes.

Syntax

partition with ( <expression> of <stream name>,
<expression> of <stream name>, ... )
begin
<query>
<query>
...
end;

Example

This query calculates the maximum temperature recorded within the last 10 events per deviceID.

partition with (deviceID of TempStream)
begin
insert into DeviceTempStream
select roomNo, deviceID, max(temp) as maxTemp
from TempStream window sliding_length (10);
end;

Partition by Range

This is created by mapping each partition key to a range condition of the input streams numerical attribute.

Syntax

partition with ( <condition> as <partition key> or
<condition> as <partition key> or ... of <stream name>,
... )
begin
<query>
<query>
...
end;

Example

This query calculates the average temperature for the last 10 minutes per office area.

partition with ( roomNo >= 1030 as 'serverRoom' or
roomNo < 1030 and roomNo >= 330 as 'officeRoom' or
roomNo < 330 as 'lobby' of TempStream)
begin
insert into AreaTempStream
select roomNo, deviceID, avg(temp) as avgTemp
from TempStream window sliding_time(10 min)
end;