Apama 10.3 | Apama Documentation | Developing Apama Applications | Developing Apama Applications in EPL | Working with Streams and Stream Queries | Defining stream queries | Generating query results
Generating query results
Aggregating items in projections
Filtering items in projections
The last component of a stream is the required projection definition, which specifies how to generate items for the query's output stream. A projection definition has the following syntax:
[group by groupByExpr[, groupByExpr]...] [having havingExpr]
select [rstream] selectExpr
Syntax Element
Each groupByExpr is an expression that returns a value of a comparable type. These expressions form the group key, which determines which group each output item is a part of. Any aggregate functions in the having or select expression operate over each group separately. See Grouping output items.
The havingExpr expression filters output items. See Filtering items in projections.
The value you specify for selectExpr defines the items that are the result of the query. The correlator evaluates selectExpr to generate each item that appears in the query's output stream. The type of selectExpr identifies the type of the query's output stream.
A projection can be one of the following kinds:
*A simple projection does not specify any aggregate functions, nor does it specify a group by or having clause. A simple projection can be a simple istream projection or a simple rstream projection.
*An aggregate projection specifies at least one aggregate function across the having and select expressions.
You can specify a group by clause as part of an aggregate projection. If there is a group by clause, the group key must be one or more expressions that take the input event and return a value of a comparable type.
You cannot specify rstream in an aggregate projection.
The following table describes the kinds of expressions that can appear in the select expression for each type of projection. In more complex expressions, the rules apply similarly to each sub-expression within that expression.
Kind of Expression
Valid in Projections
Non-item expression
Simple and aggregate
An external variable, constant, or method call. It does not refer to any of the input items.
select currentTime;
Item expression
A reference to the input item or a non-aggregate expression that contains at least one reference to the input item.
select a.i;
select sqrt(a.x)*5.0/a.y
Group key expression
An expression that returns one of the group keys can also occur in the projection.
group by a.i/10 select (a.i/10)*mean(a.x);
Aggregate function expression
An expression that contains at least one aggregate function. Arguments to the aggregate function can include item expressions.
select mean(a.i);
Note: An expression might not be syntactically equivalent to a group by expression even though it might appear to be equivalent. For example, if the group by expression is a.i*10, you cannot specify 10*a.i as an equivalent expression. An equivalent group by expression must contain the exact sub-expression specified in the group by clause.

Copyright © 2013-2018 | Software AG, Darmstadt, Germany and/or Software AG USA, Inc., Reston, VA, USA, and/or its subsidiaries and/or its affiliates and/or their licensors.