4.3.3 REGISTER QUERY_ATTRIBUTE clause (time division specification)

Organization of this subsection
(1) Format
(2) Function
(3) Operands
(4) Syntax rules
(5) Notes
(6) Usage examples

(1) Format

REGISTER QUERY_ATTRIBUTE::=REGISTER[Figure]QUERY_ATTRIBUTE[Figure]query-name
                   [Figure]STREAM_NAME=data-identifier
                   [Figure]PERIOD=mesh-interval
                   [Figure]TARGETS=aggregate-function-1'('column-name-1')',
                   ..., aggregate-function-N'('column-name-N')'

(2) Function

Specifies time division for a query.

(3) Operands

query-name

Specify a name that is unique in the stream data processing system for the query that is the target of the time division specification immediately following this clause. For details about specifying names, see 3.2.4 Specifying names.

The query name must not be the same as the name specified in another REGISTER QUERY_ATTRIBUTE clause. Also, you must specify the RANGE window in the REGISTER QUERY clause that defines the query that is the target of time division.

data-identifier

Specify the stream name or query name where the column name that is the target of time division is defined. The stream name or query name must be defined before the REGISTER QUERY_ATTRIBUTE clause.

mesh-interval

Specify a mesh interval in milliseconds. The unit ms must be entered.

You cannot specify a value of less than 100 milliseconds. If the mesh interval exceeds the RANGE window interval specified in the query name that is the target for time division, the mesh interval is set to the RANGE window interval.

For example, if the mesh interval is 1,000 milliseconds and the RANGE window interval is 500 milliseconds, the mesh interval is set to 500 milliseconds. If the mesh interval is smaller than the RANGE window interval but is greater than 86,400,000 milliseconds, the mesh interval is set to 86,400,000 milliseconds.

If you specify a value of less than 100 milliseconds, the mesh interval is set to 100 milliseconds.

aggregate-function

Specify an aggregate function. The following table shows the aggregate functions that can be specified here.

Table 4-3 Aggregate functions that can be specified

No.Aggregate functionMeaning
1SUMUsed for calculating the sum total.
2MAXUsed for calculating the maximum value.
3MINUsed for calculating the minimum value.

The number of aggregate functions that can be specified is in the range from 1 to 256.

column-name

Specify the column name that the data identifier specified in STREAM_NAME has.

Each column name must be unique.

The number of column names that can be specified is in the range from 1 to 256.

(4) Syntax rules

None.

(5) Notes

(6) Usage examples

The underline indicates the key parts of the examples.

Example 1:

Determining the sum total of the column price in the stream stock, which is found in a tuple in the RANGE window:

REGISTER STREAM stock(price INTEGER, name VARCHAR(10));
REGISTER QUERY_ATTRIBUTE q1 STREAM_NAME=stock PERIOD=300ms TARGETS=SUM(price);
REGISTER QUERY q1
ISTREAM(
SELECT name, SUM (price) AS s1
FROM stock[RANGE 1 MINUTE]
GROUP BY name
);

This specifies time division for the query q1 specified in the REGISTER QUERY_ATTRIBUTE clause. To obtain the sum total of the column price in the stream stock defined in the REGISTER STREAM clause, stock is specified for the data identifier and SUM(price) is specified for TARGETS. To obtain the maximum or minimum value instead of the total value of price, specify MAX or MIN.

Example 2:

Determining the sum total, the maximum value, and the minimum value of the column price in the stream stock, which is found in a tuple in the RANGE window:

REGISTER STREAM stock(price INTEGER, name VARCHAR(10));
REGISTER QUERY q0
ISTREAM(
SELECT name, price AS price0, price AS price1, price AS price2
FROM stock[NOW]
);
REGISTER QUERY_ATTRIBUTE q1 STREAM_NAME=q0 PERIOD=300ms
TARGETS=SUM(price0),MAX(price1),MIN(price2);
REGISTER QUERY q1
ISTREAM(
SELECT q0.name, SUM(q0.price0) AS sum_price,
MAX(q0.price1) AS max_price, MIN(q0.price2) AS min_price
FROM q0[RANGE 1 MINUTE]
GROUP BY q0.name
);

Note that, to perform more than one aggregate function on the column price of the data identifier stock in the query, you cannot specify the same column name price more than once in TARGETS. That is, you cannot specify TARGETS=SUM(price), MAX(price), MIN(price).

In this case, the column price must be redefined separately for the sum total, the maximum value, and the minimum value. In this example, a data identifier (q0 here) is defined that has columns price0, price1, and price2, which are obtained by cloning the column price using a CQL statement. Using the column names defined in q0 when specifying the operations in q1 allows you to perform multiple aggregate functions on the same data.