2.2.1 Types of window operations

Window operations can use any of four types of windows to specify the data to be processed.

The input relation generated by each type of window is explained below.

Organization of this subsection
(1) Specification based on the number of data items (ROWS window)
(2) Specification based on time interval (RANGE window)
(3) Specification based on the time stamp of the arriving tuple (NOW window)
(4) Specification based on data group (PARTITION BY window)

(1) Specification based on the number of data items (ROWS window)

The ROWS window specifies an input relation range based on the number of tuples.

For example, if you want the three most recent tuples from the input stream data s1 to be in the input relation, enter the CQL as follows:

SELECT ... FROM s1 [ROWS 3]...

The following figure shows the content of the input relation in this case.

Figure 2-3 ROWS window example

[Figure]

If tuple D arrives when there are already three tuples (A, B, and C) in the input relation, the most recent three tuples, including the newly arrived tuple, are now in the input relation. In this case, the oldest tuple (A) is removed from the input relation.

(2) Specification based on time interval (RANGE window)

The RANGE window specifies an input relation range based on a time interval.

For example, if you want the last three seconds of input stream data s2 to be in the input relation, enter the CQL as follows:

SELECT ... FROM s2 [RANGE 3 SECOND]...

The following figure shows the content of the input relation in this case.

Figure 2-4 RANGE window example

[Figure]

When tuple C arrives, the tuples from the last three seconds are in the input relation. After tuple C is added to the input relation, tuple B becomes the oldest tuple that is less than 3 seconds old, and as a result tuple A is removed from the input relation.

(3) Specification based on the time stamp of the arriving tuple (NOW window)

The NOW window uses only the time stamp of the arriving tuple to determine the data to be operated on.

Whereas the input relations specified by the other windows are line relations having a count or time range, the NOW window makes a point relation using the time stamp of the arriving tuple to determine the target of operation.

For example, for the input stream data s3, to make the tuple having the same time stamp as the arriving tuple the operation target, the CQL is defined as follows:

SELECT ... FROM s3 [NOW]

(4) Specification based on data group (PARTITION BY window)

The PARTITION BY window specifies an input relation range based on the number of tuples for each tuple type.

For example, for the input stream data s4, to keep the last three tuples for each value in the column specification list a1 in the input relations, enter the CQL as follows:

SELECT ... FROM s4 [PARTITION BY a1 ROWS 3]

The following figure shows the content of the input relation in this case.

Figure 2-5 PARTITION BY window example

[Figure]

Column a1 has a value of either x or y, and for each of these the last three tuples are kept in the input relation. When a new tuple having the value y for column a1 arrives, the oldest tuple (tuple D) having the value y for column a1 is removed from the input relation.