2.2.1 Using definition CQL to define streams and queries

CQL statements that are used to define streams and queries are called definition CQL. There are two types of definition CQL.

The following subsections explain how to specify each of these clauses.

Organization of this subsection
(1) Defining a stream (REGISTER STREAM clause)
(2) Defining a query (REGISTER QUERY clause)

(1) Defining a stream (REGISTER STREAM clause)

To define a stream, you use the definition CQL REGISTER STREAM clause.

In the REGISTER STREAM clause, you specify the stream name (the name of the input stream) and the schema specification character string (the content of the stream data that identifies it as the input stream). The following shows the format for specifying a REGISTER STREAM clause:

REGISTER STREAM stream-name
(schema-specification-character-string);

For example, the following shows a CQL statement that defines a stream for a temperature analysis system:

REGISTER STREAM temperature_stream
(observation_time TIME, id INTEGER, temperature INTEGER);

For the stream name, temperature_stream is specified. The parameters observation_time (observation time), id (observation site ID), and temperature (measured temperature) are specified using the TIME, INTEGER, and INTEGER data types, respectively.

(2) Defining a query (REGISTER QUERY clause)

To define a query, you use the definition CQL REGISTER QUERY clause. In the REGISTER QUERY clause, you specify the name of the query, a stream clause, a SELECT clause, a FROM clause, and a WHERE clause, in that order. For the query name, you specify the name of the stream that is to be output after the stream data has been processed by the query (output stream).

The following table shows what the stream clause, SELECT clause, FROM clause, and WHERE clause, which make up the CQL REGISTER QUERY clause, do.

Table 2-1 Correspondence between query actions and clauses in a CQL statement

Clause in a CQL statementQuery action
Stream clauseSpecifies a stream operation action.
SELECT and WHERE clausesSpecifies a relation operation action.
FROM clauseSpecifies a window operation action.

The format for specifying a REGISTER QUERY clause is shown below:

REGISTER QUERY query-name
stream-clause (
SELECT-clause
FROM-clause
WHERE-clause);

The following paragraphs explain the clauses in the REGISTER QUERY clause.

Stream clause
In the stream clause, you specify how to output the stream data. Depending on exactly what you want to do, you can specify an ISTREAM clause, a DSTREAM clause, or an RSTREAM clause. For details about these clauses, see 2.2.2(3) Stream operations (outputting the data processing results).
SELECT clause
In the SELECT clause, you specify the specific data to be extracted from the tuples that are to be processed. To identify the data you want, specify the data item names used in the schema specification character string of the REGISTER STREAM clause. The actual tuples to be processed are determined by the WHERE clause.
FROM clause
In the FROM clause, you specify the name of the stream that the query is to process, and the processing window. Depending on exactly what you want to do, you specify one of these four window types: a ROWS window, a RANGE window, a NOW window, or a PARTITION BY window.
You specify the stream data using the stream name specified in the REGISTER STREAM clause. Following the stream name, you specify the window type and size enclosed in square brackets ([ ]). For details about windows, see 2.2.2(1) Window operations (retrieving data for analysis).
For a query to process a relation, you must specify the name of the relation.
WHERE clause
In the WHERE clause, you specify the criteria for selecting which tuples retrieved from the window are to be processed.

For example, a query following the code for the temperature analysis system described above in (1) Defining a stream (REGISTER STREAM clause) is shown below.

REGISTER STREAM temperature_stream
(observation_time TIME, id INTEGER, temperature INTEGER);
REGISTER QUERY sensor_filter
ISTREAM (
SELECT id, temperature
FROM temperature_stream[ROWS 3]
WHERE id = 1);

The following paragraphs explain the items specified in the above REGISTER QUERY clause.

You can also specify other clauses in the REGISTER QUERY clause that are not described here. For details on these other clauses, see the uCosminexus Stream Data Platform - Application Framework Application Development Guide.