19-22 Oracle Complex Event Processing CQL Language Reference
For more information, see Section 19.12.4, Pattern Detection With the WITHIN
Clause .
19.9 DURATION Clause
The DURATION clause is an optional clause that you should use only when writing a query involving non-event detection. Non-event detection is the detection of a
situation when a certain event which should have occurred in a particular time limit does not occur in that time frame.
duration_clause::=
time_unit::= on page 7-29
Using this clause, a match is reported only when the regular expression in the PATTERN clause is matched completely and no other event or input arrives until the
duration specified in the DURATION clause expires. The duration is measured from the time of arrival of the first event in the pattern match.
You must use the INCLUDE TIMER EVENTS clause when using the DURATION clause. For more information, see
Section 19.10, INCLUDE TIMER EVENTS Clause .
This section describes:
■
Section 19.9.1, Fixed Duration Non-Event Detection
■
Section 19.9.2, Recurring Non-Event Detection
19.9.1 Fixed Duration Non-Event Detection
The duration can be specified as a constant value, such as 10. Optionally, you may specify a time unit such as seconds or minutes see
time_unit::= on page 7-29; the
default time unit is seconds. Consider the query tkpattern_q59 in
Example 19–21 that uses DURATION 10 to
specify a delay of 10 s 10000 ms and the data stream tkpattern_S19 in Example 19–22
. Stream tkpattern_S19 has schema c1 integer. The query returns the stream in
Example 19–23 .
Example 19–21 MATCH_RECOGNIZE with Fixed Duration DURATION Clause Query
query id=BBAQuery[CDATA[ select
T.p1, T.p2 from
tkpattern_S19 MATCH_RECOGNIZE
MEASURES A.c1 as p1, B.c1 as p2 include timer events
Note: You cannot use a WITHIN clause with a DURATION clause. For
more information, see Section 19.9, DURATION Clause
.
Note: You cannot use a DURATION clause with a WITHIN clause. For
more information, see Section 19.8, WITHIN Clause
.
Pattern Recognition With MATCH_RECOGNIZE 19-23
PATTERNA B duration 10
DEFINE A as A.c1 = 10, B as B.c1 = A.c1 as T
]]query
Example 19–22 MATCH_RECOGNIZE with Fixed Duration DURATION Clause Stream
Input
Timestamp Tuple
1000 10
4000 22
6000 444
7000 83
9000 88
11000 12
11000 22
11000 15
12000 13
15000 10
27000 11
28000 10
30000 18
40000 10
44000 19
52000 10
h 100000
Example 19–23 MATCH_RECOGNIZE with Fixed DURATION Clause Stream Output
Timestamp Tuple Kind
Tuple 11000:
+ 10,88
25000: +
10, 38000:
+ 10,18
50000: +
10,19 62000:
+ 10,
The tuple at time 1000 matches A. Since the duration is 10 we output a match as soon as input at time
1000+10000=11000 is received the one with the value 12. Since the sequence of tuples from 1000 through 9000 match the pattern AB and nothing else a match is
reported as soon as input at time 11000 is received.
The next match starts at 15000 with the tuple at that time matching A. The next tuple that arrives is at 27000. So here also we have tuples satisfying pattern AB and nothing
else and hence a match is reported at time 15000+10000=25000. Further output is generated by following similar logic.
For more information, see Fixed Duration Non-Event Detection
on page 19-33.
19.9.2 Recurring Non-Event Detection
When you specify a MULTIPLES OF clause, it indicates recurring non-event detection. In this case an output is sent at the multiples of duration value as long as there is no
event after the pattern matches completely.
Consider the query tkpattern_q75 in Example 19–24
that uses DURATION MULTIPLES OF 10 to specify a delay of 10 s 10000 ms and the data stream
tkpattern_S23 in Example 19–25
. Stream tkpattern_S23 has schema c1 integer. The query returns the stream in
Example 19–26 .
19-24 Oracle Complex Event Processing CQL Language Reference
Example 19–24 MATCH_RECOGNIZE with Variable Duration DURATION MULTIPLES OF
Clause Query
query id=tkpattern_q75[CDATA[ select
T.p1, T.p2, T.p3 from
tkpattern_S23 MATCH_RECOGNIZE
MEASURES A.c1 as p1, B.c1 as p2, sumB.c1 as p3 ALL MATCHES
include timer events PATTERNA B
duration multiples of 10 DEFINE A as A.c1 = 10, B as B.c1 = A.c1
as T ]]query
Example 19–25 MATCH_RECOGNIZE with Variable Duration DURATION MULTIPLES OF
Clause Stream Input
Timestamp Tuple
1000 10
4000 22
6000 444
7000 83
9000 88
11000 12
11000 22
11000 15
12000 13
15000 10
27000 11
28000 10
30000 18
44000 19
62000 20
72000 10
h 120000
Example 19–26 MATCH_RECOGNIZE with Variable Duration DURATION MULTIPLES OF
Clause Stream Output
Timestamp Tuple Kind
Tuple 11000:
+ 10,88,637
25000: +
10,, 38000:
+ 10,18,18
48000: +
10,19,37 58000:
+ 10,19,37
68000: +
10,20,57 82000:
+ 10,,
92000: +
10,, 102000:
+ 10,,
112000: +
10,,
The execution here follows similar logic to that of the example above for just the DURATION clause see
Fixed Duration Non-Event Detection on page 19-22. The
difference comes for the later outputs. The tuple at 72000 matches A and then there is nothing else after that. So the pattern AB is matched and we get output at 82000.
Since we have the MULTIPLES OF clause and duration 10 we see outputs at time 92000, 102000, and so on.
Pattern Recognition With MATCH_RECOGNIZE 19-25
19.10 INCLUDE TIMER EVENTS Clause
Use this clause in conjunction with the DURATION clause for non-event detection queries.
Typically, in most pattern match queries, a pattern match output is always triggered by an input event on the input stream over which pattern is being matched. The only
exception is non-event detection queries where there could be an output triggered by a timer expiry event as opposed to an explicit input event on the input stream.
pattern_inc_timer_evs_clause::=
pattern_clause::= on page 19-11,
pattern_skip_match_clause::= on page 19-19,
pattern_ definition_clause::=
on page 19-14, duration_clause::=
on page 19-22, subset_clause::=
on page 19-25
For more information, see Section 19.9, DURATION Clause
.
19.11 SUBSET Clause
Using this clause, you can group together one or more correlation variables that are defined in the DEFINE clause. You can use this named subset in the MEASURES and
DEFINE clauses just like any other correlation variable.
For example: SUBSET S1 = Z,X
The right-hand side of the subset Z,X is a comma-separated list of one or more correlation variables as defined in the PATTERN clause.
The left-hand side of the subset S1 is the union of the correlation variables on the right-hand side.
You cannot include a subset variable in the right-hand side of a subset.
subset_clause::=
non_mt_subset_definition_list::= on page 19-25
non_mt_subset_definition_list::=
subset_definition::= on page 19-25
subset_definition::=
subset_name::= on page 19-26,
non_mt_corr_list::= on page 19-26