2-10 Oracle Complex Event Processing EPL Language Reference
2.4.4.1 BASED ON Clause
By default, the elapse of a time interval is based on the internal system clock. However, in some cases, the time needs to be based on a timestamp value appearing
as an event property. In this case, the BASED ON clause may be used to specify the property name containing a long-typed timestamp value. In this example, the
StockTick events would be expected to have a timestamp property of type long whose value would control inclusion into and removal from the window:
SELECT AVGprice FROM StockTick RETAIN 1 MINUTE BASED ON timestamp
When using the BASED ON clause, each stream source listed in the FROM clause must have an associated timestamp property listed or Oracle CEP will throw an exception.
2.4.5 Specifying Property Name
A property may be referred to by simply using its property name within the RETAIN clause. However, if ambiguities exist because the same property name exists in more
than one stream source in the FROM clause, it must be prefixed with its alias name followed by a period similar to the behavior of properties referenced in the SELECT
clause.
2.4.6 Using PARTION BY Clause to Partition Window
The PARTITION BY clause allows a window to be further subdivided into multiple windows based on the unique values contained in the properties listed. For example,
the following query would keep 3 events for each unique stock symbol:
SELECT stockSymbol, price FROM StockTick RETAIN 3 EVENTS PARTITION BY stockSymbol
Conceptually this is similar to the GROUP BY functionality in SQL or EPL. However, the PARTITION BY clause only controls the size and subdivision of the window and
does not cause event data to be aggregated as with the GROUP BY clause. However, in most cases, the PARTITION BY clause is used in conjunction with the GROUP BY
clause with same properties specified in both.
The following examples illustrate the interaction between PARTITION BY and GROUP BY. In the first example, with the absence of the PARTITION BY clause, a total of 10
events will be kept across all stock symbols.
SELECT stockSymbol, AVGprice FROM StockTick RETAIN 10 EVENTS
GROUP BY stockSymbol
The average price for each unique set of stock symbol will be computed based on these 10 events. If a stock symbol of AAA comes into the window, it may cause a different
stock symbol such as BBB to leave the window. This would cause the average price for both the AAA group as well as the BBB group to change.
The second example includes the PARTITION BY clause and the GROUP BY clause. SELECT stockSymbol, AVGprice
FROM StockTick RETAIN 10 EVENTS PARTITION BY stockSymbol GROUP BY stockSymbol
In this case, 10 events will be kept for each unique stock symbol. If a stock symbol of AAA comes into the window, it would only affect the sub-window associated with that
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