Contents
In the StreamBase expression language, function is a data type. This sample EventFlow module demonstrates three ways to apply an algorithm to data on a stream.
StreamBase expression language functions can be defined as constant expressions or passed on a stream. As a StreamBase data type, functions 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.
This sample uses Map operators, in which the same degrees Celsius to degrees Fahrenheit conversion expression is applied in three ways:
-
For comparison, as an expression defined without a function, in the
UseLocalFn
Map operator. -
The same expression is defined as a module function in the Definitions tab, and called in the
UseModuleFn
Map operator. -
The same expression is defined as a function field in the
DefineFn
operator, then called by its field name in theUsePassedFn
operator.
In StreamBase Studio, import this sample with the following steps:
-
From the top-level menu, select
> . -
Enter
function data
to narrow the list of options. -
Select Using the function data type sample from the Data Constructs category.
-
Click
.
StreamBase Studio creates a project for the sample.
-
In the Project Explorer view, open this sample's folder.
Keep an eye on the bottom right status bar of the Studio window. Make sure any
Updating
,Downloading
,Building
, orRebuild project
messages finish before you proceed. -
Open the
src/main/eventflow/
folder.packageName
-
Double-click to open the
function.sbapp
module. Make sure the module is the currently active tab in the EventFlow Editor. -
Click the Run button. This opens the SB Test/Debug perspective and starts the module.
-
As the server starts, StreamBase Studio switches to the SB Test/Debug perspective.
-
Wait for the Waiting for fragment to initialize message to clear.
-
Select the Manual Input tab.
-
Enter a value for a temperature in
temp_cel
in thecelsius
input stream and click . -
Observe that the
temp_f_expr
,temp_f_fcn
, andtemp_f_stream
output values are identical. -
When done, press F9 or click the Terminate EventFlow Fragment button.
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.