An unnamed window is an implicitly created stateful element that cannot be referenced or used elsewhere in a project.
Unnamed windows are implicitly created in two situations: when using a join with a window that produces a stream, and when the KEEP clause is used with the FROM clause of a statement. In both situations, when an unnamed window is created it always includes a primary key.
This example creates an unnamed window when using a join with a window:
CREATE INPUT WINDOW Win1 SCHEMA (Key1 INTEGER, Col1 STRING, Col2 STRING) PRIMARY KEY (Key1); CREATE INPUT WINDOW Win2 SCHEMA (Key1 STRING, Col3 STRING) PRIMARY KEY (Key1); CREATE OUTPUT WINDOW Out1 PRIMARY KEY DEDUCED AS SELECT Win1.Key1, Win1.Col1, Win1.Col2, Win.2.Col3 FROM Win1 INNER JOIN Win2 ON Win1.Col1 = Win2.Key1;
The following three examples demonstrate when an unnamed window is created using the KEEP clause:
This example creates an unnamed window on the input Trades for the MaxTradePrice window to keep track of a maximum trade price for all symbols seen within the last 10000 trades:
CREATE WINDOW MaxTradePrice PRIMARY KEY DEDUCED STORE S1 AS SELECT trd.Symbol, max(trd.Price) MaxPrice FROM Trades trd KEEP 10000 ROWS GROUP BY trd.Symbol;
This example creates an unnamed window on Trades, and MaxTradePrice keeps track of the maximum trade price for all the symbols during the last 10 minutes of trades:
CREATE WINDOW MaxTradePrice PRIMARY KEY DEDUCED STORE S1 AS SELECT trd.Symbol, max(trd.Price) MaxPrice FROM Trades trd KEEP 10 MINUTES GROUP BY trd.Symbol;
This example creates a TotalCost unnamed window from the source stream Trades. The jumping window will retain ten rows, and clear all rows on the arrival of the 11th row.
CREATE DELTA STREAM TotalCost PRIMARY KEY DEDUCTED AS SELECT trd.*, trd.Price * trd.Size TotalCst FROM Trades trd KEEP EVERY 10 ROWS;
In all three examples, Trades can be a delta stream or a window.