Using ELEMENT_TIME With SELECT

Pseudocolumns 3-3 23000 230 25000 250 Example 3–3 Output Relation Timestamp Tuple Kind Tuple 8000 + 80,12311969 17:00:08 8010 - 80,12311969 17:00:08 9000 + 90,12311969 17:00:09 9010 - 90,12311969 17:00:09 13000 + 130,12311969 17:00:13 13010 - 130,12311969 17:00:13 15000 + 150,12311969 17:00:15 15010 - 150,12311969 17:00:15 23000 + 230,12311969 17:00:23 23010 - 230,12311969 17:00:23 25000 + 250,12311969 17:00:25 25010 - 250,12311969 17:00:25 If your query includes a GROUP BY clause, you cannot use the ELEMENT_TIME pseudocolumn in the SELECT statement directly. Instead, use a view as Section 3.2.2.2, Using ELEMENT_TIME With GROUP BY describes.

3.2.2.2 Using ELEMENT_TIME With GROUP BY

Consider query Q1 that Example 3–4 shows. You cannot use ELEMENT_TIME in the SELECT statement of the query because of the GROUP BY clause. Example 3–4 Query With GROUP BY query id=Q1[CDATA[ SELECT R.queryText AS queryText, COUNT AS queryCount FROM queryEventChannel [range 30 seconds] AS R GROUP BY queryText ]]query Instead, create a view as Example 3–5 shows. The derived stream corresponding to V1 will contain a stream element each time queryText, queryCount, maxTime changes for a specific queryText group. Example 3–5 View view id=V1[CDATA[ ISTREAM SELECT R.queryText AS queryText, COUNT AS queryCount, MAXR.ELEMENT_TIME as maxTime FROM queryEventChannel [range 30 seconds] AS R GROUP BY queryText ]]view Note that the element time associated with an output element of view V1 need not be the same as the value of the attribute maxTime for that output event. For example, as the window slides and an element from the queryEventChannel input stream expires 3-4 Oracle Complex Event Processing CQL Language Reference from the window, the queryCount for that queryText group would change resulting in an output. However, since there was no new event from the input stream queryEventChannel entering the window, the maxTime among all events in the window has not changed, and the value of the maxTime attribute for this output event would be the same as the value of this attribute in the previous output event. However, the ELEMENT_TIME of the output event corresponds to the instant where the event has expired from the window, which is different than the latest event from the input stream, making this is an example where ELEMENT_TIME of the output event is different from value of maxTime attribute of the output event. To select the ELEMENT_TIME of the output events of view V1, create a query as Example 3–6 shows. Example 3–6 Query query id=Q1[CDATA[ SELECT queryText, queryCount, ELEMENT_TIME as eventTime FROM V1 ]]query

3.2.2.3 Using ELEMENT_TIME With PATTERN

Example 3–7 shows how the ELEMENT_TIME pseudocolumn can be used in a pattern query. Here a tuple or event matches correlation variable Nth if the value of Nth.status is = F.status and if the difference between the Nth.ELEMENT_TIME value of that tuple and the tuple that last matched F is less than the given interval as a java.lang.Math.BigintLong. Example 3–7 ELEMENT_TIME Pseudocolumn in a Pattern ... PATTERN F Nth+? L DEFINE Nth AS Nth.status = F.status AND Nth.ELEMENT_TIME - F.ELEMENT_TIME 10000000000L, L AS L.status = F.status AND countNth. = 3 AND L.ELEMENT_TIME - F.ELEMENT_TIME 10000000000L ...