Using a Native CQL Type as a return-component-type

18 Oracle CQL Queries, Views, and Joins 18-1 18 Oracle CQL Queries, Views, and Joins You select, process, and filter element data from streams and relations using Oracle CQL queries and views. A top-level SELECT statement that you create using the QUERY statement is called a query . A top-level VIEW statement that you create using the VIEW statement is called a view the Oracle CQL equivalent of a subquery. A join is a query that combines rows from two or more streams, views, or relations. This chapter describes: ■ Section 18.1, Introduction to Oracle CQL Queries, Views, and Joins ■ Section 18.2, Queries ■ Section 18.3, Views ■ Section 18.4, Joins ■ Section 18.5, Oracle CQL Queries and the Oracle CEP Server Cache ■ Section 18.6, Oracle CQL Queries and Relational Database Tables ■ Section 18.7, Oracle CQL Queries and Oracle Data Cartridges For more information, see: ■ Section 1.2.1, Lexical Conventions ■ Section 1.2.3, Documentation Conventions ■ Chapter 2, Basic Elements of Oracle CQL ■ Chapter 7, Common Oracle CQL DDL Clauses ■ Chapter 20, Oracle CQL Statements

18.1 Introduction to Oracle CQL Queries, Views, and Joins

An Oracle CQL query is an operation that you express in Oracle CQL syntax and execute on an Oracle CEP CQL Processor to process data from one or more streams or views. For more information, see Section 18.2, Queries . An Oracle CQL view represents an alternative selection on a stream or relation. In Oracle CQL, you use a view instead of a subquery. For more information, see Section 18.3, Views . Oracle CEP performs a join whenever multiple streams appear in the FROM clause of the query. For more information, see Section 18.4, Joins . 18-2 Oracle Complex Event Processing CQL Language Reference Example 18–1 shows typical Oracle CQL queries defined in an Oracle CQL processor component configuration file for the processor named proc. Example 18–1 Typical Oracle CQL Query ?xml version=1.0 encoding=UTF-8? n1:config xsi:schemaLocation=http:www.bea.comnswlevsconfigapplication wlevs_application_ config.xsd xmlns:n1=http:www.bea.comnswlevsconfigapplication xmlns:xsi=http:www.w3.org2001XMLSchema-instance processor nameprocname rules view id=lastEvents schema=cusip mbid srcId bidQty ask askQty seq[CDATA[ select cusip, modbid as mbid, srcId, bidQty, ask, askQty, seq from filteredStream[partition by srcId, cusip rows 1] ]]view query id=q1[CDATA[ SELECT FROM lastEvents [Range Unbounded] WHERE price 10000 ]]query rules processor n1:config As Example 18–1 shows, the rules element contains each Oracle CQL statement in a view or query child element: ■ view: contains Oracle CQL view statements the Oracle CQL equivalent of subqueries. The view element id attribute defines the name of the view. In Example 18–1 , the view element specifies an Oracle CQL view statement the Oracle CQL equivalent of a subquery. ■ query: contains Oracle CQL select statements. The query element id attribute defines the name of the query. In Example 18–1 , the query element specifies an Oracle CQL query statement. The query statement selects from the view. By default, the results of a query are output to a down-stream channel. You can control this behavior in the channel configuration using a selector element. For more information, see Configuring a Channel in the Oracle Complex Event Processing Developers Guide for Eclipse. Each Oracle CQL statement is contained in a [CDATA[ ... ]] tag and does not end in a semicolon ;. For more information, see: ■ Section 18.1.1, How to Create an Oracle CQL Query ■ Section 1.2.1, Lexical Conventions ■ Chapter 20, Oracle CQL Statements

18.1.1 How to Create an Oracle CQL Query

Typically, you create an Oracle CQL query or view using the Oracle CEP IDE for Eclipse. After deployment, you can add, change, and delete Oracle CQL queries using the Oracle CEP Visualizer. Oracle CQL Queries, Views, and Joins 18-3 To create an Oracle CQL query: 1. Using Oracle CEP IDE for Eclipse, create an Oracle CEP application and Event Processing Network EPN. For more information, see: ■ Oracle CEP IDE for Eclipse Projects in the Oracle Complex Event Processing Developers Guide for Eclipse. ■ Oracle CEP IDE for Eclipse and the Event Processing Network in the Oracle Complex Event Processing Developers Guide for Eclipse.

2. In the EPN Editor, right-click an Oracle CQL processor and select Go to

Configuration Source as Figure 18–1 shows. Figure 18–1 Navigating to the Configuration Source of a Processor from the EPN Editor The EPN Editor opens the corresponding component configuration file for this processor and positions the cursor in the appropriate processor element as Figure 18–2 shows. 18-4 Oracle Complex Event Processing CQL Language Reference Figure 18–2 Editing the Configuration Source for a Processor 3. Create queries and views and register user-defined functions and windows. For examples, see ■ Section 18.2, Queries ■ Section 18.3, Views ■ Section 18.4, Joins ■ Section 18.7, Oracle CQL Queries and Oracle Data Cartridges ■ Section 18.5, Oracle CQL Queries and the Oracle CEP Server Cache ■ Chapter 4, Operators ■ Chapter 5, Expressions ■ Chapter 6, Conditions ■ Chapter 8, Built-In Single-Row Functions ■ Chapter 9, Built-In Aggregate Functions ■ Chapter 10, Colt Single-Row Functions ■ Chapter 11, Colt Aggregate Functions ■ Chapter 12, java.lang.Math Functions ■ Chapter 13, User-Defined Functions ■ Chapter 19, Pattern Recognition With MATCH_RECOGNIZE ■ Chapter 20, Oracle CQL Statements Oracle CQL Queries, Views, and Joins 18-5 ■ Oracle Complex Event Processing Getting Started 4. Using Oracle CEP IDE for Eclipse, package your Oracle CEP application and deploy to the Oracle CEP server. For more information, see Assembling and Deploying Oracle CEP Applications in the Oracle Complex Event Processing Developers Guide for Eclipse. 5. After deployment, use the Oracle CEP Visualizer to change, add, and delete queries in the Oracle CEP application. For more information, see Managing Oracle CQL Rules in the Oracle Complex Event Processing Visualizer Users Guide.

18.2 Queries

Queries are the principle means of extracting information from data streams and views. query::= The query clause itself is made up of one of the following parts: ■ sfw_block: use this select-from-where clause to express a CQL query. For more information, see Section 18.2.1.1, Select, From, Where Block . ■ idstream_clause: use this clause to specify an input IStream or delete DStream relation-to-stream operator that applies to the query. For more information, see Section 18.2.1.9, IDStream Clause ■ rstream: use this clause to specify an RStream relation-to-stream operator that applies to the query. For more information, see RStream Relation-to-Stream Operator on page 4-26 ■ binary: use this clause to perform set operations on the tuples that two queries or views return. For more information, see Section 18.2.1.8, Binary Clause The following sections discuss the basic query types that you can create: ■ Section 18.2.2, Simple Query ■ Section 18.2.3, Built-In Window Query ■ Section 18.2.4, MATCH_RECOGNIZE Query ■ Section 18.2.5, Relational Database Table Query ■ Section 18.2.6, XMLTable Query ■ Section 18.2.7, Function TABLE Query