Field Grids Sample

Sample Overview

The field-grids sample illustrates how fields specified with the Include and Add actions, and local variables created with the Declare action, can be used in both simple and aggregate expressions in output grids. It also shows how to avoid typechecking errors by properly qualifying field names.

The StreamBase application field-grids.sbapp includes four independent flows. The two flows on top show simple expressions in field grids, and the two at the bottom illustrate aggregate expressions in field grids, all involving declared local variables.

When the application loads, one of the Map operators and one of the Aggregate operators display typechecking errors involving failure to qualify field names. Before running the application, you must correct those errors.

For information on this topic, see Using Field Grids.

Running This Sample in StreamBase Studio

  1. In the Package Explorer, double-click to open the field-grids.sbapp application. Make sure the application is the currently active tab in the EventFlow Editor.

  2. Notice the yellow warning decoration on the DeclareAddID Map operator in the upper right. To see why, select it and click the Output Settings tab in the Properties View. The warning message above the view tells you: Ambiguous reference to "id". The expression "id" will refer to the unparented variable. Try using qualifiers (for example, "input.") if you want otherwise.

    The ambiguity happens because the input stream field named id is included and id is also the name of a variable that was declared. To remove the warning, you can either:

    • Use a name other than id for the declared variable, or

    • Use the qualifier "input1." to specify you want to use the input field.

    If you do neither, the default is to use the declared local variable and issue the warning.

  3. Notice that one Map operator and one Aggregate operator are both red, indicating that they fail to typecheck. To see why, follow the next steps.

  4. To fix the AddFields Map operator:

    1. Select the AddFields operator and look at its Output Settings tab in the Property View. In row 2, the expression x is highlighted and you see the error the field "x" is not available from any stream. Try qualifying the expression with "output."

    2. Notice that row 3 does qualify x as output.x and that it typechecks.

    3. Rename the expression for xRef to output.x. It will now have the same content as xRef_properly.

    4. Notice that the AddFields operator now typechecks.

  5. To fix the DeclareAggregateError Aggregate operator:

    1. Select the DeclareAggregateError operator and look at its Aggregate Functions tab in the Property View. In row 3, the expression sumPrice/countPrice is highlighted and you see the error "the field "countPrice" is not available from any stream. Try qualifying the expression with "output.""

    2. As the message indicates, change the expression sumPrice/countPrice to sumPrice/output.countPrice.

    3. Notice that the DeclareAggregateError operator now typechecks.

  6. Save the fixed field-grids.sbapp or optionally save it as a new file if you want to compare it with the original file. To save as a new file:

    1. Click FileSave As to open the Save As dialog.

    2. In the Enter or select the parent folder field, click or type sample-field-grids.

    3. In File name field, type field-grids-fixed

    4. Click OK to create the file in the sample-field-grids folder.

    5. In the Package Explorer, locate and double-click field-grids-fixed.sbapp to open it. Make sure it is the currently active tab in the EventFlow Editor.

  7. Click the Run button. This opens the SB Test/Debug perspective and starts the application.

  8. There are four input and four output streams. The following table indicates some application inputs you can provide and the output that results from each.

    Input Stream Output Stream Example Input Example Output
    NoInput TextOut null (just click Send Data) TextOut x=text_field, xRef_properly=text_field
    idIn idsOut 2 idsOut id=2, local_id_ref=id_text, id_ref=2
    Prices1 AveragePrices1
    100
    200
    300
    null
    null
    AveragePrices1 countPrice=3, avgPrice=200.0
    Prices2 AveragePrices2
    100
    200
    300
    null
    null
    AveragePrices1 countPrice=3, avgPrice=200.0
  9. When done, press F9 or click the Stop Running Application button.

Importing This Sample into StreamBase Studio

In StreamBase Studio, import this sample with the following steps:

  • From the top-level menu, click FileLoad StreamBase Sample.

  • Type grids to narrow the list of options.

  • Select Avoiding field grid name conflicts from the Data Constructs and Operators category.

  • Click OK.

StreamBase Studio creates a single project named sample-field-grids.

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_field-grids

See Default Installation Directories for the default 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/field-grids

See Default Installation Directories for the default location of studio-workspace on your system.