Defines a named window that can be referenced later and used by one or more queries.
win_name |
The name of the window. |
schema_clause |
A definition of the schema for the window. See SCHEMA Clause for more information. |
keep_clause |
The policy defining how rows are kept in this window. See KEEP Clause for more information. |
master_window |
The name of the master window this window mirrors. See Shared Windows for more information. |
name |
The name of the stream or window where removed rows are published. |
properties_clause |
Definitions for index columns, filter columns, or filter values. See properties_clause for more information. |
Use the Create Window statement to create a named window, a public window, or a shared window (either master or mirror).
The Create Window statement:
Optionally defines the window as a public, master, or mirror window. Note that a public window can also be a master or mirror window, but a master window cannot also be a mirror window.
Includes either one or two KEEP clauses, which define the conditions under which the window should retain rows (window policies are discussed in more detail in the description of the KEEP clause), or defines the window as a mirror of a master window. Note that a statement defining a mirror window cannot include a KEEP clause.
Optionally includes a PROPERTIES clause defining index columns for a public window, filter columns for a master window, or filter values or a filter expression for a mirror window.
Optionally includes an INSERT REMOVED clause that identifies a data stream or named window in the same query module as the current window. Any rows removed from the current window are published to the specified stream or window.
Named windows are recognized by all CCL statements within a module, but not by statements outside the module.
The window name must be unique within the query module.
Because named windows are not permanently attached to any stream, they must be explicitly populated by other statements in order to contain information.
A master window cannot also be a mirror window.
A mirror window is read only; you cannot insert, update, or delete rows from it.
A mirror window must be in a separate project from the master window it mirrors.
The FIRST and LAST functions do not work with mirror windows.
The schema defined for a mirror window must exactly match the schema of the master window it is mirroring.
If you set accelerated playback on the project containing the master window, you must set accelerated playback to the same value on all projects containing windows mirroring that master window.
If you set persistence but not guaranteed delivery on the project containing the master window, any windows mirroring that master may not be accurate after a restart of the master project.
The maximum delay setting for the module containing the mirror window must be at least slightly larger than the maximum delay setting for the module containing the master window, assuming you are using message timestamp.
Create Schema Statement
Public Windows
Shared Windows
KEEP
SCHEMA
CREATE WINDOW AllGuestsWindow SCHEMA (Name STRING, NetWorth FLOAT) KEEP ALL;
CREATE WINDOW RecentReadingsWindow0 SCHEMA ReadingsSchema KEEP 10 ROWS;
CREATE WINDOW RecentReadingsWindow1 SCHEMA 'RfidReadingsSchema.ccs' KEEP 10.5 MINUTES;
CREATE WINDOW RecentReadingsWindow3 SCHEMA 'RfidReadingsSchema.ccs' KEEP 10 MINUTES 30 SECONDS;
CREATE WINDOW RecentReadingsWindow4 SCHEMA 'RfidReadingsSchema.ccs' KEEP INTERVAL '00:10:30';
CREATE WINDOW TodayTrades SCHEMA ( Symbol STRING, Shares FLOAT, Duration INTERVAL) KEEP FOR Duration;
The following example creates a public window:
CREATE SCHEMA Myschema (Symbol STRING, Price FLOAT, Volume INTEGER, VWAP FLOAT); CREATE PUBLIC WINDOW MyPubWindow SCHEMA Myschema KEEP 1 HOUR PROPERTIES INDEXCOLUMNS = "Symbol, Price";
The following example illustrates a basic master and mirror window relationship. ProjectA (in the Default workspace) defines and populates a master window named MyTradesWindow:
CREATE MASTER WINDOW MyTradesWindow SCHEMA MySchema KEEP 24 hours; INSERT INTO MyTradesWindow SELECT * FROM MyTradesStream;
ProjectB defines a mirror of MyTradesWindow and sends rows to OutStream based on rows in the mirror window:
CREATE WINDOW MyWindow SCHEMA MySchema MIRROR "/Stream/Default/ProjectA/MyTradesWindow"; INSERT INTO OutStream SELECT Symbol, Avg(Price), Min(Price), Max(Price) FROM MyWindow GROUP BY Symbol;
The following example shows the use of filter columns. The master window definition specifies the filter columns Exchange and Symbol:
CREATE MASTER WINDOW MyTradesWindow SCHEMA MySchema KEEP 24 hours PROPERTIES FilterColumns='Exchange,Symbol'; INSERT INTO MyTradesWindow SELECT * FROM MyTradesStream;
The mirror window definition specifies filter values "NYSE" and "IBM." The mirror window will only receive rows from the master that have the value "NYSE" in the Exchange column and the value "IBM" in the Symbol column:
CREATE WINDOW MyIbmWindow SCHEMA MySchema MIRROR "/Stream/Default/ProjectA/MyTradesWindow" PROPERTIES Filter='NYSE,IBM'; INSERT INTO OutIbmStream SELECT Symbol, Avg(Price), Min(Price), Max(Price) FROM MyIbmWindow;