Query Table Index by Expression Sample

About This Sample

This sample consists of a simple EventFlow application, QueryIndexByExpression.sbapp, that illustrates the Query Table's index by expression feature. This feature allows you to use an expression as part of specifying the field or fields that comprise a secondary index for a Query Table. The expression must be statically resolvable, and must contain the name of at least one field in the Query Table's schema.

This sample's Query Table has the schema {string symbol, double lastPriceChange} and is automatically populated with the following values by means of the Initial Contents tab of the table's Properties view:

IBM, -4.3
MSFT, 6.7
GOOG, -2.3
APPL, 9.3

The field name portion of the Query Table's secondary index is specified with the expression abs(lastPriceChange). This simple expression allows you to enter either a query value either as a positive or negative number and obtain the same result. For example, if a Query operator specifies a Read operation based on this secondary index, you could enter either 4.3 or –4.3 to obtain the result IBM.

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 the operator sample group.

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

  4. In the Manual Input view, the QueryByPriceDelta input stream is preselected. Enter one of the values from the initially loaded contents shown above, as either a positive or negative number. For example, enter –4.3, then enter 4.3.

  5. Click Send Data, and a tuple arrives in the Output Streams view. In both cases, the Output Streams view shows the IBM row of the Query Table returned on the QueryResults stream.

  6. Continue experimenting with values from the list above, or values not in the list.

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


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:


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