Sample 0105 - Performing Joins with windows
Introduction
This sample demonstrates how to set up an execution plan with time windows and length windows and perform a join (with a condition) to trigger an output. This sample uses Event Simulator for inputs and the logger publisher for logging the outputs to the DAS console.
The execution plan used in this sample is as follows:
from TempStream[temp > 30.0]#window.time(1 min) as T join RegulatorStream[isOn == false]#window.length(1) as R on T.roomNo == R.roomNo select T.roomNo, T.temp, R.deviceID, 'start' as action insert into RegulatorActionStream ;
The first query does the following.
- Processes the events received through the
TempStream
, filters events withtemp > 30.0
condition and inserts the events that satisfy the filter condition into a 1-minute time window (renamed asT
). - Filters events coming through the
RegulatorStream
with theisOn == false
condition, and inserts the events that satisfy the condition into a length window of 1 event (renamed asR
). - Performs a join between the above two windows, with the condition
T.roomNo == R.roomNo
, this creates tuples consisting of the events matching this condition as in SQL. - Selects the
roomNo
fromT
events,temp
fromT
events,deviceID
fromR
, and also inserts an additional attribute namedaction
with the valuestart
. - Emits those events as output events through the
RegulatorActionStream
stream.
Prerequisites
Set up the prerequisites required for all samples.
Building the sample
Start the WSO2 DAS server with the sample configuration numbered 0105. For instructions, see Starting sample CEP configurations.
This sample configuration points the default Axis2 repo to <DAS_HOME>/samples/cep/artifacts/0105
(by default, the Axis2 repo is <DAS_HOME>/repository/deployment/server
).
Executing the sample
Log into the DAS management console that is located at
https://<DAS_HOST>:<DAS_PORT>/carbon
.- Go to Tools -> Event Simulator. The following files are displayed under the Send multiple events section.
events.csv
: This file contains sample events to simulate the event flow of the event stream namedTempStream:1.0.0
.regularEvents.csv
: This file contains sample events to simulate the event flow of the event stream namedRegularStream:1.0.0
.
View the output events received from the DAS console. This sample uses the logger adaptor to log output events to the console.
The output of the consumer sending events from the producer is logged as shown in the following example.