The Splitter construct is a multi-way filter that sends data to different target streams depending on the filter condition. It works similar to the ANSI 'case' statement.
CREATE [[LOCAL]|OUTPUT] SPLITTER name AS { WHEN condition THEN {target_streamname [, …]} } […] [ ELSE {target_streamname[,..]} ] SELECT { column_list | * } FROM source_name [{[alias] [KeepClause]}|{[KeepClause][alias]}] ;
condition |
Any expression that results in a 0 or 1. |
name | Any string specified to identify the splitter construct. Must be unique within a module or top level project. |
target_streamname |
Name of a stream or delta stream into which the filtered records are inserted. Must be unique within the module or top level project. |
source_name |
The source (stream, window, or delta stream) that provides input data on which the splitter logic is applied. |
column_list |
A set of expressions referring only to the columns in the source stream, constant expressions, constant literals, global variables and functions, or parameters. |
The target stream or delta streams are implicitly defined by the compiler. The schema for the target streams are derived based on the column_list specification. All the targets are defined as either local or output depending on the visibility clause defined for the splitter. The default is local. Note that when the splitter has an output visibility, output adapters can be directly attached to the splitter targets, even though those targets are implicitly defined.
Local DECLARE BLOCKS cannot be specified on SPLITTERS. However, functions, parameters, and variables in the global DECLARE BLOCK can be accessed in the condition or column expressions in the projection.
Create a Splitter
In the following example, if a trade event arrives where the Symbol is IBM or ORCL, then the event is directed to both ProcessHardWareStock and ProcessSoftwareStock streams. If a trade event arrives where the Symbol is either 'SAP' or 'MSFT', then it is directed to the ProcessSoftwareStock stream. All other trades are directed to the ProcessOtherStock stream.
CREATE SPLITTER Splitter1 AS WHEN Trades.Symbol IN ('IBM', 'ORCL' ) THEN ProcessHardWareStock, ProcessSoftwareStock WHEN Trades.Symbol IN ('SAP', 'MSFT') THEN ProcessSoftwareStock ELSE ProcessOtherStock SELECT * FROM Trades;
A splitter is typically more efficient both in terms of CPU utilization and throughput when there is more than a two way split than an equivalent construct composed of two or more streams that implement a filter. Unlike other streams in ESP, a Splitter and all its target streams run in a single thread. This means that the Splitter thread is responsible for distributing data to its dependents.
However, note that because the splitter is single threaded, its performance advantage degrades quickly when it needs to distribute the same data more than once. For example, there is more than one target stream for each filter condition or when the target streams themselves have many dependents.