Pattern Matching

Use the MATCHING clause in your CCL query to take input from one or more elements (streams, windows, or delta streams) and produce records when a prescribed pattern is found within the input data.

Pattern streams can check whether or not events (rows from the input sources matching certain criteria) occur during a specific time interval, and then send records to downstream streams if a match has occurred.

Pattern matching can be used to distill complex relationships between data into compact and easily-maintainable expressions.

Attention: The pattern rule engine will use any incoming event in order to match the defined pattern, regardless of the opcode of an incoming event. The opcode can be included in each event's definition in order to filter out unwanted rows.
This example creates an output stream, ThreeTrades, which monitors the QTrades streams and sends a new event when it detects three trades on the same symbol within five seconds. The output of this stream is the symbol of the traded stock, and its latest three prices. The trades do not have to occur consecutively, but the trades must occur within five seconds of each other. Multiple patterns may be in the process of being matched at the same time.
CREATE OUTPUT STREAM ThreeTrades
AS 
SELECT 
		T1.Symbol, 
		T1.Price Price1,
		T2.Price Price2,
		T3.Price Price3
FROM QTrades T1, QTrades T2, QTrades T3
MATCHING[5 SECONDS: T1, T2, T3]
ON T1.Symbol = T2.Symbol = T3.Symbol
;

For details on the MATCHING clause, see the SAP Sybase Event Stream Processor Programmers Reference.