DECLARE block statements specify the variables, parameters, typedefs and functions used in a CCL project.
DECLARE [declaration;] ... END;
CCL declare blocks consist of a DECLARE statement and an END statement with zero or more declarations between them.
datatypeName variableName [:=any_expression] [,...]
existingdatatypeName newdatatypeName
parameter datatypeName parameterName [:=constant_expression]
Declare blocks can be local or global. When declare blocks are used inside a CREATE stream or window statement they become local declare blocks. A local declare block is visible only inside the stream or window with which it is used. When a DECLARE block statement is used inside a module or project, it becomes a global declare block. Global declare blocks are visible anywhere within that project or module.
Terminate each declaration in the DECLARE block statement with a semicolon.
declare integer toggle(integer x) { if ( x%2 = 0) { return 1; } else { return 2; } } end; CREATE SCHEMA sc1 (k1 integer,k2 string); CREATE SCHEMA sc2a (k1 integer,k2 string,k3 string, k4 integer); create schema s1_104(c2 integer, c3 date, c4 float, c5 string, c6 money ); CREATE INPUT WINDOW iwin1 SCHEMA sc1 primary key(k1); CREATE INPUT WINDOW iwin2 SCHEMA sc1 primary key(k1); create input window w1_104 schema s1_104 primary key(c2); create delta stream ds2_104 primary key deduced as select * from w1_104; create output window ww_innerjoin1 schema sc2a primary key (k1,k2)This example shows the DECLARE block local to a stream, meaning it is inside a CREATE command (not flex)
declare integer i1 := 1; string s1 := 'ok'; end as select A.k1,(A.k2 + s1) k2,B.k2 k3, toggle(A.k1) k4 from iwin1 A join iwin2 B on A.k1 = B.k1 ;This example shows a DECLARE block local to a flex stream.
create flex flex104 in ds2_104 out output stream flexos104 schema s1_104 begin declare integer counter := 0; end; on ds2_104 { counter++; output ds2_104_stream[ [c2=ds2_104.c2;|] ]; }; on end transaction { if( counter = 4 ) { typeof( flexos104 ) rec; rec := flexos104_stream[ [c2=0;|] ]; rec.c2 := rec.c2 + counter; output rec; rec := flexos104_stream[ [c2=1;|] ]; rec.c2 := rec.c2 + counter; output rec; rec := flexos104_stream[ [c2=2;|] ]; rec.c2 := rec.c2 + counter; output rec; rec := flexos104_stream[ [c2=3;|] ]; rec.c2 := rec.c2 + counter; output rec; } }; end;