Aggregate Operator Time Dimension Sample

This topic describes AggregateByTime.sbapp, the Aggregate operator time dimension sample.

Running AggregateByTime.sbapp in StreamBase Studio

This sample demonstrates use of the time-based Aggregate operator. The time-based aggregate uses elapsed time to manage windows. This example uses 2-second windows to compute average price per share of symbols.

  1. In the Package Explorer, double-click to open the AggregateByTime.sbapp application. Make sure the application is the currently active tab in the EventFlow Editor.

  2. Click the Run button. This opens the SB Test/Debug perspective and starts the application.

  3. No output is displayed in the Application Output view yet, but the dequeuer is prepared to receive output. This view will eventually show the output of the application.

  4. In the Feed Simulations view, right click on AggregateByTime.sbfs and select Run Feed Simulation.

  5. Observe application output in the Application Output view. The format is similar to the following:

    Symbol=MSFT, TimeBasedAverage=26.05, start_time=2007-04-26 13:05:26.000-0400, 
        end_time=2007-04-26 13:05:28.000-0400
    Symbol=AAPL, TimeBasedAverage=43.95, start_time=2007-04-26 13:05:26.000-0400, 
        end_time=2007-04-26 13:05:28.000-0400

    Tip

    If output rows are too long to see all the data, click a row to display its fields in the Display Fields pane below the table.

    Average, start, and end times will all vary depending on the rate of input. For example, the first time you run the sample, the first tuple may occur just before the 2-second boundary and the second time it may occur just after the 2-second boundary. The averages will be different because the tuples are seen in different windows.

  6. When done, press F9 or click the Stop Running Application button.

Running AggregateByTime.sbapp in Terminal Windows

This section describes how to run the sample in UNIX terminal windows or Windows command prompt windows. On Windows, be sure to use the StreamBase Command Prompt from the Start menu as described in the Test/Debug Guide, not the default command prompt.

  1. Open three terminal windows on UNIX, or three StreamBase Command Prompts on Windows. In each window, navigate to the directory where the sample is installed, or to your workspace copy of the sample, as described above.

  2. In window 1, type:

    sbd AggregateByTime.sbapp

  3. In window 2, type:

    sbc dequeue AvgOut

    No output is displayed at this point, but the dequeuer is prepared to receive output. This window will eventually show the output of the application.

  4. In window 3, type:

    sbfeedsim ResourceFiles\AggregateByTime.sbfs

    Data starts flowing into the application. Observe several lines in the dequeue window, similar to the following:

    MSFT,26.05,2007-04-26 13:29:52.000-0400,2007-04-26 13:29:54.000-0400
    AAPL,43.95,2007-04-26 13:29:52.000-0400,2007-04-26 13:29:54.000-0400

    Average, start, and end times all vary depending on where the tuples fall relative to the wall-clock time. For example, the first time you run the sample, the first tuple may occur just before the 2-second boundary and the second time may occur just after the 2-second boundary. The averages will be different because the tuples occur in different windows. The start times and end times will, of course, be different.

  5. In window 3, type sbadmin shutdown to terminate the daemon and dequeuer.

Importing This Sample into StreamBase Studio

In StreamBase Studio, import this sample with the following steps:

  • From the top menu, click FileLoad StreamBase Sample.

  • Select operator from the Data Constructs and Operators category.

  • Click OK.

StreamBase Studio creates a single project for the all operator samples.

Sample Location

By default, the sample files are installed in:

  • On Windows: C:\Program Files\StreamBase Systems\StreamBase.n.m\sample\operator

  • On UNIX: /opt/streambase/sample/operator

When you load the sample into StreamBase Studio, Studio copies the sample project's files to your Studio workspace. StreamBase Systems recommends that you use the workspace copy of the sample, especially on UNIX, where you may not have write access to /opt/streambase. In the default installation, the path to this sample in your Studio workspace is:

UNIX:       
  ~/streambase-studio-n.m-workspace/sample_operator
Windows XP:
  C:\Documents and Settings\username\My Documents\StreamBase Studio n.m Workspace\sample_operator
Windows 7 and Windows Vista:
  C:\Users\username\Documents\StreamBase Studio n.m Workspace\sample_operator