Variables represent a specific piece of information that may change throughout project execution. Variables are declared using the SPLASH syntax.
typeName {variableName[:=any_expression] [, ...]}
Variables may be declared within any declare block, SPLASH UDF, or Flex procedures. Multiple variables may be declared on a single line.
The declaration of a variable can also include a optional initial value, which must be a constant expression. Variables without an initial value initialize to NULL.
Variables can be of complex types. However, complex variables can only be used in local declare blocks and declare blocks within a Flex stream.
Variables declared in a local declare block may subsequently be used in SELECT clauses, but cause compiler errors when used in WHERE clauses.
For SPLASH language details, see SPLASH Programmers Guide.
This example defines a variable, then uses the variable in both a regular stream and a FLEX stream.
declare
INTEGER ThresholdValue := 1000;
end;
//
// Create Schemas
Create Schema TradeSchema(
Ts bigdatetime,
Symbol STRING,
Price MONEY(4),
Volume INTEGER
);
Create Schema ControlSchema (
Msg STRING,
Value INTEGER
); //
// Input Trade Window
//
CREATE INPUT WINDOW TradeWindow
SCHEMA TradeSchema
PRIMARY KEY (Ts);
//
// Input Stream for Control Messages
//
CREATE INPUT STREAM ControlMsg SCHEMA ControlSchema ;
//
// Output window, only has rows that were greater than the thresholdvalue
// was when the row was received
CREATE Output WINDOW OutTradeWindow
SCHEMA (Ts bigdatetime, Symbol STRING, Price MONEY(4), Volume INTEGER)
PRIMARY KEY (Ts)
as
select *
from TradeWindow
where TradeWindow.Volume > ThresholdValue;
//
//Flex Stream to process the control message
CREATE FLEX FlexControlStream
IN ControlMsg
OUT OUTPUT WINDOW SimpleOutput
SCHEMA ( a integer, b string, c integer)
PRIMARY KEY ( a)
BEGIN
ON ControlMsg
{
// change the value of ThresholdValue
if ( ControlMsg.Msg = 'set') {ThresholdValue:=ControlMsg.Value;}
// The following is being populate so you can see that the ThresholdValue is being set
output [a=ControlMsg.Value; b=ControlMsg.Msg; c=ThresholdValue; |];
}
;
END
;