EventFlow Function Sample

About This Sample

This sample application demonstrates three ways to apply an algorithm to data on a stream. Using Map operators, it converts temperature data in degrees Celsius to degrees Fahrenheit, by applying:

  1. A function on a stream.

  2. A global function defined as a constant.

  3. An EventFlow expression.

StreamBase expression language functions can be defined as constant expressions or passed on a stream. Functions are a StreamBase data type. They return a declared data type and can accept any other data type as arguments. In this sample, there is one double argument and a double result.

The Map operator UseGlobalExpression invokes a function that was defined as a constant on the project's Definitions tab using the Add Constant button. Map operator UseFcnFromData applies a function added to the input stream by Map operator CreateFcn in a field called to_fahr. Map operator UseExpression, which evaluates an expression rather than a function to transform its input, is included for comparison purposes.

Importing This Sample into StreamBase Studio

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

  • From the top menu, select FileLoad StreamBase Sample.

  • Type function to narrow the list of options.

  • Select function from the Applications category.

  • Click OK.

StreamBase Studio creates a project for the sample.

Running function.sbapp 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 named application file 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. Select the Manual Input tab.

  6. Enter a value for a temperature in temp_cel in the celsius input stream and click Send Data.

  7. Observe that the temp_f_stream, temp_f_fcn, and temp_f_expr output values are identical.

  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_function

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