Striim 3.9.4 / 3.9.5 documentation

Understanding windows in custom functions

As you work with multiple rows of data, Striim provides you with the support you need to use sliding windows of data. To understand how this works, consider the following complete dataset:

OrderID

OrderDate

OrderValue

1111

1/1/2016

111.11

2222

2/1/2016

222.22

3333

3/1/2016

333.33

4444

4/1/2016

444.44

5555

5/1/2016

555.55

6666

6/1/2016

666.66

7777

7/1/2016

777.77

8888

8/1/2016

888.88

9999

9/1/2016

999.99

The following describes how the dataset is treated in a sliding window in which up to 3 rows of data at a time are included.

Initialization

When your object is initialized, you do not yet have a working record (a row of data), and the window has no data yet. Consider the following TQL statement:

SELECT
  AVG(OrderValue),
  OrderID,
  OrderDate,
  OrderValue
FROM
  STREAM_ST

As you learned in Developing multi-row functions, the getAggValue() function defines return values, the incAggValue() function defines incremental logic, and decAggValue() defines decremental logic.

At the time of initialization, the running sum and count for the data would each be zero.

First row

Using the dataset above, the incAggValue() function adds the first row to the window, and the getAggValue() function is called and adds those values to the running sum and count.

Here is the state of the data at this point. The working record is:

OrderID

OrderDate

OrderValue

1111

1/1/2016

111.11

The window is:

OrderID

OrderDate

OrderValue

1111

1/1/2016

111.11

Sum: 111.11

Count: 1

AVG: 111.11

Second row

Using the dataset above, the incAggValue() function adds the second row to the window, and the getAggValue() function is called and adds those values to the running sum and count.

Here is the state of the data at this point. The working record is:

OrderID

OrderDate

OrderValue

2222

2/1/2016

222.22

The window is:

OrderID

OrderDate

OrderValue

1111

1/1/2016

111.11

2222

2/1/2016

222.22

Sum: 333.33

Count: 2

AVG: 166.65

Third row

Using the dataset above, the incAggValue() function adds the third row to the window, and the getAggValue() function is called and adds those values to the running sum and count.

Here is the state of the data at this point. The working record is:

OrderID

OrderDate

OrderValue

3333

3/1/2016

333.33

The window is:

OrderID

OrderDate

OrderValue

1111

1/1/2016

111.11

2222

2/1/2016

222.22

3333

3/1/2016

333.33

Sum: 666.66

Count: 3

AVG: 222.22

Fourth row

Up till now, since the sliding window could contain up to 3 rows, for each new row the incAggValue() function added the new row to the window, and the getAggValue() function was called and added those values to the running sum and count. With a 4th row, this algorithm changes. The decAggValue() function is called to remove the 1st row, the incAggValue() function adds the 4th row to the window, and the getAggValue() function is called and adds those values to the running sum and count.

Here is the state of the data at this point. The working record is:

OrderID

OrderDate

OrderValue

4444

4/1/2016

444.44

The window now only includes rows 2-4 and excludes row 1, and the count holds steady at 3 rows:

OrderID

OrderDate

OrderValue

2222

2/1/2016

222.22

3333

3/1/2016

333.33

4444

4/1/2016

444.44

Sum: 999.99

Count: 3

AVG: 333.33

Toward the end

The trend continues as new rows are added: a row is dropped in order to add the new row, and the values are updated. Eventually, as input events cease and windowed events being to timeout, only the decAggValue() and getAggValue()functions are called.