This topic describes
Aggregate operator time dimension sample.
In StreamBase Studio, import this sample with the following steps:
From the top-level menu, click> .
sample groupto 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.
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 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> from the context menu.
AggregateByTime.sbappfile and click the Run button. This opens the SB Test/Debug perspective and starts the module.
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.
In the Feed Simulations view, right click on
AggregateByTime.sbfsand select .
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
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 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
ngoes down or up, accordingly.
Click the Manual Input tab, type a string for Symbol and number for PricePerShare, and then click. After two seconds, observe the operator time out and emit output.
When done, press F9 or click the Terminate EventFlow Fragment button.
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.