Shared Windows

Shared windows allow you to perform a snapshot query with live updates, to duplicate contents of one master window in other mirror windows in other projects, and to receive updates to the mirror windows as the master window changes.

Master

A master window is define just the same as any other named window. The optional PROPERTIES clause allows you to define filter columns that allow mirror windows to specify that they will only receive rows from the master with specific values in the filter columns. Only a single set of filter columns can be defined per master window.

Mirror

A mirror window is a read-only window that receives duplicate rows from the master window. When you define a mirror window you specify the master window with a name in the following form, where hostname identifies the computer running Sybase CEP Manager for the project containing the master window, and port is the port number used by that Manager:

ccl://hostname:port/Stream/workspace/project_name/master_window_name

If the project containing the master window is running in the same Manager as the project containing the mirror window, you can use a relative name that omits "ccl://hostname:port".

The MIRROR clause replaces the KEEP clause in a mirror window definition; the window retention policy is defined for the master window. The optional PROPERTIES clause allows you to specify values for the filter columns defined in the PROPERTIES clause of the master window, which restricts the rows in the mirror to those with the specified filter values in the filter columns. You specify filter values in CSV format and list them in the same order as the filter columns definition on the master window. Filter values can be omitted from a mirror window even if the master defines filter columns, but if filter values are included, a value must be specified for every filter column.

Use the FILTEREXPR property to specify an expression for filtering purposes, regardless of whether or not the master window is defined with the FILTERCOLUMNS property. If including this property, the mirror only receives rows for which the expression evaluates to True. The expression is a standard CCL Boolean scalar expression, such as the following:

FILTEREXPR="Symbol=IBM AND Price>10"

Note that you cannot include any of the following in the filter expression:

However, you can include user-defined scalar functions and the zero-argument variant of GETTIMESTAMP().

Considerations

When a project that contains a mirror window starts up, the contents of its master window are copied to the mirror. This has a negative performance impact on the project containing the master window. How large an impact depends on the size of the window, the number of projects containing mirror windows starting at the same time, and how much optimization Sybase CEP Server can achieve (if both projects are running on the same server, Sybase CEP Server copies pointers instead of actual row contents). To reduce the performance impact, especially if your master and mirror projects are on separate servers, consider limiting the rows to be copied by using filter columns and also limiting the number of mirror windows that depend on the same master window.

Output from a mirror window does not begin until the entire initial copy has been received from the master window. After the initial copy, the mirror window changes in concert with the master window, receiving the same insertions, deletions, and updates within the constraints of any defined filters.

If the project containing a master window starts or restarts while a project containing a mirror of that master is running, the mirror replaces its contents with a fresh copy of the master window once that project has restarted.

Examples

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;