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 menu, click FileLoad StreamBase Sample.

  • Type operator to narrow the list of options.

  • Select Operator sample group from the Data Constructs and Operators category.

  • Click OK.

StreamBase Studio creates a single project for the operator sample group.

Running This Sample in StreamBase Studio

  1. In the Project Explorer, open the sample you just loaded.

  2. Open the src/main/eventflow folder.

  3. Open the package folder (most samples contain a single package folder. Open the top-level package folder if your sample contains more than one folder).

  4. Open the QueryIndexByExpression.sbapp application and click the Run button. This opens the SB Test/Debug perspective and starts the application.

    If you see red marks, wait a moment for the project in Studio to load its features.

    If red marks do not resolve themselves in a moment, select the project and right-click MavenUpdate Project from the context menu.

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

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

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

  8. When done, press F9 or click the Stop Running Application 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.