Schema Inheritance

Tell a new schema to inherit the structure of an existing schema.

The example creates a schema named TradeSchema.

CREATE SCHEMA TradeSchema (Ts bigdatetime, Symbol STRING, Price MONEY(4), Volume INTEGER);

The example then creates the schema VTradeSchema, and uses the INHERITS syntax to extend VTradeSchema by incorporating TradeSchema column values.

CREATE SCHEMA VTradeSchema INHERITS TradeSchema (vwap money(4));

The example creates an input window named TradeWindow, to which it attaches the File CSV Input adapter.

Finally, the example creates an aggregate output window named VwapWindow, in which the volume-weighted average price is returned for TradeWindow data. The return values are grouped by Symbol.

CREATE OUTPUT WINDOW VwapWindow
	SCHEMA VTradeSchema
 	PRIMARY KEY DEDUCED 
AS 
	SELECT  TradeWindow.Ts Ts, 
		TradeWindow.Symbol AS Symbol, 
		TradeWindow.Price Price, 
		TradeWindow.Volume Volume,
		((SUM(TradeWindow.Price*TradeWindow.Volume)) / (SUM(TradeWindow.Volume))) AS vwap
	FROM TradeWindow
	GROUP BY TradeWindow.Symbol;