CREATE MODULE

Create a module that can be added to a project later using the LOAD MODULE statement.

The example creates a module named Module1, identifying the input and output windows that are later defined in the BEGIN-END block.
CREATE MODULE Module1  IN rawStockFeed OUT infoByStockSymbol 

In the BEGIN-END block, the example declares the parameter myparam, for which it sets a default value of 2. The example also creates a memory store named store1.

BEGIN			
	DECLARE
		parameter integer myparam := 2;
	END;

	CREATE DEFAULT MEMORY STORE store1;

The example creates two schemas named inputSchema and outputSchema. It then creates an input window named rawStockFeed, which references inputSchema, and an output window named infoByStockSymbol, which references outputSchema. The function getRecordCount(), which is referenced later in the statement, is declared using a DECLARE block.

The output window infoByStockSymbol uses SELECT and FROM clauses to pull data from rawStockFeed. A WHERE clause places a filter on the data when the share volume is greater than the value set for myparam. The example concludes by closing the BEGIN-END block.

	CREATE OUTPUT WINDOW infoByStockSymbol
	SCHEMA outputSchema 
		PRIMARY KEY DEDUCED 
			DECLARE
				integer recordCount:=1;
				integer getRecordCount() {
					return recordCount++ ; 
				}
			END
		AS	 
			SELECT rawStockFeed.Symbol, 
				avg(rawStockFeed.Price) AvgPrice, 
				sum(rawStockFeed.Volume) Volume,
				count(rawStockFeed.Symbol) NumRecordsForSymbol,
				getRecordCount() TotalNumRecords, 
				myparam as dummy
			FROM rawStockFeed 
			WHERE rawStockFeed.Volume > myparam
			GROUP BY rawStockFeed.Symbol;
END;