Using WITH Clause to Keep LargestSmallestUnique Values

EPL Reference: Clauses 2-11 symbol and not other windows for different stock symbols. Thus, in this case, only the average price of AAA would be affected.

2.4.7 Using WITH Clause to Keep LargestSmallestUnique Values

The WITH clause allows the largest, smallest, and unique property values to be kept in the window. For example, to keep the two highest priced stocks, the following statement would be used: SELECT stockSymbol, price FROM StockTick RETAIN ALL WITH 2 LARGEST price In the case of time-based windows, the [n] qualifier before the LARGEST or SMALLEST keyword determines how many values are kept. For example, the following statement would keep the two smallest prices seen over one minute: SELECT stockSymbol, price FROM StockTick RETAIN 1 MINUTE WITH 2 SMALLEST price In the absence of this qualifier, the single largest or smallest value is kept. The UNIQUE qualifier causes the window to include only the most recent among events having the same value for the specified property. For example, the following query would keep only the last stock tick for each unique stock symbol: SELECT FROM StockTick RETAIN 1 DAY WITH UNIQUE stockSymbol Prior events of the same property value would be posted as old events by the engine.

2.5 MATCHING

Either a MATCHING or a FROM clause must appear in an EPL statement. The MATCHING clause is an alternate mechanism for determining which events are used by the EPL statement. It allows for the detection of a series of one or more events occurring that satisfies a specified pattern. Pattern expressions consist of references to streams separated by logical operators such as AND, OR, and FOLLOWED BY to define the sequence of events that compose the pattern. You may include an optional RETAIN clause, as specified in Section 2.4, RETAIN, to define the characteristics of the window containing the matched events. The MATCHING clause executes prior to the WHERE or HAVING clauses. The MATCHING clause syntax is as follows: MATCHING pattern_expression [RETAIN retain_clause] with pattern_expression having the following syntax: [NOT|EVERY] stream_expression AND | OR | [NOT] FOLLOWED BY stream_expression [WITHIN time_interval] You can use the NOT operator to detect the absence of an event and the EVERY operator to control how pattern matching continues after a match. The stream_ expression is a stream source name optionally bound to a variable and filtered by a parenthesized expression: stream_expression: [var_name:=]stream_name [ filter_expression ]