Variables in the DECLARE Block

Define a variable, then use the variable in both a regular stream and Flex stream.

The example specifies a default value of 1000 for the variable ThresholdValue.

declare 
 INTEGER ThresholdValue := 1000;
end;

The example creates two schemas named TradeSchema and ControlSchema. An input window named TradeWindow references TradeSchema, and an input stream named ControlMsg references ControlSchema.

The example then creates an output window named OutTradeWindow. The SELECT clause sends rows greater than ThresholdValue to OutTradeWindow.

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;

The example creates a Flex stream named FlexControlStream to process the control messages. The BEGIN syntax introduces conditions based on control messages. If the control message is set, the ThresholdValue is set to equal the control message value instead of the default 1000.

CREATE FLEX FlexControlStream 
  IN ControlMsg 
  OUT OUTPUT WINDOW SimpleOutput 
  SCHEMA ( a integer, b string, c integer)
     PRIMARY KEY ( a)
BEGIN
    ON ControlMsg
    {
    	if ( ControlMsg.Msg = 'set')  {ThresholdValue:=ControlMsg.Value;}
    	output [a=ControlMsg.Value; b=ControlMsg.Msg; c=ThresholdValue; |];
    }
    ;
END
;

Finally, the example creates two ATTACH ADAPTER instances named csvInCntMsg and csvInConn1 using the File CSV Input adapter. In the first instance, the adapter is attached to ControlMsg and assigned to RunGroup1. In the second instance, the adapter is attached to TradeWindow and assigned to RunGroup2. The ADAPTER START GROUPS statement tells the project server to read the control messages first, then the stock trades data.