Aggregate Operator Time Dimension Sample

About This Sample

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

Importing This Sample into StreamBase Studio

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

  • From the top-level menu, click File>Import Samples and Community Content.

  • Enter sample group to narrow the list of options.

  • Select Operator sample group from the Data Constructs and Operators category.

  • Click Import Now.

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

Running This Sample 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, grouping its computations by stock symbol.

  1. In the Project Explorer view, open the sample you just loaded.

    If you see red marks on a project folder, wait a moment for the project to load its features.

    If the red marks do not resolve themselves after a minute, select the project, right-click, and select Maven>Update Project from the context menu.

  2. Open the src/main/eventflow/com.tibco.sb.sample.operator folder.

  3. Open the AggregateByTime.sbapp file and click the Run button. This opens the SB Test/Debug perspective and starts the module.

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

  5. In the Feed Simulations view, right click AggregateByTime.sbfs and select Run.

  6. Observe tuples as they pass through the Output Streams view. The format is similar to the following:

    12:06:42 AvgOut stock=MSFT, TimeBasedAverage=26.05, 
        start_time=2013-12-05 12:06:40.000-0500, end_time=2013-12-05 12:06:42.000-0500, 
        first_time=2013-12-05 12:06:40.513-0500, last_time=2013-12-05 12:06:41.620-0500, n=4
    12:06:44 AvgOut stock=AAPL, TimeBasedAverage=43.95, 
        start_time=2013-12-05 12:06:42.000-0500, end_time=2013-12-05 12:06:44.000-0500, 
        first_time=2013-12-05 12:06:42.223-0500, last_time=2013-12-05 12:06:43.725-0500, n=4

    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.

    Each row is an average for a group. The output fields represent the following, per window:

    • Symbol — The stock symbol, used to sort tuples into groups

    • Average — Time-based Average price per share, calculated with the aggregate function avg()

    • start_time — The time the window opened (its openval())

    • end_time — The time the window closed (its closeval())

    • first_time — Time at which the first tuple arrived in the window (firstval(time))

    • last_time — Time at which the last tuple arrived in the window (lastval(time))

    • n — The number of tuples over which average price per share was computed (count())

    Averages and 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.

  7. When the feed simulation stops, observe how emission occurs in two seconds (the difference between end_time and start_time is 2.0) regardless of whether the operator continues to receive input. If you rerun the sample and speed up or slow down the feed simulation, notice n goes down or up, accordingly.

  8. Click the Manual Input tab, type a string for Symbol and number for PricePerShare, and then click Send Data. After two seconds, observe the operator time out and emit output.

  9. When done, press F9 or click the Terminate EventFlow Fragment button.

Sample Location

When you load the sample into StreamBase® Studio, Studio copies the sample project's files to your Studio workspace, which is normally part of your home directory, with full access rights.

Important

Load this sample in StreamBase® Studio, and thereafter use the Studio workspace copy of the sample to run and test it, even when running from the command prompt.

Using the workspace copy of the sample avoids permission problems. The default workspace location for this sample is:

studio-workspace/sample_operator

See Default Installation Directories for the default location of studio-workspace on your system.