Pattern Detection MATCH_RECOGNIZE Examples

19-32 Oracle Complex Event Processing CQL Language Reference Example 19–35 PATTERN Clause and WITHIN Clause query id=queryWithin[CDATA[ SELECT T.Ac2, T.Bc2, T.Cc2 FROM S MATCH_RECOGNIZE MEASURES A.c2 as Ac2, B.c2 as Bc2, C.c2 as Cc2 PATTERN A B+ | C within 3000 milliseconds DEFINE A as A.c1=10 or A.c1=25, B as B.c1=20 or B.c1=15 or B.c1=25, C as C.c1=15 as T ]]query Example 19–36 PATTERN Clause and WITHIN INCLUSIVE Clause query id=queryWithinInclusive[CDATA[ SELECT T.Ac2, T.Bc2, T.Cc2 FROM S MATCH_RECOGNIZE MEASURES A.c2 as Ac2, B.c2 as Bc2, C.c2 as Cc2 PATTERN A B+ | C within inclusive 3000 milliseconds DEFINE A as A.c1=10 or A.c1=25, B as B.c1=20 or B.c1=15 or B.c1=25, C as C.c1=15 as T ]]query Example 19–37 Pattern Detection With the WITHIN Clause: Stream Input Timestamp Tuple 1000 10,100 h 2000 3000 15,200 3000 20,300 4000 25,400 5000 20,500 6000 20,600 7000 35,700 8000 10,800 9000 15,900 h 11000 11000 20,1000 11000 50,1100 As Table 19–3 shows for the queryWithin query, the candidate match starts with the event at TimeStamp=1000 and since the WITHIN clause duration is 3 seconds, the query will output the match only if it completes before the event at TimeStamp=4000. When the query receives the event at TimeStampe=4000, the longest match up to that point since we are not using ALL MATCHES is output. Note that although the event at TimeStamp=4000 matches B, it is not included in the match. The next match starts with the event at TimeStamp=4000 since that event also matches A and the previous match ends at TimeStamp=3000. Table 19–3 WITHIN and WITHIN INCLUSIVE Query Output Query queryWithin Query queryWithinInclusive Timestamp Tuple Kind Tuple 3000: + 100,300, 6000: + 400,600, 9000: + 800,900, Timestamp Tuple Kind Tuple 4000: + 100,400, 11000: + 800,1000, Pattern Recognition With MATCH_RECOGNIZE 19-33 As Table 19–3 shows for the queryWithinInclusive query, the candidate match starts with the event at TimeStamp=1000. When the query receives the event at TimeStamp=4000, that event is included in the match because the query uses WITHIN INCLUSIVE and the event matches B. Note that although the event at TimeStamp=5000 matches B, the pattern is not grown further since it exceeds the duration 3 seconds measured from the start of the match TimeStamp=1000. Since this match ends at TimeStamp=4000 and we are not using ALL MATCHES, the next match does not start at TimeStamp=4000, even though it matches A. For more information, see: ■ Section 19.8, WITHIN Clause ■ Section 19.7, ALL MATCHES Clause

19.12.5 Fixed Duration Non-Event Detection

Consider an object that moves among five different rooms. Each time it starts from room 1, it must reach room 5 within 5 minutes. Figure 19–3 shows the object’s performance. This data can be represented as a stream of time and room number. Note that when the object started from room 1 at time 1, it reached room 5 at time 5, as expected. However, when the object started from room 1 at time 6, it failed to reach room 5 at time 11; it reached room 5 at time 12. When the object started from room 1 at time 15, it was in room 5 at time 20, as expected. However, when the object started from room 1 at time 23, it failed to reach room 5 at time 28; it reached room 5 at time 30. The successes at times 5 and 20 are considered events: the arrival of the object in room 5 at the appropriate time. The failures at time 11 and 28 are considered non-events: the expected arrival event did not occur. Using Oracle CQL, you can query for such non-events. Figure 19–3 Fixed Duration Non-Event Detection Example 19–38 shows query q on stream S with schema c1 integer representing room number that detects these non-events. Each time the object fails to reach room 5 within 5 minutes of leaving room 1, the query returns the time of departure from room 1.