Creating an Aggregate as a Simple Query

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.

  1. In the Visual editor Palette, in Streams and Windows, click aggregate_template.gif Aggregate.
  2. Click in the diagram to create the object.
  3. Change the default name, Aggregate1, to VWAP.
  4. Connect PriceFeed to the VWAP aggregate:
    1. Click the Connector tool in the Palette.
    2. 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_allowed.gif Connection is allowed
      not_allowed Connection is not allowed
  5. Enter Column Expressions:
    1. Click Copy Columns from Input (copycolumn.gif) 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
    2. 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
    3. Add additional columns by clicking Add Column Expression compute_template.gif in the shape toolbar.

      For this example, add another column and edit its name to VWAP.

  6. 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 )
  7. 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.
Related concepts
Simple Queries