Defines a named window that can be referenced and used by one or more downstream operators or, if an output window, can be used to publish results.
CREATE INPUT WINDOW name schema_clause primary_key_clause [store_clause] [keep_clause] [autogenerate_clause] [GUARANTEE DELIVERY]; CREATE [ LOCAL | OUTPUT ] WINDOW name schema_clause { PRIMARY KEY (column1, column2, ...) | PRIMARY KEY DEDUCED } [store_clause] [aging_clause] [keep_clause] [local-declare-block] [GUARANTEE DELIVERY] [partition_clause] as_clause ;
name |
A name for the window being created. |
schema_clause |
Required for input windows, but optional for local and output windows. When the schema clause is not specified for local and output windows, it is automatically deduced by the compiler. |
primary_key_clause |
Set primary key. |
store_clause |
(Optional) Specifies the physical mechanism used to store the state of the records. If no clause is specified, project or module defaults apply. |
autogenerate_clause |
(Optional) Specify that the server will automatically generate values for one or more columns of datatype long. This can be used to generate a primary key for events that lack a natural key. Valid only for input windows. See AUTOGENERATE Clause for more information. |
keep_clause |
(Optional) Specifies the retention policy for the window. When not specified, the window uses the KEEP ALL retention policy as a default. |
aging_clause |
(Optional) Specifies the data aging policy. Used only with output or local windows. |
local-declare-block |
(Optional) Allows variable and function declarations that can be accessed in expressions in the query. You cannot define a local-declare-block on an input stream. |
partition_clause |
(Optional) Creates a specified number of parallel instances of the window. The partition type specifies how to partition the input for the window. See the PARTITION BY Clause for more information. |
GUARANTEE DELIVERY | (Optional) Enables guaranteed delivery for this window. Any window with guaranteed delivery must also be assigned to a log store. |
as_clause |
Introduces a query to a statement. |
The SCHEMA and PRIMARY KEY clauses are mandatory for an input window. The SCHEMA clause is optional for derived windows. If a SCHEMA is not defined the compiler implicitly determines it based on the projection list. For derived windows, the primary key may be either deduced or explicitly specified. There are a few exceptions to these rules, which is noted in the appropriate context.
The CREATE WINDOW statement can also include a STORE clause to determine how records are stored, and a KEEP clause to determine how many records are stored and for how long. The window can be of type input, output, or local. Local and output windows can include an AGING clause that specifies the data aging policy.
Use GUARANTEE DELIVERY to enable guaranteed delivery only for a window stored in a log store; guaranteed delivery is not available to windows stored in memory stores. Do not use GUARANTEE DELIVERY inside a module because you cannot directly attach adapters to elements in modules.
When you enable guaranteed delivery on a window that has registered guaranteed delivery subscribers, the window stores a copy of every event it produces in its log store until all the registered guaranteed delivery subscribers acknowledge receiving the events.
Because copies of events are kept in the same log store the window is assigned to, the log store for a guaranteed delivery window must be significantly larger than the log store for a similar window without guaranteed delivery. Ensure that the log store for every guaranteed delivery window is large enough to accommodate the required events. If the log store runs out of room, the project server shuts down.
CREATE WINDOW TradesAge PRIMARY KEY DEDUCED KEEP 10 MINUTES AGES EVERY 5 SECONDS SET AgeColumn 5 TIMES AS SELECT Trades.*, 0 AgeColumn FROM Trades;
CREATE WINDOW TradesAge PRIMARY KEY DEDUCED KEEP 10 MINUTES AGES EVERY 5 SECONDS SET AgeColumn 5 TIMES DECLARE long counter := 0; long getRecordCount() { return ++counter; } END AS SELECT Trades.*, getRecordCount() RecordCount, 0 AgeColumn FROM Trades;
CREATE INPUT WINDOW FreshTrades SCHEMA (TradeId long, Symbol string, Shares integer, Price money(4), Age integer) PRIMARY KEY (TradeId) KEEP 1000 ROWS AGES EVERY 5 MINUTES SET Age 100 TIMES AUTOGENERATE (TradeId);
CREATE LOG STORE Store1 PROPERTIES fileName='store'; CREATE INPUT WINDOW In1 SCHEMA (Key1 integer, Col1 string, Col2 float) PRIMARY KEY (Key1) STORE Store1 GUARANTEE DELIVERY; CREATE OUTPUT WINDOW Out1 PRIMARY KEY (Key1) STORE Store1 GUARANTEE DELIVERY AS SELECT * FROM In1;