This topic describes
AggregateByTime.sbapp, the Aggregate operator time dimension sample.
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.
In the Project Explorer, open the sample you just loaded.
Open the package folder (most samples contain a single package folder. Open the top-level package folder if your sample contains more than one folder).
AggregateByTime.sbappapplication and click the Run button. This opens the SB Test/Debug perspective and starts the application.
If you see red marks, wait a moment for the project in Studio to load its features.
If red marks do not resolve themselves in a moment, select the project and right-click→ from the context menu.
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.
In the Feed Simulations view, right click on
AggregateByTime.sbfsand select .
Observe application output in the Application Output 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
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
end_time — The time the window closed (its
first_time — Time at which the first tuple arrived in the window (
last_time — Time at which the last tuple arrived in the window (
n — The number of tuples over which average price per share was computed (
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.
When the feed simulation has stopped, you can 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 run again, speeding up or slowing down the feed simulation, you will see n go down or up, accordingly.
Click the Manual Input tab, type a string for Symbol and number for PricePerShare, and then hit. After two seconds, you will observe the operator time out and emit output.
When done, press F9 or click the Stop Running Application button.
In StreamBase Studio, import this sample with the following steps:
From the top menu, click→ .
operatorto narrow the list of options.
Select Operator sample group from the Data Constructs and Operators category.
StreamBase Studio creates a single project for the all operator samples.
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.
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:
See Default Installation Directories for the default location of
studio-workspace on your system.