In addition to creating unnamed windows inside a FROM clause, you can also create reusable window definitions that can be shared by multiple queries.
These window definitions are called named windows and are defined with the CCL Create Window Statement. The following table illustrates the main differences between an unnamed and named window:
Unnamed Window |
Named Window |
---|---|
Is defined inside a Query Statement. |
Is defined in a separate Create Window statement. |
Does not have a name. |
Has a name, which must be unique to the query module. |
May be used only by the statement where it is defined. |
May be used by several other types of CCL statements, including any Query Statements in the query module. |
Has one or more window policies (KEEP clauses), defined inside the Query Statement's FROM clause. The policies are linked to a data stream that serves as one of the query's data sources and apply only to that data stream. |
Has one or more window policies (KEEP clauses), defined by the Create Window statement. The policies are not permanently linked to a particular data stream and are applied to whatever data enters the window. |
Inherits a schema from the data stream to which it is linked. |
Includes a SCHEMA clause that provides a schema definition for the window. |
Inherits data from the data stream to which it is linked. |
Does not contain any data when it is first created. Named windows are populated by being used as destinations by other CCL queries. |
Here is an example of a previous example rewritten to incorporate named windows.
CREATE WINDOW WindowTradesMicrosoft SCHEMA 'WindowTradesMSFT.ccs' KEEP 3 ROWS; INSERT INTO WindowTradesMicrosoft SELECT volume, price FROM StockTrades WHERE symbol = 'MSFT'; INSERT INTO AvgPriceMicrosoft SELECT AVG(price) FROM WindowTradesMicrosoft;
The first statement in this example creates a named window called WindowTradesMicrosoft. The schema for this window is contained inside the WindowTradesMSFT.ccs schema file and the window's policy keeps up to three most-recent rows that enter the window. The second query supplies the window with data and the third uses it as its data source. Neither of the subsequent queries determines the window's policy or its schema.
For more information about the Create Window statement and its clauses, please see the Sybase CEP CCL Reference.