CREATE WINDOW statement

Defines a named window that can be referenced later and used by one or more queries.

Syntax

CREATE [ PUBLIC | MASTER ] WINDOW win_name schema_clause {keep_clause [, keep_clause] } | { MIRROR master_window } [INSERT REMOVED [ROWS] INTO name ] [ properties_clause ]
Components

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.

properties_clause

PROPERTIES [ INDEXCOLUMNS=" col_name [, ...] " ] [ FILTERCOLUMNS=" col_name [, ...] " | [ FILTER=" value [, ...] " ] [ FILTEREXPR=" expression " ] ]
Components

col_name

The name of a column to be indexed (for a public window) or used as a filter (for a master window).

value

A filter value for a mirror window.

expression

A filter expression for a mirror window.

Usage

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:

Restrictions

See Also

Examples

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;