Contents
This topic describes Iterate.sbapp, the Iterate
operator's sample application.
This sample uses an Aggregate operator and the aggregatelist() expression language function to aggregate incoming
tuples and collect them by their Symbol field into three-element lists of tuples, so
that every list output contains three input tuples of the same stock. An Iterate operator then takes these
lists, extracts their component tuples, and feeds them to a Map operator, which
reorders and supplements the output fields.
This sample demonstrates one use of the aggregatelist()
function, to create lists with elements from individual tuples, and demonstrates a use
of the Iterate operator, to extract the elements from a list back into individual
tuples again.
The incoming tuple contains fields named Symbol, Name, Description, Volume, and Price.
-
In the Package Explorer, double-click to open the
Iterate.sbappapplication. 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 Manual Input view, select the
StockIninput stream. -
Enter a dozen or so tuples, alternating the Symbol field, but re-using the same Symbol several times, clicking Send Data after each entry. For example, enter:
IBM, IBM Corporation, 4000, 127.81 DELL, Dell Inc, 2500, 13.62 IBM, IBM Corporation, 1000, 128.00 DELL, Dell Inc, 500, 13.64 MSFT, Microsoft Corporation, 6000, 28.70 DELL, Dell Inc, 2000, 13.75 MSFT, Microsoft Corporation, 400, 27.75 IBM, IBM Corporation, 2500, 129.62
Tip
Instead of typing in the Manual Input view, while
Iterate.sbappis still running in Studio, open a StreamBase Command Prompt. Start an enqueue session for the sample's input stream by typingsbc enqueue StockIn. Then copy the contents of the gray box above and paste them into the command prompt window. -
Inspect the Application Output view. Notice that there are three entries for Dell and three for IBM. There is no output for Microsoft yet because we have only entered two tuples. Enter one more Microsoft tuple to trigger its entries in the Application Output view:
MSFT, Microsoft Corporation, 1400, 29.45
-
Enter more tuples and watch them accumulate in groups of three.
-
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 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 Iterate.sbappThe window shows
notice[StreamBaseServer] listening on port 10000. -
In window 2: type:
sbc dequeue StockOutNo 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 StockInThe sbc command now awaits keyboard input.
-
In window 3, type:
IBM, IBM Corporation, 4000, 127.81 DELL, Dell Inc, 2500, 13.62 IBM, IBM Corporation, 1000, 128.00 DELL, Dell Inc, 500, 13.64 MSFT, Microsoft Corporation, 6000, 28.70 DELL, Dell Inc, 2000, 13.75
Observe that nothing appears in window 2 until you type the last line above, which is the third entry for Dell.
Tip
Instead of typing the entries shown, you can copy and paste into window 3.
-
In window 3, type two more lines:
MSFT, Microsoft Corporation, 400, 27.75 IBM, IBM Corporation, 2500, 129.62
Observe that output lines for IBM now appear in window 2.
-
In window 3, type one more line:
MSFT, Microsoft Corporation, 1400, 29.45
Observe that output lines for Microsoft now appear in window 2.
-
Enter more tuples and watch them accumulate in groups of three.
-
In window 3 type Ctrl+C to stop the sbc enqueue command.
-
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 all the operator samples.
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 Studion.mWorkspace\sample_operator Windows 7 and Windows Vista: C:\Users\username\Documents\StreamBase Studion.mWorkspace\sample_operator
