Computing Rates per Feed Computing Highest Priced Stocks Segmenting Location Data

Overview of the Event Processing Language EPL 1-15 causing the engine to call the update listener only once when the second Withdrawal event is received: SELECT ISTREAM COUNT AS mycount FROM Withdrawal RETAIN ALL HAVING COUNT = 2

1.4 Use Cases

The use cases below illustrate through examples usage of various language features.

1.4.1 Computing Rates per Feed

For the throughput statistics and to detect rapid fall-off we calculate a ticks per second rate for each market data feed. We can use an EPL statement that batches together 1 second of events from the market data event stream source. We specify the feed and a count of events per feed as output values. To make this data available for further processing, we insert output events into the TicksPerSecond event stream: INSERT INTO TicksPerSecond SELECT feed, COUNT AS cnt FROM MarketDataEvent RETAIN BATCH OF 1 SECOND GROUP BY feed

1.4.2 Computing Highest Priced Stocks

For computing the highest priced stocks, we define a sliding window that retains 100 events for each unique stock symbol where the block size of the trade is greater than 10. For example, if there are 5,000 stock symbols, then 5,000 x 100 or 5,000,000 events would be kept. Only MarketTrade events with a block size of greater than 10 will enter the window and only the 100 highest priced events will be retained. The results will be grouped by stock symbol and ordered alphabetically with stock symbols having an average price of less than 100 being filtered from the output. SELECT symbol, AVGprice FROM SELECT FROM MarketTrade WHERE blockSize 10 RETAIN 100 EVENTS WITH LARGEST price PARTITION BY symbol GROUP BY symbol HAVING AVGprice = 100 ORDER BY symbol

1.4.3 Segmenting Location Data

We detect the route a car is taking based on the car location event data that contains information about the location and direction of a car on a highway. We first segment the data by carId to isolate information about a particular car and subsequently segment by expressway, direction and segment to plot its direction. We are then able to calculate the speed of the car based on this information. The first PARTITION BY carId groups car location events by car while the following PARTITION BY expressway PARTITION BY direction further segment the data by more detailed location and direction property values. The number of events retained, 4 in this query, applies to the maximum number kept for the last PARTITION BY clause. Thus at most 4 events will be kept for each distinct segment property value. 1-16 Oracle Complex Event Processing EPL Language Reference SELECT carId, expressway, direction, SUMsegmentMAXtimestamp-MINtimestamp AS speed FROM CarLocationEvent RETAIN 4 events PARTITION BY carId PARTITION BY expressway PARTITION BY direction

1.4.4 Detecting Rapid Fall-off