Defining stream queries
A stream query operates on one or two streams to transform their contents into a single output stream. A stream query definition declares an identifier for the items in the stream so that the item can be referred to by the operators in the stream query. Here is a simple stream query definition:
stream<integer> ints := from a in sA select a.i;
When the correlator executes a statement that contains a stream query definition, the correlator creates a new stream query. Each stream query has an output stream (the type of which might differ from that of the input stream).
A stream query definition is an expression that evaluates to a stream value. The value is a reference to the output stream of the generated query.
Following is an example of a simple stream query in a stream listener:
from a in sA select a.b as b {
doSomethingWith(b);
}
The following table describes the user-defined parts of this stream listener. It is important to understand the distinctive role each one serves.
Syntax Element | Description |
a | |
sA | This variable represents the stream being queried. |
a.b | This expression describes what each query result looks like. In this example, the query produces outputs from the b field of the events in the stream. |
b | This is the variable that you coassign the query results to so that the correlator can use the query result in the stream listener's code block. |