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 column expressions by double-clicking to open the inline
editor, or by selecting the expressions and pressing
Ctrl+F2 to open the expression in the pop-up
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.
The aggregate element is now valid.
(Optional) Use the Toggle option to change the
aggregate object from LOCAL to OUTPUT.
By making it an output window, you allow external applications to subscribe to
or query it, and you will be able to view it using the Streamviewer in Run-Test
perspective.