This subsection provides examples of individual window operations.
Assuming stream data with the configuration shown in the following figure arrives, the input relation created by the specification of each window is explained.
Figure 2-6 Configuration of the tuples used in the window operation examples
The horizontal axis in the figure shows time, increasing from left to right. Times t1 to t6 indicate the time at which tuples arrived. Each tuple consists of a stock name and a rate of price increase.
This subsection shows an example of a window operation that specifies [ROWS 3]. This specification means that the number of tuples in the input relation is three.
The following figure shows lifespan of each tuple in the input relation when [ROWS 3] is specified.
Figure 2-7 Lifespan of each tuple in the input relation when [ROWS 3] is specified
As the time passes from t1 to t2 to t3, tuples (Stock A, 1.0), (Stock A, 0.8), and (Stock B, 1.1) arrive sequentially and are included in the input relation.
When the tuple (Stock A, 1.0) arrives at time t4, the number of tuples in the input relation exceeds three, and the oldest tuple in the input relation expires. In this example, the tuple (Stock A, 1.0) generated at time t1 is deleted from the input relation and the tuple (Stock A, 1.0) that arrived at time t4 is newly added to the input relation.
This subsection shows an example of a window operation that specifies [RANGE 1 SECOND]. This specification means that lifespan of any given tuple will only be one second in the input relation.
Each tuple included in the input relation disappears after one second regardless of the number of tuples that arrive subsequently.
The following figure shows the lifespan of each tuple in the input relation when [RANGE 1 SECOND] is specified.
Figure 2-8 Lifespan of each tuple in the input relation when [RANGE 1 SECOND] is specified
Tuples that arrive at time t1 to t4 disappear after one second regardless of when other tuples arrive.
This subsection shows an example of a window operation that specifies [NOW]. This specification means that the input relation only contains the time stamp of the current tuple.
The following figure shows the lifespan of each tuple in the input relation when [NOW] is specified.
Figure 2-9 Lifespan of each tuple in the input relation when [NOW] is specified
When [NOW] is specified, the tuple only exists in the input relation when it arrives. Once an operation is performed on the tuple, it disappears from the input relation.
This subsection shows an example of a window operation that specifies [PARTITION BY stock-name ROWS 1]. This specification means that the number of tuples specified by the ROWS operand are included in the input relation for each stock name.
The following figure shows the lifespan of each tuple in the input relation when [PARTITION BY stock-name ROWS 1] is specified.
Figure 2-10 Lifespan of each tuple in the input relation when ([PARTITION BY stock-name ROWS 1] is specified
When this is specified, one tuple is included for Stock names A and B.
When the new tuple (Stock A, 0.8) arrives at time t2 while the tuple (Stock A, 1.0), which arrived at time t1, is still in the input relation, the older tuple (Stock A, 1.0) disappears and is replaced with the tuple (Stock A, 0.8). If the tuple (Stock B, 1.1) subsequently arrives at time t3, the tuple (Stock A, 0.8) does not disappear since the new arrival is for a different stock, and the new tuple (Stock B, 1.1) is included in the input relation. The tuple (Stock A, 0.8), which arrived at time t2, stays in the input relation until the newer tuple (Stock A, 1.0) arrives at time t4, and the tuple (Stock B, 1.1), which arrived at time t3, stays in the input relation until the newer tuple (Stock B, 1.3) arrives at time t6.