Apama Documentation : Developing Apama Applications : EPL Streams: A Quick Tour : Common stream query patterns : Aggregation in stream queries
Aggregation in stream queries
Examples in earlier topics show the calculation of running averages of the temperature and pressure readings. A common use-case, illustrated below, is the calculation of the volume-weighted average price of a stock. This example uses the weighted-average aggregate function, wavg().
01. using com.apama.aggregates.wavg;
02. event Tick { string symbol; decimal price; decimal volume; }
03. monitor CalculateVwap {
04. action onload() {
05. decimal vwap;
06. from t in all Tick(symbol="SOW") within 300.0
07. select wavg(t.price,t.volume): vwap {
07. print vwap.toString();
08. }
09. }
10. }
Aggregation can also be used in combination with group by to generate the aggregate results for different groups of items, as illustrated in the code examples in Using partitions and groups in stream queries. Note that code authors are not restricted to the set of built-in aggregates as it is possible to define custom aggregates.
Copyright © 2013-2016 Software AG, Darmstadt, Germany.

Product LogoContact Support   |   Community   |   Feedback