You will learn

Details

Unlike Streams, which are stateless, Windows are like tables, holding information from one event to the next. Here we will add a aggregate window that is keyed by MACHINEID, holding a set of aggregate values for each machine.

If you want to skip the steps to add this window using the visual editor you can skip to step 8 to view the CCL and copy it into your project.

Step 1: Add an Aggregate Window to the Project

Click on Aggregate in Streams and Windows drawer of the Palette and drop it onto the canvas.

Rename the stream to AVG_TEMP by clicking on Aggregate symbol. Then press the Enter key.

Edit the expression for EVENT_TIME. Change it to: last(DEVICE_EVENTS.EVENT_TIME). This will cause the aggregate values for the group to show the event time of the last event received in the group. Confirm your entry by pressing Enter.

Double click the name EVENT_VALUE and rename this column to AVG_TEMP by typing in the text field. Confirm your entry by pressing Enter.

Double-click on the expression for AVG_TEMP, which is currently set to DEVICE_EVENTS.EVENT_VALUE.

We are now going to edit this expression to compute an average. Also, since the value field is a string, before we can compute an average, we need to convert it to a number. Change the expression to: avg(to_decimal(DEVICE_EVENTS.EVENT_VALUE, 4, 2)). Confirm your entry by pressing Enter.