ELEMENT_TIME for a System-Timestamped Stream

3-2 Oracle Complex Event Processing CQL Language Reference For more information, see System-Timestamped Channels in the Oracle Complex Event Processing Developers Guide for Eclipse.

3.2.1.2 ELEMENT_TIME for an Application-Timestamped Stream

In this case, the associated element time is assigned by the application using the application assembly file wlevs:expression element to specify a derived timestamp expression. Oracle CEP processes the result of this expression as follows: ■ Section 3.2.1.2.1, Dervied Timestamp Expression Evalutes to int or bigint ■ Section 3.2.1.2.2, Dervied Timestamp Expression Evalutes to timestamp For more information, see Application-Timestamped Channels in the Oracle Complex Event Processing Developers Guide for Eclipse.

3.2.1.2.1 Dervied Timestamp Expression Evalutes to int or bigint If the dervied timestamp

expression evaluates to an Oracle CQL native type of int, then it is cast to and returned as a corresponding bigint value. If the expression evaluates to an Oracle CQL native type of bigint, that value is returned as is.

3.2.1.2.2 Dervied Timestamp Expression Evalutes to timestamp If the derived timestamp

expression evaluates to an Oracle CQL native type of timestamp, it is converted to a long value by expressing this time value as the number of milliseconds since the standard base time known as the epoch, namely January 1, 1970, 00:00:00 GMT.

3.2.2 Using the ELEMENT_TIME Pseudocolumn in Oracle CQL Queries

This section describes how to use ELEMENT_TIME in various queries, including: ■ Section 3.2.2.1, Using ELEMENT_TIME With SELECT ■ Section 3.2.2.2, Using ELEMENT_TIME With GROUP BY ■ Section 3.2.2.3, Using ELEMENT_TIME With PATTERN

3.2.2.1 Using ELEMENT_TIME With SELECT

Example 3–1 shows how you can use the ELEMENT_TIME pseudocolumn in a select statement. Stream S1 has schema c1 integer. Given the input stream that Example 3–2 shows, this query returns the results that Example 3–3 shows. Note that the function to_timestamp is used to convert the Long values to timestamp values. Example 3–1 ELEMENT_TIME Pseudocolumn in a Select Statement query id=q4[CDATA[ select c1, to_timestampelement_time from S1[range 10000000 nanoseconds slide 10000000 nanoseconds] ]]query Example 3–2 Input Stream Timestamp Tuple 8000 80 9000 90 13000 130 15000 150 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