Apama 10.11.3 | Developing Apama Applications | EPL Reference | Expressions | Stream queries
 
Stream queries
 
Stream query window definitions
A stream query defines an operation that the correlator applies continuously to one or two streams of items. The output of a stream query is a continuous stream of derived items, stream<X>, where X is the type returned by the expression in the select clause. See also Defining stream queries.
Syntax diagram for stream queries
A from clause specifies a stream that the query is operating on.
An item in a stream can be an event, a simple type (boolean, decimal, float, integer or string) or a location type. The first Identifier is the identifier that represents the current item in the stream you are querying. You use this identifier in subsequent clauses in the stream query.
The first Expression identifies the stream that you want to query.
A stream query window definition is optional. If you do not specify any window then the stream query operates on only the items that arrive on the stream for a given activation of that query. See Stream query window definitions.
A subsequent from clause indicates a cross-join operation.
Alternatively, a subsequent join clause indicates an equi-join operation. An equi-join has a key expression for each of the two streams that are being joined. Two items are joined into an output item only if the values of their key expressions are equal.
A where clause qualifies the items produced from a window or a join operation.
A group by clause organizes the qualified items, or the items produced from a window or join operation.
A having clause filters the output items produced from the projection.
The required select clause specifies how to generate the output items.
Semantic constraints
from Identifier in Expression join Identifier in Expression
The identifier can be any legal identifier and, within the stream query's scope, is associated with items from the source stream and therefore has their type. In a joined stream query, the two identifiers must be distinct.
The expression's result must be a value of some stream type. The correlator evaluates the expression outside the stream query's scope. For example:
stream<A> a := all A();
from a in a ...
This is legal, because the identifier a is not in scope for evaluation of the expression a.
on Expression1 equals Expression2
The correlator evaluates both expressions within the stream query's scope.
Expression1 must contain the first item identifier and cannot contain the second. Expression2 must contain the second item identifier and cannot contain the first.
The two expressions must return the same type, and that type must be a comparable type.
where Expression group by Expression, Expression, ...
The item identifier or identifiers are in scope and should be used in these expressions. The where expression must return a boolean value. The group by expressions can return any comparable types.
having Expression
The item identifier or identifiers are in scope and can be used in this expression. The presence of this clause implies that the projection must be an aggregate projection. The expression must return a boolean value.
You can use one or more aggregate functions in the having expression. In fact, you can use aggregate functions only in having expressions and select expressions.
select [rstream] Expression
The item identifier or identifiers are in scope and can be used in this expression. The expression must return a value.
You can use one or more aggregate functions in a select expression. In fact, you can use aggregate functions only in having expressions and select expressions. If you specify an aggregate function you cannot specify the rstream keyword.