Apama 10.15.0 | Developing Apama Applications | Developing Apama Applications in EPL | Working with Streams and Stream Queries | Defining stream queries | Stream query definition syntax
 
Stream query definition syntax
A stream query definition contains several elements, some of which are optional and some of which are required. These elements, and their constituent parts, are described in the following sections. The elements appear in a stream query in this order:
FromClause [ FromClause | JoinClause ] [ WhereClause ] ProjectionDefinition
Element
Required or Optional
Description
FromClause
Required
Specifies the input stream for the query. See Specifying input streams in from clauses.
A from clause can also specify which items from the input stream the query should operate on. See Adding window definitions to from and join clauses.
If a second from clause appears, the correlator performs a cross-join to combine items from the two streams. See Defining cross-joins with two from clauses.
JoinClause
Optional
Specifies a second stream for the query to operate on. The correlator performs an equi-join to combine items from the two streams. See Defining equi-joins with the join clause.
A join clause can also specify which items from the input stream the query should operate on. See Adding window definitions to from and join clauses.
WhereClause
Optional
Applies a filtering criterion to the items in the window or the items produced by the join operation. See Filtering items before projection.
ProjectionDefinition
Required
Defines how the query generates output items. See Generating query results.
Identifier scope in stream queries
Consider the following code fragment:
integer a;
stream<float> prices := from a in ticks select a.price;
In this example, the a in the query refers to the current Tick item in the stream and not to the a integer variable. In a stream query, you can use an identifier that you have not previously declared. If there is a variable in a containing scope that has the same name as an identifier in the query, then for expressions in the query the identifier in the query hides the variable in the containing scope.
Following is another example of how scope works with stream queries:
integer a := 42;
from a in ticks select a.price as p {
   print a.toString(); // Prints "42" rather than one of the ticks. }
The previous code fragment illustrates that identifiers in the listener action can have the same names as identifiers in the stream query. While this is not good practice, it is important to recognize that the listener action is not part of the stream query. Consequently, an identifier in a stream query is out-of-scope in the stream query's listener action.