Add to the sample diagram an Aggregate simple query to create a volume weighted average price (VWAP).
An Aggregate query groups events that have common values, and computes summary statistics for the group.
- In the Visual editor Palette, in Streams and
Windows, click
Aggregate.
- Click in the diagram to create the object.
- Change the default name, Aggregate1, to VWAP.
- Connect PriceFeed to the VWAP aggregate:
- Click the Connector tool in the
Palette.
- Click the PriceFeed input
window, then click the VWAP aggregate.
Click the shape that produces the output first, then the shape
that receives the data, to indicate the direction of data
flow.
Watch for visual indicators that show you when the connection is valid.
Indicator |
Meaning |
|
Connection is allowed |
 |
Connection is not allowed |
- Enter Column Expressions:
- Click Copy Columns from Input
(
) in the shape toolbar to select the columns to
copy into the schema for the aggregate window. For this example, copy these columns:
- PriceFeed.Symbol
- PriceFeed.TradeTime
- PriceFeed.Price
- Edit column names to clarify that these columns will hold the most
recent price and time for the group:
- Change TradeTime to LastTime
- Change Price to LastPrice
- Add
additional columns by clicking Add Column
Expression
in
the shape toolbar.
For this example, add another column and edit its name to
VWAP.
- Edit a column
expression by double-clicking to open the inline editor, by selecting one of the tabs in
the Properties view, or by selecting an expression and pressing
Ctrl+F2 to edit it using the pop-up expression
editor.
For this example, edit the VWAP column expression to:
sum ( PriceFeed.Price *
PriceFeed.Shares ) /
sum ( PriceFeed.Shares )
- Click Add GroupBy Clause ({
}) to edit the grouping of columns in the aggregate
object.
Note: The Aggregate shape must have exactly one GROUP BY expression.
For this example, select PriceFeed.Symbol as the
grouping column.
The red warning border disappears, indicating that
the element is now valid.
By default, the Aggregate is created as Output, which allows
external applications to subscribe to or query it, and allows you to view it using the
StreamViewer in the SAP Sybase ESP Run-Test
perspective.