This subsection gives examples of the following two types of query definitions in which time division is specified:
In this example, a relation operation using an aggregate function is performed on the arriving tuples that are in the 1-minute RANGE window. The following stream is handled in this example:
In the following definition example, the sum total of the column price in the stream stock is determined from the tuples that are in the RANGE window.
REGISTER STREAM stock(price INTEGER, name VARCHAR(10)); ...(1) |
The name of the query in which time division is used is ql specified in (3). Therefore, the query name ql is also specified in the QUERY_ATTRIBUTE statement in (2).
In this example, the sum total of the column price is determined using time division for the stream stock specified in (1). Therefore, stock is specified for the STREAM_NAME= data identifier in (2) and the aggregate function SUM (price) is specified for TARGETS=.
If you want to determine the maximum or minimum value instead of the sum total, specify the aggregate function MAX or MIN.
In the following definition example, the sum total, maximum value, and minimum value of the column price in the stream stock are determined from the tuples in the RANGE window.
REGISTER STREAM stock(price INTEGER, name VARCHAR(10)); |
When using time division, you cannot execute multiple aggregate functions for the same column name of the same data identifier at the same time. For example, you cannot specify TARGETS=SUM(price),MAX(price),MIN(price) for a query on column name price of the data identifier stock.
When specifying multiple aggregate functions, you must provide separate column names as the targets of the aggregate functions. In this example, the individual aggregate functions SUM, MAX, and MIN are executed after the column name is changed from price to price0, price1, and price2, respectively.