Contents
This topic describes AggregateByField.sbapp
, the
Aggregate operator field dimension sample.
In this sample, the Aggregate operator uses a field-based dimension to sum the volume of trades in a particular stock over 30 second windows, advancing every 30 seconds. It also ensures that the aggregation works for intermixed tuples for different stocks.
-
In the Package Explorer, double-click to open the
AggregateByField.sbapp
application. Make sure the application is the currently active tab in the EventFlow Editor. -
Click the Run button. This opens the SB Test/Debug perspective and starts the application.
-
In the Application Output view, select the OutputChunkedTrades output stream. No output is displayed at this point, but the dequeuer is prepared to receive output. This view will eventually show the output of the application.
-
In the Manual Input view, enter
7
,AMAT
, and100
in the Time, Symbol, and Volume fields, respectively. Note that strings in StreamBase are case sensitive, so "AMAT" is not the same as "amat". -
Click
, and observe that no output is displayed yet in the Application Output view. -
Enter
10
,AMAT
, and100
in the Time, Symbol, and Volume fields, respectively. -
Click
, and observe that no output is displayed yet in the Application Output view. -
Enter
20
,AMAT
, and200
in the Time, Symbol, and Volume fields, respectively. -
Click
, and observe that no output is displayed yet in the Application Output view. -
Enter
40
,AMAT
, and100
in the Time, Symbol, and Volume fields, respectively. -
Click
, and observe this line in the Application Output view:Symbol=AMAT, TimeChunk=0, TotalVolume=400
Tip
If output data is too long to easily see in the Application Output table, click a row to display its field data in the Display Fields pane below the table.
-
Enter
41
,AMAT
, and100
in the Time, Symbol, and Volume fields, respectively. -
Click
, and observe that no output is displayed in the Application Output view. -
Enter
45
,INTC
, and100
in the Time, Symbol, and Volume fields, respectively. -
Click
, and observe that no output is displayed in the Application Output view. -
Enter
50
,AMAT
, and200
in the Time, Symbol, and Volume fields, respectively. -
Click
, and observe that no output is displayed in the Application Output view. -
Enter
55
,INTC
, and300
in the Time, Symbol, and Volume fields, respectively. -
Click
, and observe that no output is displayed in the Application Output view. -
Enter
65
,AMAT
, and100
in the Time, Symbol, and Volume fields, respectively. -
Click
, and observe these lines in the Application Output view.Symbol=AMAT, TimeChunk=30, TotalVolume=400
Symbol=INTC, TimeChunk=30, TotalVolume=400 -
When done, press F9 or click the Stop Running Application button.
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.
-
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.
-
In window 1, type:
sbd AggregateByField.sbapp.
The window shows: .
notice[StreamBaseServer] listening on port 10000
-
In window 2, type
sbc dequeue OutputChunkedTrades.
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.
-
In window 3, type
sbc enqueue TradesIn.
The sbc command is now awaiting keyboard input. Then type:
7,AMAT,100
No output is displayed yet in the dequeue window.
-
Type:
10,AMAT,100
No output is displayed yet in the dequeue window.
-
Type:
20,AMAT,200
No output is displayed yet in the dequeue window.
-
Type:
40,AMAT,100
Observe this line in the dequeue window:
AMAT,0,400
-
Type:
41,AMAT,100
No output is displayed in the dequeue window.
-
Type:
45,INTC,100
No output is displayed in the dequeue window.
-
Type:
50,AMAT,200
No output is displayed in the dequeue window.
-
Type:
55,INTC,300
No output is displayed in the dequeue window.
-
Type:
65,AMAT,100
Observe these lines in the dequeue window:
AMAT,30,400
INTC,30,400 -
Press Control+Z (Windows) or Control+D (UNIX).
The sbc process will exit.
-
In window 3, type the following command to terminate the server and dequeuer:
sbadmin shutdown
In StreamBase Studio, import this sample with the following steps:
-
From the top menu, click
→ . -
Select operator from the Data Constructs and Operators category.
-
Click OK.
StreamBase Studio creates a single project for the 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.
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 the permission problems that can occur when trying to work with the initially installed location of the sample. The default workspace location for this sample is:
studio-workspace
/sample_operator
See Default Installation
Directories for the location of studio-workspace
on your system.
In the default TIBCO StreamBase installation, this sample's files are initially installed in:
streambase-install-dir
/sample/operator
See Default Installation
Directories for the location of streambase-install-dir
on your system. This location
may require administrator privileges for write access, depending on your platform.