Contents
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.
-
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. -
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.
-
-
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.
-
To fix the AddFields Map operator:
-
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."
-
Notice that row 3 does qualify x as output.x and that it typechecks.
-
Rename the expression for xRef to output.x. It will now have the same content as xRef_properly.
-
Notice that the AddFields operator now typechecks.
-
-
To fix the DeclareAggregateError Aggregate operator:
-
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.""
-
As the message indicates, change the expression sumPrice/countPrice to sumPrice/output.countPrice.
-
Notice that the DeclareAggregateError operator now typechecks.
-
-
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:-
Click Save As dialog.
→ to open the -
In the Enter or select the parent folder field, click or type
sample-field-grids
. -
In File name field, type
field-grids-fixed
-
Click
to create the file in the sample-field-grids folder. -
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.
-
-
Click the Run button. This opens the SB Test/Debug perspective and starts the application.
-
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 -
When done, press F9 or click the Stop Running Application button.
In StreamBase Studio, import this sample with the following steps:
-
From the top-level menu, click
→ . -
Type
grids
to narrow the list of options. -
Select
from the Data Constructs and Operators category. -
Click OK.
StreamBase Studio creates a single project named sample-field-grids.
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_field-grids
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/field-grids
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.