Recurring Non-Event Detection DURATION Clause

Pattern Recognition With MATCH_RECOGNIZE 19-27 Example 19–28 MATCH_RECOGNIZE with SUBSET Clause Stream Input Timestamp Tuple 1000 1,8 2000 2,8 3000 3,8 4000 4,6 5000 5,3 6000 6,7 7000 7,6 8000 8,2 9000 9,6 10000 10,2 11000 11,9 12000 12,9 13000 13,8 14000 14,5 15000 15,0 16000 16,9 17000 17,2 18000 18,0 19000 19,2 20000 20,3 21000 21,8 22000 22,5 23000 23,9 24000 24,9 25000 25,4 26000 26,7 27000 27,2 28000 28,8 29000 29,0 30000 30,4 31000 31,4 32000 32,7 33000 33,8 34000 34,6 35000 35,4 36000 36,5 37000 37,1 38000 38,7 39000 39,5 40000 40,8 41000 41,6 42000 42,6 43000 43,0 44000 44,6 45000 45,8 46000 46,4 47000 47,3 48000 48,8 49000 49,2 50000 50,5 51000 51,3 52000 52,3 53000 53,9 54000 54,8 55000 55,5 56000 56,5 57000 57,9 58000 58,7 59000 59,3 60000 60,3 Example 19–29 MATCH_RECOGNIZE with SUBSET Clause Stream Output Timestamp Tuple Kind Tuple 19-28 Oracle Complex Event Processing CQL Language Reference 9000: + 3,9,25,13,5.428571 21000: + 12,21,24,22,4.6 28000: + 24,28,15,15,6.0 38000: + 33,38,19,12,5.1666665 48000: + 42,48,13,22,5.0 For more information, see: ■ Section 19.1.3.1, Running Aggregates and Final Aggregates ■ Section 19.2, MEASURES Clause ■ Section 19.3, PATTERN Clause ■ Section 19.4, DEFINE Clause

19.12 MATCH_RECOGNIZE Examples

The following examples illustrate basic MATCH_RECOGNIZE practices: ■ Pattern Detection on page 19-28 ■ Pattern Detection With PARTITION BY on page 19-29 ■ Pattern Detection With Aggregates on page 19-31 ■ Fixed Duration Non-Event Detection on page 19-33 For more examples, see Oracle Complex Event Processing Getting Started.

19.12.1 Pattern Detection

Consider the stock fluctuations that Figure 19–1 shows. This data can be represented as a stream of stock ticks index number or time and stock price. Figure 19–1 shows a common trading behavior known as a double bottom pattern between days 1 and 9 and between days 12 and 19. This pattern can be visualized as a W-shaped change in stock price: a fall X, a rise Y, a fall W, and another rise Z. Figure 19–1 Pattern Detection: Double Bottom Stock Fluctuations Example 19–30 shows a query q on stream S2 of stock price events with schema symbol, stockTick, and price. This query detects double bottom patterns on the incoming stock trades using the PATTERN clause A W+ X+ Y+ Z+. The correlation names in this clause are: ■ A: corresponds to the start point of the double bottom pattern. Pattern Recognition With MATCH_RECOGNIZE 19-29 Because correlation name A is true for every input, it is not defined in the DEFINE clause. If you specify a correlation name that is not defined in the DEFINE clause, it is considered to be true for every input. ■ W+: corresponds to the first decreasing arm of the double bottom pattern. It is defined by W.price prevW.price. This definition implies that the current price is less than the previous one. ■ X+: corresponds to the first increasing arm of the double bottom pattern. ■ Y+: corresponds to the second decreasing arm of the double bottom pattern. ■ Z+: corresponds to the second increasing arm of the double bottom pattern. Example 19–30 Simple Pattern Detection: Query query id=q[CDATA[ SELECT T.firstW, T.lastZ FROM S2 MATCH_RECOGNIZE MEASURES A.stockTick as firstW, lastZ as lastZ PATTERNA W+ X+ Y+ Z+ DEFINE W as W.price prevW.price, X as X.price prevX.price, Y as Y.price prevY.price, Z as Z.price prevZ.price as T WHERE S2.symbol = oracle ]]query

19.12.2 Pattern Detection With PARTITION BY

Consider the stock fluctuations that Figure 19–2 shows. This data can be represented as a stream of stock ticks index number or time and stock price. In this case, the stream contains data for more than one stock ticker symbol. Figure 19–2 shows a common trading behavior known as a double bottom pattern between days 1 and 9 and between days 12 and 19 for stock BOFA. This pattern can be visualized as a W-shaped change in stock price: a fall X, a rise Y, a fall W, and another rise Z.