Iterate Operator Sample

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 and extracts their component tuples to reorder and supplement the output fields.

The incoming tuple contains fields named Symbol, Name, Volume, and Price.

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 all the operator samples.

Running This Sample in StreamBase Studio

  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 Iterate.sbapp file and click the Run button. This opens the SB Test/Debug perspective and starts the module.

  4. In the Manual Input view, select the StockIn input stream.

  5. 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
    AAPL, Apple Inc, 2500, 133.62
    IBM, IBM Corporation, 1000, 128.00
    AAPL, Apple Inc, 500, 133.64
    MSFT, Microsoft Corporation, 6000, 28.70
    AAPL, Apple Inc, 2000, 133.75
    MSFT, Microsoft Corporation, 400, 27.75
    IBM, IBM Corporation, 2500, 129.62

    Tip

    Instead of typing in the Manual Input view, while Iterate.sbapp is still running in Studio, open a StreamBase Command Prompt. Start an enqueue session for the sample's input stream by typing sbc enqueue StockIn. Then copy the contents of the gray box above and paste them into the command prompt window.

  6. Inspect the Output Streams 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 Output Streams view:

    MSFT, Microsoft Corporation, 1400, 29.45
  7. Enter more tuples and watch them accumulate in groups of three.

  8. 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.