PK O_\Eoa,mimetypeapplication/epub+zipPKO_\EiTunesMetadata.plist~ artistName Oracle Corporation book-info cover-image-hash 339031241 cover-image-path OEBPS/dcommon/oracle-logo.jpg package-file-hash 323631749 publisher-unique-id E12048-10 unique-id 813583556 genre Oracle Documentation itemName Oracle® Fusion Middleware CQL Language Reference for Oracle Complex Event Processing, 11g Release 1 (11.1.1.6.3) releaseDate 2012-08-03T11:31:31Z year 2012 PK̃~PKO_\EMETA-INF/container.xml PKYuPKO_\EOEBPS/datacartjava.htm Oracle Java Data Cartridge

15 Oracle Java Data Cartridge

This chapter describes how to use the Oracle Java Data Cartridge, an extension of Oracle Continuous Query Language (Oracle CQL) with which you can write CQL code that seamlessly interacts with Java classes in your Oracle CEP application.

This chapter describes the types, methods, fields, and constructors that the Oracle Java data cartridge exposes. You can use these types, methods, fields, and constructors in Oracle CQL queries and views as you would Oracle CQL native types.

This chapter describes:

For more information, see:

15.1 Understanding the Oracle Java Data Cartridge

The Oracle Java data cartridge is a built-in Java cartridge which allows you to write Oracle CQL queries and views that seamlessly interact with the Java classes in your Oracle CEP application.

This section describes:

15.1.1 Data Cartridge Name

The Oracle Java data cartridge uses the cartridge ID com.oracle.cep.cartrdiges.java.

The Oracle Java data cartridge is the default Oracle CEP data cartridge.

For types under the default Java package name or types under the system package of java.lang, you may reference the Java type in an Oracle CQL query unqualified by package or data cartridge name:

<query id="q1"><![CDATA[
    select String(“foo”) …
]]></query>

Note:

To simplify Oracle Java data cartridge type names, you can use aliases as Section 2.7.2, "Defining Aliases Using the Aliases Element" describes.


For more information, see:

15.1.2 Class Loading

The Oracle Java data cartridge supports the following policies for loading the Java classes that your Oracle CQL queries reference:

For more information, see:

15.1.2.1 Application Class Space Policy

This is the default class loading policy.

In this mode, the Oracle Java data cartridge uses the class-space of the application in scope when searching for a Java class.

This is only applicable when a type is specified only by its local name, that is, there is a single identifier, and no other identifiers are being used for its package. That is:

select String(“foo”) …

And not:

select java.lang.String(“foo”) …

In this case the procedure is as follows:

  • Attempt to load the class defined by the single identifier (call it ID1) using the application's class-space as usual; if this fails then:

  • Verify if the application defines any class within its bundle's internal class-path whose name matches ID1, independent of the package; if this fails then:

  • Verify if application specifies an Import-Package MANIFEST header statement which in conjunction with ID1 can be used to load a Java class.

For an example, see Section 15.1.2.4, "Class Loading Example".

15.1.2.2 No Automatic Import Class Space Policy

This is an optional class loading policy. To use this policy, you must include the following MANIFEST header entry in your Oracle CEP application:

OCEP_JAVA_CARTRIDGE_CLASS_SPACE: APPLICATION_NO_AUTO_IMPORT_CLASS_SPACE

This mode is similar to the application class space policy except that Oracle CEP will not attempt to automatically import a package when a package is not specified.

For more information, see Section 15.1.2.1, "Application Class Space Policy".

15.1.2.3 Server Class Space Policy

This is an optional class loading policy. To use this policy, you must include the following MANIFEST header entry in your Oracle CEP application:

OCEP_JAVA_CARTRIDGE_CLASS_SPACE: SERVER_CLASS_SPACE

An Oracle CQL query can reference any exported Java class, regardless of the application or module that is exporting it.

The query can also access all classes visible to the OSGi framework's parent class-loader, which includes the runtime JDK classes.

This means that an Oracle CQL application may contain an Oracle CQL query that references classes defined by other Oracle CEP applications, as long as they are exported. This behavior facilitates the creation of Java-based cartridges whose sole purpose is to provide new Java libraries.


Note:

You may only reference a Java class that is part of the internal class-path of an Oracle CEP application if it is exported, even if a processor within this application defines the Oracle CQL query.


For an example, see Section 15.1.2.4, "Class Loading Example".

15.1.2.4 Class Loading Example

Consider the example that Figure 15-1 shows: application B1 imports package mypackage3 that application B2 exports.

Figure 15-1 Example Oracle CEP Applications

Description of Figure 15-1 follows

Table 15-1 summarizes which classes these two different applications can access depending on whether they are running in the application class space or server class space.

Table 15-1 Class Accessibility by Class Loading Policy

Class Loading PolicyApplication B1Application B2

Application Class Space

  • mypackage1.A

  • myprivatepackage1.B

  • package2.C

  • package2.C

  • privatepackage2.D

Server Class Space

  • package2.C

  • package2.C


In application B1, you can use any of the Java classes A, B, and C in your Oracle CQL queries:

select A …
select B …
select C …

However, in application B2, you cannot use Java classes A and B in your Oracle CQL queries. You can only use Java classes C and D:

select C …
select D …

15.1.3 Method Resolution

An Oracle CQL expression that accesses a Java method uses the following algorithm to resolve the method:

  1. All parameter types are converted to Java types as Section 15.1.4, "Datatype Mapping" describes.

    For example, an Oracle CQL INTEGER is converted to a Java primitive int.

  2. Standard Java method resolution rules are applied as the Java Language Specification, Third Edition, Section 15.12, "Method Invocation Expressions" describes.


Note:

Variable arity methods are not supported. For more information, see the Java Language Specification, Third Edition, Section 12.12.2.4.


As an example, consider the following Oracle CQL expression:

attribute.methodA(10)

Where attribute is of type mypackage.MyType which defines the following overloaded methods:

  • methodA(int)

  • methodA(Integer)

  • methodA(Object)

  • methodA(long)

As the literal 10 is of the primitive type int, the order of precedence is:

  • methodA(int)

  • methodA(long)

  • methodA(Integer)

  • methodA(Object)

For more information, see Section 15.1.2, "Class Loading".

15.1.4 Datatype Mapping

The Oracle Java data cartridge applies a fixed, asymmetrical mapping between Oracle CQL native datatypes and Java datatypes.

  • Table 15-2 lists the mappings between Oracle CQL native datatypes and Java datatypes.

  • Table 15-3 lists the mappings between Java datatypes and Oracle CQL native datatypes.

Table 15-2 Oracle Java Data Cartridge: Oracle CQL to Java Datatype Mapping

Oracle CQL Native DatatypeJava Datatype

BIGINT

longFoot 1 

BOOLEAN

booleanFootref 1

BYTE

byte[]Footref 1

CHAR

java.lang.String

DOUBLE

doubleFootref 1

FLOAT

floatFootref 1

INTEGER

intFootref 1

INTERVAL

longFootref 1

XMLTYPE

java.lang.String


Footnote 1 primitive Java datatype

Table 15-3 Oracle Java Data Cartridge: Java Datatype to Oracle CQL Mapping

Java DatatypeOracle CQL Native Datatype

longFoot 1 

BIGINT

booleanFootref 1

BOOLEAN

byte[]Footref 1

BYTE

java.lang.String

CHAR

doubleFootref 1

DOUBLE

floatFootref 1

FLOAT

intFootref 1

INTEGER

java.sql.Date

java.sql.Timestamp

INTERVAL

java.sql.SQLXML

XMLTYPE


Footnote 1 primitive Java datatype

All other Java classes are mapped as a complex type.

For more information on these datatype mappings:

For more information on Oracle CQL native datatypes and their implicit and explicit datatype conversion, see Section 2.1, "Datatypes".

15.1.4.1 Java Datatype String and Oracle CQL Datatype CHAR

Oracle CQL datatype CHAR is mapped to java.lang.String and java.lang.String is mapped to Oracle CQL datatype CHAR. This means you can access java.lang.String member fields and methods for an attribute defined as Oracle CQL CHAR. For example, if a1 is declared as type Oracle CQL CHAR, then you can write a query like this:

<query id="q1"><![CDATA[ 
    select a1.substring(1,2)
]]></query>

15.1.4.2 Literals

You cannot access member fields and methods on literals, even Oracle CQL CHAR literals. For example, the following query is not allowed:

<query id="q1-forbidden"><![CDATA[ 
    select "hello".substring(1,2)
]]></query>

15.1.4.3 Arrays

Java arrays are converted to Oracle CQL data cartridge arrays, and Oracle CQL data cartridge arrays are converted to Java arrays. This applies to both complex types and simple types.

You can use the data cartridge TABLE clause to access the multiple rows returned by a data cartridge function in the FROM clause of an Oracle CQL query.

For more information, see:

15.1.4.4 Collections

Typically, the Oracle Java data cartridge converts an instance that implements the java.util.Collection interface to an Oracle CQL complex type.

An Oracle CQL query can iterate through the members of the java.util.Collection.

You can use the data cartridge TABLE clause to access the multiple rows returned by a data cartridge function in the FROM clause of an Oracle CQL query.

For more information, see:

15.1.5 Oracle CQL Query Support for the Oracle Java Data Cartridge

You may use Oracle Java data cartridge types in expressions within a SELECT clause and WHERE clause.

You may not use Oracle Java data cartridge types in expressions within an ORDER BY clause.

For more information, see:

15.2 Using the Oracle Java Data Cartridge

This section describes common use-cases that highlight how you can use the Oracle Java data cartridge in your Oracle CEP applications, including:

For more information, see:

15.2.1 How to Query Using the Java API

This procedure describes how to use the Oracle Java data cartridge in an Oracle CEP application that uses one event type defined as a tuple (Student) that has an event property type defined as a Java class (Address.java).

To query with Java classes:

  1. Implement the Address.java class as Example 15-1 shows.

    Example 15-1 Address.java Class

    package test;
    
    class Address {
        String street;
        String state;
        String city;
        String [] phones;
    }
    

    In this example, assume that the Address.java class belongs to this application.

    If the Address.java class belonged to another Oracle CEP application, it must be exported in its parent application. For more information, see Section 15.2.2, "How to Query Using Exported Java Classes".

  2. Define the event type repository as Example 15-2 shows.

    Example 15-2 Event Type Repository

    <event-type-repository>
        <event-type name="Student">
            <properties>
                <property name="name" type="char"/>
                <property name="address" type="Address"/>
            </properties>
        </event-type>
    
        <event-type name="Address">
            <class-name>test.Address</class-name>
        </event-type>
    <event-type-repository>
    

    Because the test.Address class belongs to this application, it can be declared in the event type repository. This automatically makes the class globally accessible within this application; its package does not need to be exported.

  3. Assume that an adapter is providing Student events to channel StudentStream as Example 15-3 shows

    Example 15-3 Channel

    <channel id="StudentStream" event-type="Student"/>
    
  4. Assume that the StudentStream is connected to a processor with the Oracle CQL query q1 that Example 15-4 shows.

    Example 15-4 Oracle CQL Query

    <processor> 
        <rules>
            <query id="q1"><![CDATA[ 
                select 
                    name, 
                    address.street as street, 
                    address.phones[0] as primary_phone 
                from 
                    StudentStream
            ]]></query>
        </rules>
    </processor>
    

    The Oracle Java data cartridge allows you to access the address event property from within the Oracle CQL query using normal Java API.

15.2.2 How to Query Using Exported Java Classes

This procedure describes how to use the Oracle Java data cartridge in an Oracle CEP application that uses one event type defined as a tuple (Student) that has an event property type defined as a Java class (Address.java). In this procedure, the Address.java class belongs to a separate Oracle CEP application. It is exported in its parent application to make it accessible to other Oracle CEP applications deployed to the same Oracle CEP server.

To query with Java classes:

  1. Implement the Address.java class as Example 15-1 shows.

    Example 15-5 Address.java Class

    package test;
    
    class Address {
        String street;
        String state;
        String city;
        String [] phones;
    }
    
  2. Export the test package that contains the Address.java class.

    For more information, see "How to Export a Package" in the Oracle Fusion Middleware Developer's Guide for Oracle Complex Event Processing for Eclipse.

    The test package may be part of this Oracle CEP application or it may be part of some other Oracle CEP application deployed to the same Oracle CEP server as this application.

  3. Define the event type repository as Example 15-2 shows.

    Example 15-6 Event Type Repository

    <event-type-repository>
        <event-type name="Student">
            <property name="name" type="char"/>
            <property name="address" type="Address"/>
        </event-type>
    <event-type-repository>
    
  4. Assume that an adapter is providing Student events to channel StudentStream as Example 15-3 shows

    Example 15-7 Channel

    <channel id="StudentStream" event-type="Student"/>
    
  5. Assume that the StudentStream is connected to a processor with the Oracle CQL query q1 that Example 15-4 shows.

    Example 15-8 Oracle CQL Query

    <processor> 
        <rules>
            <query id="q1"><![CDATA[ 
                select 
                    name, 
                    address.street as street, 
                    address.phones[0] as primary_phone 
                from 
                    StudentStream
            ]]></query>
        </rules>
    </processor>
    

    The Oracle Java data cartridge allows you to access the address event property from within the Oracle CQL query using normal Java API.

PKlIPKO_\EOEBPS/dcommon/oracle.gifJGIF87aiyDT2F'G;Q_oKTC[ 3-Bq{ttsoGc4I)GvmLZ).1)!ꑈ53=Z]'yuLG*)g^!8C?-6(29K"Ĩ0Яl;U+K9^u2,@@ (\Ȱ Ë $P`lj 8x I$4H *(@͉0dа8tA  DсSP v"TUH PhP"Y1bxDǕ̧_=$I /& .)+ 60D)bB~=0#'& *D+l1MG CL1&+D`.1qVG ( "D2QL,p.;u. |r$p+5qBNl<TzB"\9e0u )@D,¹ 2@C~KU 'L6a9 /;<`P!D#Tal6XTYhn[p]݅ 7}B a&AƮe{EɲƮiEp#G}D#xTIzGFǂEc^q}) Y# (tۮNeGL*@/%UB:&k0{ &SdDnBQ^("@q #` @1B4i@ aNȅ@[\B >e007V[N(vpyFe Gb/&|aHZj@""~ӎ)t ? $ EQ.սJ$C,l]A `8A o B C?8cyA @Nz|`:`~7-G|yQ AqA6OzPbZ`>~#8=./edGA2nrBYR@ W h'j4p'!k 00 MT RNF6̙ m` (7%ꑀ;PKl-OJPKO_\EOEBPS/dcommon/oracle-logo.jpgohJFIFC    $.' ",#(7),01444'9=82<.342C  2!!22222222222222222222222222222222222222222222222222'7" }!1AQa"q2#BR$3br %&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz w!1AQaq"2B #3Rbr $4%&'()*56789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz ?( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( (QEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQE!KEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEQEzE7V%ȣOΏ9??:a"\fSrğjAsKJ:nOzO=}E1-I)3(QEQEQEQEQEQEQE֝Hza<["2"pO#f8M[RL(,?g93QSZ uy"lx4h`O!LŏʨXZvq& c՚]+: ǵ@+J]tQ]~[[eϸ (]6A&>ܫ~+כzmZ^(<57KsHf妬Ϧmnẁ&F!:-`b\/(tF*Bֳ ~V{WxxfCnMvF=;5_,6%S>}cQQjsOO5=)Ot [W9 /{^tyNg#ЄGsֿ1-4ooTZ?K Gc+oyڙoNuh^iSo5{\ܹ3Yos}$.nQ-~n,-zr~-|K4R"8a{]^;I<ȤL5"EԤP7_j>OoK;*U.at*K[fym3ii^#wcC'IIkIp$󿉵|CtĈpW¹l{9>⪦׺*ͯj.LfGߍԁw] |WW18>w.ӯ! VӃ :#1~ +މ=;5c__b@W@ +^]ևՃ7 n&g2I8Lw7uҭ$"&"b eZ":8)D'%{}5{; w]iu;_dLʳ4R-,2H6>½HLKܹR ~foZKZ࿷1[oZ7׫Z7R¢?«'y?A}C_iG5s_~^ J5?œ tp]X/c'r%eܺA|4ծ-Ե+ْe1M38Ǯ `|Kյ OVڅu;"d56, X5kYR<̭CiطXԮ];Oy)OcWj֩}=܅s۸QZ*<~%뺃ȶp f~Bðzb\ݳzW*y{=[ C/Ak oXCkt_s}{'y?AmCjޓ{ WRV7r. g~Q"7&͹+c<=,dJ1V߁=T)TR՜*N4 ^Bڥ%B+=@fE5ka}ędܤFH^i1k\Sgdk> ֤aOM\_\T)8靠㡮3ģR: jj,pk/K!t,=ϯZ6(((((((49 xn_kLk&f9sK`zx{{y8H 8b4>ÇНE|7v(z/]k7IxM}8!ycZRQ pKVr(RPEr?^}'ðh{x+ՀLW154cK@Ng C)rr9+c:׹b Жf*s^ fKS7^} *{zq_@8# pF~ [VPe(nw0MW=3#kȵz晨cy PpG#W:%drMh]3HH<\]ԁ|_W HHҡb}P>k {ZErxMX@8C&qskLۙOnO^sCk7ql2XCw5VG.S~H8=(s1~cV5z %v|U2QF=NoW]ո?<`~׮}=ӬfԵ,=;"~Iy7K#g{ñJ?5$y` zz@-~m7mG宝Gٱ>G&K#]؃y1$$t>wqjstX.b̐{Wej)Dxfc:8)=$y|L`xV8ߙ~E)HkwW$J0uʟk>6Sgp~;4֌W+חc"=|ř9bc5> *rg {~cj1rnI#G|8v4wĿhFb><^ pJLm[Dl1;Vx5IZ:1*p)إ1ZbAK(1ׅ|S&5{^ KG^5r>;X׻K^? s fk^8O/"J)3K]N)iL?5!ƾq:G_=X- i,vi2N3 |03Qas ! 7}kZU781M,->e;@Qz T(GK(ah(((((((Y[×j2F}o־oYYq $+]%$ v^rϭ`nax,ZEuWSܽ,g%~"MrsrY~Ҿ"Fت;8{ѰxYEfP^;WPwqbB:c?zp<7;SBfZ)dϛ; 7s^>}⍱x?Bix^#hf,*P9S{w[]GF?1Z_nG~]kk)9Sc5Ո<<6J-ϛ}xUi>ux#ţc'{ᛲq?Oo?x&mѱ'#^t)ϲbb0 F«kIVmVsv@}kҡ!ˍUTtxO̧]ORb|2yԵk܊{sPIc_?ħ:Ig)=Z~' "\M2VSSMyLsl⺿U~"C7\hz_ Rs$~? TAi<lO*>U}+'f>7_K N s8g1^CeКÿE ;{+Y\ O5|Y{/o+ LVcO;7Zx-Ek&dpzbӱ+TaB0gNy׭ 3^c T\$⫫?F33?t._Q~Nln:U/Ceb1-im WʸQM+VpafR3d׫é|Aү-q*I P7:y&]hX^Fbtpܩ?|Wu󭏤ʫxJ3ߴm"(uqA}j.+?S wV ~ [B&<^U?rϜ_OH\'.;|.%pw/ZZG'1j(#0UT` Wzw}>_*9m>󑓀F?EL3"zpubzΕ$+0܉&3zڶ+jyr1QE ( ( ( ( ( ( ( (UIdC0EZm+]Y6^![ ԯsmܶ捆?+me+ZE29)B[;я*wGxsK7;5w)}gH~.Ɣx?X\ߚ}A@tQ(:ͧ|Iq(CT?v[sKG+*רqҍck <#Ljα5݈`8cXP6T5i.K!xX*p&ќZǓϘ7 *oƽ:wlຈ:Q5yIEA/2*2jAҐe}k%K$N9R2?7ýKMV!{W9\PA+c4w` Wx=Ze\X{}yXI Ү!aOÎ{]Qx)#D@9E:*NJ}b|Z>_k7:d$z >&Vv󃏽WlR:RqJfGإd9Tm(ҝEtO}1O[xxEYt8,3v bFF )ǙrPNE8=O#V*Cc𹾾&l&cmCh<.P{ʦ&ۣY+Gxs~k5$> ӥPquŽўZt~Tl>Q.g> %k#ú:Kn'&{[yWQGqF}AЅ׮/}<;VYZa$wQg!$;_ $NKS}“_{MY|w7G!"\JtRy+贾d|o/;5jz_6fHwk<ѰJ#]kAȎ J =YNu%dxRwwbEQEQEQEQEQEQEQEQEQE'fLQZ(1F)hQ@X1KEQE-Q@ 1KE3h=iPb(((1GjZ(-ʹRPbR@ 1KE7`bڒyS0(-&)P+ ڎԴP11F)h&:LRmQ@Q@Š(((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((_ğ<+F; sU%ԑ >,BH(uSU xþ1Wϲs${wgoQn_swB/'L\ܓFgԏZ ^dj^L^NmH Ҁ6(?nƓjh%ةlΣ /F6}pj2E3HgHЌ(UQR8oX,G8OB]>o9@$xWy'ڹOM=ҼWb"٠9-*r⬻zWokeh͝(F@n~X=q+⟇1b>ƑeIX.~C,o5የ-m;D Nʬ` `+CcE??Ki!R!cxw[ jvc}&Eٱ7T)8&þ/?os$wSn^bo:-4^js4JKm!#rv89>' O59t , \8r,Vk|IgxEv((RmĜ+bkz6,u/}-|.'<VÚ~tk,^cH61¢ !;M;Ėz[#CuAƶ+j_&*/;Q8d ǹHyAsM↷7l-6rò,%Fs;A*',}'f[]tݷs~UWhk?:4JE]WpcY=" ƚw/|_xSw(kycH#r28,X7D5Kh76 mɍ~0H;6194WpGӧգ%8Z&GdPƧo6kcO5Kv`{}fyq \`@?Kv=26OޝyAe Qɼ芍H8͟2敮j#;iѻm؏6+wTx;KYY\-%'Aӣ?|=\-ٴk+٬$ɷWo,y~^6n8LP}gYywx4r@c ~5)ak="M$L0\iv D)$A A'z {cKv6ʲ8{0 Azv/'q[|^py8^uF˦-O!$X1$ $$׸PY&xGVn>c>.]SG EhWCI@Ep5+}8<3&O+U#0Xv;V/^k~-<=6RYG\2#Dd(+|ykM.On--jO>?H@2pX9FӾLjc<={&pmjJd ؐ:(+cgDuٮżO4 b,Z9A5ː7jj^)m+ͷZ|R5%11WoQ?θ~ K+[|/r3?>'Dm-Ƕkm1q /+|HQѼRzO.k* !A71C[ћŶzCqamH`yVA9qPTfG~#5FypEe U=: >_X<+{#:8Il(((((((((((((ro%޿ѿnŠ('cig6~o-aeM}ŵ"!'s@a tx;FemyZ/ڴn6hIH %0(1rǖ:ܞ|YK4sڬ9رwOX&[L,oN39]=V u7GmF 硭 { xRGF[-r$r ۩3ܼݯ iz ռ"nE6d WG]Do#/VcrQN wŠ(;gkx˵uˈ&ݒ/ S/Ñ<#ki.gxIGbRB{((?Z&}z7kz/̄*pNNHae%է]fK{b70à# L<^,?3?0]\0Fج78ǦCDћVzn8Coa)nV8axf.8qoTc#VO|Оw3ӧ4Oϯv߹_n%NgI"FYNw9  P[OԿ#O{~. 2D%I8u"/7 ḭ_ܝUͼ2Gol6WQ@OY> 7Gnn!9z܌ fj:G<3#U>OAĒ)Ki5Uw(@3wQ@w@^j*[FR{V{F'6PU~` Vu>蚏>i:No{<2-wL9RAŠ{_j^ - MiY. p'R49<sUW<iwkLn7tpbQ.\(_&m6}O -!q"_XW}wO7ǙZ,o;8,.໵;&A"6  88 ¬P/k?غ΋AtȖ nn! $ʀ $^_2ns#vKy"_F褑`W䳿LoxĈ  B^Ӽ)} Uh2$J噘w3%hXxw7k$\m'ϴ N\WqE !c»g|m[ǻtwcv:`ph2{PM#L ىqqR.HsɌp$.շ4K;VU 23F}Icco,vÞ&Ȏ0ʵ\,k"pe(P(KqKòx3:]V͜~c ?_>]ZzImy2n%F Ҹ./ _+I}e8b| sO@Ə9ktZ(ȬYT& j|7м]7Öe5e'{A,x,B%bigRO i]<yR[$ P/Q5"мGN'^9DY2I@8Qy}Njt_LXS(c:'+i+th;xjx<'ޣcsڗɷ˳Be?;p0 <;דc&o8>)g[~1x. 3tOC^^WMY56IN2} H3wjrDs(;xn i^'WLI2fXl#aW/WӼ1+ojze~*O]bg{U+z-N@φz>(iQpBLsАG4jWxnM W)Il!/?{qXMQ|)gZ<&JHATq\?-/TI_v_,}>P2_dž8RN^gfԬ5BSZK#摾`Nf3^5VֵkXm剼%YQ7*O9e[**X̷h4mpwN3_zIJjڭWDۣYnb(PynsF(|cjOCg\E,_*`BHf3p1$xA/"n¿?}f˿g[7c6~8̷FH ɍ)oKx~]0i7w͌ĎBp87IῈ>v%s=iD.@Ufp>fxF@8>'#Iyx𪼼gȒ@KoZxz.rF/~S2$n5::xbM")uhftIlH78=8/g&㿈wRaEI$b-@ g^=y|zkPFukDžtIFSS$oC`8\6P/R(ƭg9vjF}w $`l w-h4o _xhϦFw-xNel0ap7?K O=7M'aGYbIw$``m>b  8潺X(iXͅ ;n<t0{-KJm*jD`d6Lw5Z|3>XkftvtBmeC$j/SўP<iVԦ6IncZ/T ^7Ϋxppx$:Dt/SўP<iVԦ6IncZ8|hVWw骼>CJc#T6!J#?j0iz!y]Z8ՊR[@ƕ|Koòxr3ݥW-ޠ~#*gīcNy$(bI'5|9I$ҵ85mCQtxc,xeqan+bMY.ݣYli A8'_α:?+ V#dO@3F89SVZ;Onɫh"vaQ=G`9O06QIz]:yMcLEW H1x>iɡ놹o!-q{#HPKL /xsLZmv F4P3n{u*~uxB tDKzy*FCd M{x}m_4?+?d]m|awD<#iڍׁ#HahD}p ggGio~s[6ީ=+<6 "n5p@$PIFFzja5-Kbar FV(#ܧp:V-8,iM8VeQ |d2G~!?,$diP\Y~Ӎ] \K1ZRs H˶!6f(EދܼQ߷E0`̇i9囡Mhk;Ҽjޫw.oky̡_~'y`Eye/wL#$4BPŴp޽nO  xY/|?SzݴBmQ:KENԐx+ޣC?'oMڼg8U<9pxnO?C|ObKMZmlE.nđzQ@Q@Q@Q@Q@Q@Q@Q@Q@Q@Q@$VN? h~&ŵ]_W;1#n k^# 妨WL>Dn²F2ێg%;+tح%Rɶ#}@eۘH8%?iƵ%IJv s=?+O"G@E5-fcerwN#x9MzGmn4k ki$bH0dMjQ\-oQÍ[Vn>}˱_nO <9_xG>&OL͍'\vs(zcwsoWNH$"GWGtw\ IۜwuWˏ^=y-m JE-O Z}O:n&wrdS@ ps(}cZjpCɳ˝IK%9s'&k} y#1mdPH#8Q@%}QcZ @$b9V܅6#;g9g4Er^=[{W߂~Up `)'nqP\O~!>v!͈"`rG\!/g,a/A}mC$Bt רPEe[ÞԵv(GF$`>Tzl(G%gZ>K.EynnږTnX3 U*4Q^oC֟P\]yQC_~9ۜgz>)ɠx\CyvlFU,rAf="+񶿭Exgh5E%R@zrT**H iEr<]2m rH7X%۷a! 㩮 +C{?4Իҍ54k_JIqy$dx'_|?կ 4Io+. F˝z3@E7o4GC.d4+,e~%s̝@e<N95PEPEPEPEPEPEPEPEPEPNu?áطKq4ܟi 8${Y6ϯ޵\[WV( ۂGIF7bio&d߷nvsօy{OlGKgs$hʊ8ghl>f}&xsGImc.-w1cO$Ma <Q=cE{@*$EcN8P¯C5_^/dz} ۙ%,IPyk+'oikkQ2 ι5k= ˺&9AS8 u f}cww#"g$?cvG|wy`\VS OZrOmlZ$X2b v /} \욄+RG :p: Oow:m ;Mk$t4Zđ$j6 7FrpoXM;z#yRxCR χjp).#0FY0]n;Ez Z }.$d.rz`c_ ]>@v##8@l}ό?ۿ>|gns89a97_5%FKyA8\:cvײZhu//+rcyk8'3޹gguE|xdK03NX}hy s W҆uws֤qpS:&@8 qm{ev 8ӣ{d09EfLX'돟P?|/4Hi] '-͒rs_IuO4H-3#>s8$ xrxڎ?WܷwXF_: llێmE]ƭeecc,ֺq2mH_+rۜW7RRc{+d'5M:X%* GZ aT|?]xF 3SoYIqY4*āq++ҾxE-+ 4};,[FGPq]y?k+AMOQм˫^isĖ8OJ<7m:t-d漙r'.Io<\$גDQK23;kxn⸷9$l]H #w6sayku2n#r0!G# gw~ _CRXab} miL$?/ʟw^^ K ;q+|oZex<f(0` Hc]]vs]mylN:WafmgywVп;]H*p_]uj67a cqڀ8Huw҈+7z}}dj7mPphxc>wڿ4g$ݷ;~cst [;?wp\yy2_22"_?|-[ڽV{muyf<>k1!r;bR_?^ۏ9@g%|#Ee$׏B>jSڶ<7^Ov1;XJGn秨^[F<.48E Rp;ڽ5&#:[iՌwvbTYH*z8$t&8;-4 a-$!I!]KmAۜdgM;b߽qzI?wk32%mplgkxjkIF{&6Dd*RG`y |>war#s«j!JͮciD`@!qʧh,y!ORpho)|C- 2rH"D rFy@o0^Gu^\I{ axPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPPKgthohPKO_\EOEBPS/dcommon/cpyr.htmD Oracle Legal Notices

Oracle Legal Notices

Copyright Notice

Copyright © 1994-2014, Oracle and/or its affiliates. All rights reserved.

Trademark Notice

Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.

Intel and Intel Xeon are trademarks or registered trademarks of Intel Corporation. All SPARC trademarks are used under license and are trademarks or registered trademarks of SPARC International, Inc. AMD, Opteron, the AMD logo, and the AMD Opteron logo are trademarks or registered trademarks of Advanced Micro Devices. UNIX is a registered trademark of The Open Group.

License Restrictions Warranty/Consequential Damages Disclaimer

This software and related documentation are provided under a license agreement containing restrictions on use and disclosure and are protected by intellectual property laws. Except as expressly permitted in your license agreement or allowed by law, you may not use, copy, reproduce, translate, broadcast, modify, license, transmit, distribute, exhibit, perform, publish, or display any part, in any form, or by any means. Reverse engineering, disassembly, or decompilation of this software, unless required by law for interoperability, is prohibited.

Warranty Disclaimer

The information contained herein is subject to change without notice and is not warranted to be error-free. If you find any errors, please report them to us in writing.

Restricted Rights Notice

If this is software or related documentation that is delivered to the U.S. Government or anyone licensing it on behalf of the U.S. Government, the following notice is applicable:

U.S. GOVERNMENT END USERS: Oracle programs, including any operating system, integrated software, any programs installed on the hardware, and/or documentation, delivered to U.S. Government end users are "commercial computer software" pursuant to the applicable Federal Acquisition Regulation and agency-specific supplemental regulations. As such, use, duplication, disclosure, modification, and adaptation of the programs, including any operating system, integrated software, any programs installed on the hardware, and/or documentation, shall be subject to license terms and license restrictions applicable to the programs. No other rights are granted to the U.S. Government.

Hazardous Applications Notice

This software or hardware is developed for general use in a variety of information management applications. It is not developed or intended for use in any inherently dangerous applications, including applications that may create a risk of personal injury. If you use this software or hardware in dangerous applications, then you shall be responsible to take all appropriate fail-safe, backup, redundancy, and other measures to ensure its safe use. Oracle Corporation and its affiliates disclaim any liability for any damages caused by use of this software or hardware in dangerous applications.

Third-Party Content, Products, and Services Disclaimer

This software or hardware and documentation may provide access to or information on content, products, and services from third parties. Oracle Corporation and its affiliates are not responsible for and expressly disclaim all warranties of any kind with respect to third-party content, products, and services. Oracle Corporation and its affiliates will not be responsible for any loss, costs, or damages incurred due to your access to or use of third-party content, products, or services.

Alpha and Beta Draft Documentation Notice

If this document is in preproduction status:

This documentation is in preproduction status and is intended for demonstration and preliminary use only. It may not be specific to the hardware on which you are using the software. Oracle Corporation and its affiliates are not responsible for and expressly disclaim all warranties of any kind with respect to this documentation and will not be responsible for any loss, costs, or damages incurred due to the use of this documentation.

Oracle Logo

PK0hPKO_\EOEBPS/dcommon/blafdoc.cssc@charset "utf-8"; /* Copyright 2002, 2011, Oracle and/or its affiliates. All rights reserved. Author: Robert Crews Version: 2011.8.12 */ body { font-family: Tahoma, sans-serif; /* line-height: 125%; */ color: black; background-color: white; font-size: small; } * html body { /* http://www.info.com.ph/~etan/w3pantheon/style/modifiedsbmh.html */ font-size: x-small; /* for IE5.x/win */ f\ont-size: small; /* for other IE versions */ } h1 { font-size: 165%; font-weight: bold; border-bottom: 1px solid #ddd; width: 100%; text-align: left; } h2 { font-size: 152%; font-weight: bold; text-align: left; } h3 { font-size: 139%; font-weight: bold; text-align: left; } h4 { font-size: 126%; font-weight: bold; text-align: left; } h5 { font-size: 113%; font-weight: bold; display: inline; text-align: left; } h6 { font-size: 100%; font-weight: bold; font-style: italic; display: inline; text-align: left; } a:link { color: #039; background: inherit; } a:visited { color: #72007C; background: inherit; } a:hover { text-decoration: underline; } a img, img[usemap] { border-style: none; } code, pre, samp, tt { font-family: monospace; font-size: 110%; } caption { text-align: center; font-weight: bold; width: auto; } dt { font-weight: bold; } table { font-size: small; /* for ICEBrowser */ } td { vertical-align: top; } th { font-weight: bold; text-align: left; vertical-align: bottom; } li { text-align: left; } dd { text-align: left; } ol ol { list-style-type: lower-alpha; } ol ol ol { list-style-type: lower-roman; } td p:first-child, td pre:first-child { margin-top: 0px; margin-bottom: 0px; } table.table-border { border-collapse: collapse; border-top: 1px solid #ccc; border-left: 1px solid #ccc; } table.table-border th { padding: 0.5ex 0.25em; color: black; background-color: #f7f7ea; border-right: 1px solid #ccc; border-bottom: 1px solid #ccc; } table.table-border td { padding: 0.5ex 0.25em; border-right: 1px solid #ccc; border-bottom: 1px solid #ccc; } span.gui-object, span.gui-object-action { font-weight: bold; } span.gui-object-title { } p.horizontal-rule { width: 100%; border: solid #cc9; border-width: 0px 0px 1px 0px; margin-bottom: 4ex; } div.zz-skip-header { display: none; } td.zz-nav-header-cell { text-align: left; font-size: 95%; width: 99%; color: black; background: inherit; font-weight: normal; vertical-align: top; margin-top: 0ex; padding-top: 0ex; } a.zz-nav-header-link { font-size: 95%; } td.zz-nav-button-cell { white-space: nowrap; text-align: center; width: 1%; vertical-align: top; padding-left: 4px; padding-right: 4px; margin-top: 0ex; padding-top: 0ex; } a.zz-nav-button-link { font-size: 90%; } div.zz-nav-footer-menu { width: 100%; text-align: center; margin-top: 2ex; margin-bottom: 4ex; } p.zz-legal-notice, a.zz-legal-notice-link { font-size: 85%; /* display: none; */ /* Uncomment to hide legal notice */ } /*************************************/ /* Begin DARB Formats */ /*************************************/ .bold, .codeinlinebold, .syntaxinlinebold, .term, .glossterm, .seghead, .glossaryterm, .keyword, .msg, .msgexplankw, .msgactionkw, .notep1, .xreftitlebold { font-weight: bold; } .italic, .codeinlineitalic, .syntaxinlineitalic, .variable, .xreftitleitalic { font-style: italic; } .bolditalic, .codeinlineboldital, .syntaxinlineboldital, .titleinfigure, .titleinexample, .titleintable, .titleinequation, .xreftitleboldital { font-weight: bold; font-style: italic; } .itemizedlisttitle, .orderedlisttitle, .segmentedlisttitle, .variablelisttitle { font-weight: bold; } .bridgehead, .titleinrefsubsect3 { font-weight: bold; } .titleinrefsubsect { font-size: 126%; font-weight: bold; } .titleinrefsubsect2 { font-size: 113%; font-weight: bold; } .subhead1 { display: block; font-size: 139%; font-weight: bold; } .subhead2 { display: block; font-weight: bold; } .subhead3 { font-weight: bold; } .underline { text-decoration: underline; } .superscript { vertical-align: super; } .subscript { vertical-align: sub; } .listofeft { border: none; } .betadraft, .alphabetanotice, .revenuerecognitionnotice { color: #f00; background: inherit; } .betadraftsubtitle { text-align: center; font-weight: bold; color: #f00; background: inherit; } .comment { color: #080; background: inherit; font-weight: bold; } .copyrightlogo { text-align: center; font-size: 85%; } .tocsubheader { list-style-type: none; } table.icons td { padding-left: 6px; padding-right: 6px; } .l1ix dd, dd dl.l2ix, dd dl.l3ix { margin-top: 0ex; margin-bottom: 0ex; } div.infoboxnote, div.infoboxnotewarn, div.infoboxnotealso { margin-top: 4ex; margin-right: 10%; margin-left: 10%; margin-bottom: 4ex; padding: 0.25em; border-top: 1pt solid gray; border-bottom: 1pt solid gray; } p.notep1 { margin-top: 0px; margin-bottom: 0px; } .tahiti-highlight-example { background: #ff9; text-decoration: inherit; } .tahiti-highlight-search { background: #9cf; text-decoration: inherit; } .tahiti-sidebar-heading { font-size: 110%; margin-bottom: 0px; padding-bottom: 0px; } /*************************************/ /* End DARB Formats */ /*************************************/ @media all { /* * * { line-height: 120%; } */ dd { margin-bottom: 2ex; } dl:first-child { margin-top: 2ex; } } @media print { body { font-size: 11pt; padding: 0px !important; } a:link, a:visited { color: black; background: inherit; } code, pre, samp, tt { font-size: 10pt; } #nav, #search_this_book, #comment_form, #comment_announcement, #flipNav, .noprint { display: none !important; } body#left-nav-present { overflow: visible !important; } } PKr.hcPKO_\EOEBPS/dcommon/doccd_epub.jsM /* Copyright 2006, 2012, Oracle and/or its affiliates. All rights reserved. Author: Robert Crews Version: 2012.3.17 */ function addLoadEvent(func) { var oldOnload = window.onload; if (typeof(window.onload) != "function") window.onload = func; else window.onload = function() { oldOnload(); func(); } } function compactLists() { var lists = []; var ul = document.getElementsByTagName("ul"); for (var i = 0; i < ul.length; i++) lists.push(ul[i]); var ol = document.getElementsByTagName("ol"); for (var i = 0; i < ol.length; i++) lists.push(ol[i]); for (var i = 0; i < lists.length; i++) { var collapsible = true, c = []; var li = lists[i].getElementsByTagName("li"); for (var j = 0; j < li.length; j++) { var p = li[j].getElementsByTagName("p"); if (p.length > 1) collapsible = false; for (var k = 0; k < p.length; k++) { if ( getTextContent(p[k]).split(" ").length > 12 ) collapsible = false; c.push(p[k]); } } if (collapsible) { for (var j = 0; j < c.length; j++) { c[j].style.margin = "0"; } } } function getTextContent(e) { if (e.textContent) return e.textContent; if (e.innerText) return e.innerText; } } addLoadEvent(compactLists); function processIndex() { try { if (!/\/index.htm(?:|#.*)$/.test(window.location.href)) return false; } catch(e) {} var shortcut = []; lastPrefix = ""; var dd = document.getElementsByTagName("dd"); for (var i = 0; i < dd.length; i++) { if (dd[i].className != 'l1ix') continue; var prefix = getTextContent(dd[i]).substring(0, 2).toUpperCase(); if (!prefix.match(/^([A-Z0-9]{2})/)) continue; if (prefix == lastPrefix) continue; dd[i].id = prefix; var s = document.createElement("a"); s.href = "#" + prefix; s.appendChild(document.createTextNode(prefix)); shortcut.push(s); lastPrefix = prefix; } var h2 = document.getElementsByTagName("h2"); for (var i = 0; i < h2.length; i++) { var nav = document.createElement("div"); nav.style.position = "relative"; nav.style.top = "-1.5ex"; nav.style.left = "1.5em"; nav.style.width = "90%"; while (shortcut[0] && shortcut[0].toString().charAt(shortcut[0].toString().length - 2) == getTextContent(h2[i])) { nav.appendChild(shortcut.shift()); nav.appendChild(document.createTextNode("\u00A0 ")); } h2[i].parentNode.insertBefore(nav, h2[i].nextSibling); } function getTextContent(e) { if (e.textContent) return e.textContent; if (e.innerText) return e.innerText; } } addLoadEvent(processIndex); PKo"nR M PKO_\EOEBPS/funcusr.htmRK User-Defined Functions

13 User-Defined Functions

This chapter describes how you can write user-defined functions for use in Oracle Continuous Query Language (Oracle CQL) to perform more advanced or application-specific operations on stream data than is possible using built-in functions.

For more information, see Section 1.1.11, "Functions".

13.1 Introduction to Oracle CQL User-Defined Functions

You can write user-defined functions in Java to provide functionality that is not available in Oracle CQL or Oracle CQL built-in functions. You can create a user-defined function that returns an aggregate value or a single (non-aggregate) value.

For example, you can use user-defined functions in the following:

  • The select list of a SELECT statement

  • The condition of a WHERE clause

To make your user-defined function available for use in Oracle CQL queries, the JAR file that contains the user-defined function implementation class must be in the Oracle CEP server classpath or the Oracle CEP server classpath must be modified to include the JAR file.

For more information, see:

13.1.1 Types of User-Defined Functions

Using the classes in the oracle.cep.extensibility.functions package you can create the following types of user-defined functions:

You can create overloaded functions and you can override built-in functions.

13.1.1.1 User-Defined Single-Row Functions

A user-defined single-row function is a function that returns a single result row for every row of a queried stream or view (for example, like the concat built-in function does).

For more information, see "How to Implement a User-Defined Single-Row Function".

13.1.1.2 User-Defined Aggregate Functions

A user-defined aggregate is a function that implements com.bea.wlevs.processor.AggregationFunctionFactory and returns a single aggregate result based on group of tuples, rather than on a single tuple (for example, like the sum built-in function does).

Consider implementing your aggregate function so that it performs incremental processing, if possible. This will improve scalability and performance because the cost of (re)computation on arrival of new events will be proportional to the number of new events as opposed to the total number of events seen thus far.

For more information, see "How to Implement a User-Defined Aggregate Function".

13.1.2 User-Defined Function Datatypes

Table 13-1 lists the datatypes you can specify when you implement and register a user-defined function.

Table 13-1 User-Defined Function Datatypes

Oracle CQL DatatypeEquivalent Java Datatype

bigint

java.lang.Long

char

java.lang.String

double

java.lang.Double

float

java.lang.Float

int

java.lang.Integer

Object

java.lang.Object


The Oracle CQL Datatype column lists the datatypes you can specify in the Oracle CQL statement you use to register your user-defined function and the Equivalent Java Datatype column lists the Java datatype equivalents you can use in your user-defined function implementation.

At run time, Oracle CEP maps between the Oracle CQL datatype and the Java datatype. If your user-defined function returns a datatype that is not in this list, Oracle CEP will throw a ClassCastException.

For more information about data conversion, see Section 2.2.4, "Datatype Conversion".

13.1.3 User-Defined Functions and the Oracle CEP Server Cache

You can access an Oracle CEP cache from an Oracle CQL statement or user-defined function.

For more information, see:

13.2 Implementing a User-Defined Function

This section describes:

For more information, see Section 13.1, "Introduction to Oracle CQL User-Defined Functions".

13.2.1 How to Implement a User-Defined Single-Row Function

You implement a user-defined single-row function by implementing a Java class that provides a public constructor and a public method that is invoked to execute the function.

To implement a user-defined single-row function:

  1. Implement a Java class as Example 13-1 shows.

    Ensure that the data type of the return value corresponds to a supported data type as Section 13.1.2, "User-Defined Function Datatypes" describes.

    For more information on accessing the Oracle CEP cache from a user-defined function, see Section 13.1.3, "User-Defined Functions and the Oracle CEP Server Cache".

    Example 13-1 MyMod.java User-Defined Single-Row Function

    package com.bea.wlevs.example.function;
    
    public class MyMod {
        public Object execute(int arg0, int arg1) {
            return new Integer(arg0 % arg1);
        }
    }
    
  2. Compile the user-defined function Java implementation class and register the class in your Oracle CEP application assembly file as Example 13-2 shows.

    Example 13-2 Single-Row User Defined Function for an Oracle CQL Processor

    <wlevs:processor id="testProcessor">
        <wlevs:listener ref="providerCache"/>
        <wlevs:listener ref="outputCache"/>
        <wlevs:cache-source ref="testCache"/>
        <wlevs:function function-name="mymod" exec-method=”execute” />
            <bean class="com.bea.wlevs.example.function.MyMod"/>
        </wlevs:function>
    </wlevs:processor>
    

    Specify the method that is invoked to execute the function using the wlevs:function element exec-method attribute. This method must be public and must be uniquely identifiable by its name (that is, the method cannot have been overridden).

    For more information, see "wlevs:function" in the Oracle Fusion Middleware Developer's Guide for Oracle Complex Event Processing for Eclipse.

  3. Invoke your user-defined function in the select list of a SELECT statement or the condition of a WHERE clause as Example 13-3 shows.

    Example 13-3 Accessing a User-Defined Single-Row Function in Oracle CQL

    ...
    <view id="v1" schema="c1 c2 c3 c4"><![CDATA[ 
        select
            mymod(c1, 100), c2, c3, c4 
        from 
            S1
    ]]></view>
    ...
    <query id="q1"><![CDATA[ 
        select * from v1 [partition by c1 rows 1] where c4 - c3 = 2.3 
    ]]></query>
    ...
    

13.2.2 How to Implement a User-Defined Aggregate Function

You implement a user-defined aggregate function by implementing a Java class that implements the com.bea.wlevs.processor.AggregationFunctionFactory interface.

To implement a user-defined aggregate function:

  1. Implement a Java class as Example 13-4 shows.

    Consider implementing your aggregate function so that it performs incremental processing, if possible. This will improve scalability and performance because the cost of (re)computation on arrival of new events will be proportional to the number of new events as opposed to the total number of events seen thus far. The user-defined aggregate function in Example 13-4 supports incremental processing.

    Ensure that the data type of the return value corresponds to a supported data type as Section 13.1.2, "User-Defined Function Datatypes" describes.

    For more information on accessing the Oracle CEP cache from a user-defined function, see Section 13.1.3, "User-Defined Functions and the Oracle CEP Server Cache".

    Example 13-4 Variance.java User-Defined Aggregate Function

    package com.bea.wlevs.test.functions;
     
    import com.bea.wlevs.processor.AggregationFunction;
    import com.bea.wlevs.processor.AggregationFunctionFactory;
     
    public class Variance implements AggregationFunctionFactory, AggregationFunction {
     
        private int count;
        private float sum;
        private float sumSquare;
     
        public Class<?>[] getArgumentTypes() {
            return new Class<?>[] {Integer.class};
        }
     
        public Class<?> getReturnType() {
            return Float.class;
        }
     
        public AggregationFunction newAggregationFunction() {
            return new Variance();
        }
     
        public void releaseAggregationFunction(AggregationFunction function) {
        }
     
        public Object handleMinus(Object[] params) {
            if (params != null && params.length == 1) {
                Integer param = (Integer) params[0];
                count--;
                sum -= param;
                sumSquare -= (param * param);
            }
            
            if (count == 0) {
                return null;
            } else {
                return getVariance();
            }
        }
     
        public Object handlePlus(Object[] params) {
            if (params != null && params.length == 1) {
                Integer param = (Integer) params[0];
                count++;
                sum += param;
                sumSquare += (param * param);
            }
            
            if (count == 0) {
                return null;
            } else {
                return getVariance();
            }
        }
     
        public Float getVariance() {
            float avg = sum / (float) count;
            float avgSqr = avg * avg;
            float var = sumSquare / (float)count - avgSqr;
            return var;
        }
     
        public void initialize() {
            count = 0;
            sum = 0.0F;
            sumSquare = 0.0F;
        }
     
    }
    
  2. Compile the user-defined function Java implementation class and register the class in your Oracle CEP application assembly file as Example 13-5 shows.

    Example 13-5 Aggregate User Defined Function for an Oracle CQL Processor

      <wlevs:processor id="testProcessor">
         <wlevs:listener ref="providerCache"/>
         <wlevs:listener ref="outputCache"/>
         <wlevs:cache-source ref="testCache"/>
         <wlevs:function function-name="var">
           <bean class="com.bea.wlevs.test.functions.Variance"/>
         </wlevs:function>
       </wlevs:processor>
    

    For more information, see "wlevs:function" in the Oracle Fusion Middleware Developer's Guide for Oracle Complex Event Processing for Eclipse.

  3. Invoke your user-defined function in the select list of a SELECT statement or the condition of a WHERE clause as Example 13-6 shows.

    Example 13-6 Accessing a User-Defined Aggregate Function in Oracle CQL

    ...
    <query id="uda6"><![CDATA[ 
        select var(c2) from S4[range 3] 
    ]]></query>
    ...
    

    At run-time, when the user-defined aggregate is executed, and a new event becomes active in the window of interest, the aggregations will have to be recomputed (since the set over which the aggregations are defined has a new member). To do so, Oracle CEP passes only the new event (rather than the entire active set) to the appropriate handler context by invoking the appropriate handlePlus* method in Example 13-4. This state can now be updated to include the new event. Thus, the aggregations have been recomputed in an incremental fashion.

    Similarly, when an event expires from the window of interest, the aggregations will have to be recomputed (since the set over which the aggregations are defined has lost a member). To do so, Oracle CEP passes only the expired event (rather than the entire active set) to the appropriate handler context by invoking the appropriate handleMinus method in Example 13-4. As before, the state in the handler context can be incrementally updated to accommodate expiry of the event in an incremental fashion.

PK"=GRRPKO_\E OEBPS/toc.ncx& Oracle® Fusion Middleware CQL Language Reference for Oracle Complex Event Processing, 11g Release 1 (11.1.1.6.3) Cover Title and Copyright Information Contents List of Examples List of Figures List of Tables Preface Part I Understanding Oracle CQL 1 Introduction to Oracle CQL 2 Basic Elements of Oracle CQL 3 Pseudocolumns 4 Operators 5 Expressions 6 Conditions 7 Common Oracle CQL DDL Clauses Part II Functions 8 Built-In Single-Row Functions 9 Built-In Aggregate Functions 10 Colt Single-Row Functions 11 Colt Aggregate Functions 12 java.lang.Math Functions 13 User-Defined Functions Part III Data Cartridges 14 Introduction to Data Cartridges 15 Oracle Java Data Cartridge 16 Oracle Spatial 17 Oracle CEP JDBC Data Cartridge Part IV Using Oracle CQL 18 Oracle CQL Queries, Views, and Joins 19 Pattern Recognition With MATCH_RECOGNIZE 20 Oracle CQL Statements Index Copyright PKAaPKO_\EOEBPS/content.opf Oracle® Fusion Middleware CQL Language Reference for Oracle Complex Event Processing, 11g Release 1 (11.1.1.6.3) en-US E12048-10 Oracle Corporation Oracle Corporation Oracle® Fusion Middleware CQL Language Reference for Oracle Complex Event Processing, 11g Release 1 (11.1.1.6.3) 2012-08-03T11:31:31Z Describes the Oracle Continuous Query Language (CQL) used to query event streams in Oracle Complex Event Processing applications. Oracle CQL is an extension to and partial subset of the American National Standards Institute (ANSI) and the International Standards Organization (ISO) SQL:1999 standard. PKq|PKO_\EOEBPS/pseudocolumns.htm9m Pseudocolumns

3 Pseudocolumns

This chapter provides a reference for Oracle Continuous Query Language (Oracle CQL) pseudocolumns, which you can query for but which are not part of the data from which an event was created.

3.1 Introduction to Pseudocolumns

You can select from pseudocolumns, but you cannot modify their values. A pseudocolumn is also similar to a function without arguments (see Section 1.1.11, "Functions").

Oracle CQL supports the following pseudocolumns:

3.2 ELEMENT_TIME Pseudocolumn

Every stream element of a base stream or derived stream (a view that evaluates to a stream) has an associated element time.The ELEMENT_TIME pseudo column returns this time as an Oracle CQL native type bigint.


Note:

ELEMENT_TIME is not supported on members of an Oracle CQL relation. For more information, see Section 1.1.1, "Streams and Relations".


This section describes:

For more information, see:

3.2.1 Understanding the Value of the ELEMENT_TIME Pseudocolumn

The value of the ELEMENT_TIME pseudocolumn depends on whether or not you configure the stream element's channel as system- or application-timestamped.

3.2.1.1 ELEMENT_TIME for a System-Timestamped Stream

In this case, the element time for a stream element is assigned by the Oracle CEP system in such a way that subtracting two values of system-assigned time will give a duration that roughly matches the elapsed wall clock time.

For more information, see "System-Timestamped Channels" in the Oracle Fusion Middleware Developer's Guide for Oracle Complex Event Processing 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:

For more information, see "Application-Timestamped Channels" in the Oracle Fusion Middleware Developer's Guide for Oracle Complex Event Processing 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:

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_timestamp(element_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
23000       230
25000       250

Example 3-3 Output Relation

Timestamp   Tuple Kind  Tuple
 8000       +           80,12/31/1969 17:00:08
 8010       -           80,12/31/1969 17:00:08
 9000       +           90,12/31/1969 17:00:09
 9010       -           90,12/31/1969 17:00:09
13000       +           130,12/31/1969 17:00:13
13010       -           130,12/31/1969 17:00:13
15000       +           150,12/31/1969 17:00:15
15010       -           150,12/31/1969 17:00:15
23000       +           230,12/31/1969 17:00:23
23010       -           230,12/31/1969 17:00:23
25000       +           250,12/31/1969 17:00:25
25010       -           250,12/31/1969 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,
            MAX(R.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 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.Bigint(Long).

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 
                count(Nth.*) = 3
                AND L.ELEMENT_TIME - F.ELEMENT_TIME < 10000000000L 
...
PKѰɗ99PKO_\EOEBPS/datacartunder.htm Introduction to Data Cartridges

14 Introduction to Data Cartridges

This chapter introduces data cartridges in Oracle Complex Event Processing (Oracle CEP). Data cartridges extend Oracle Continuous Query Language (Oracle CQL) to support domain-specific abstract data types of the following forms: simple types, complex types, array types, and domain-specific functions.

This chapter describes:

14.1 Understanding Data Cartridges

The Oracle CQL data cartridge framework allows you to tightly integrate arbitrary domain data types and functions with the Oracle CQL language, allowing the usage of these extensions within Oracle CQL queries in the same way you use Oracle CQL native types and built-in functions.

With regards to data types, the framework supports both simple and complex types, the latter allowing the usage of object-oriented programming.

Using Oracle CQL data cartridges, you can extend the Oracle CQL engine with domain-specific types that augment and interoperate with native Oracle CQL built-in types.

14.1.1 Data Cartridge Name

Each data cartridge is identified by a unique data cartridge name that defines a name space for the data cartridge implementation. You use the data cartridge name to disambiguate references to types, methods, fields, and constructors, if necessary (see link::=).

14.1.2 Data Cartridge Application Context

Depending on the data cartridge implementation, you may be able to define an application context that the Oracle CEP server propagates to the functions and types that an instance of the data cartridge provides.

For example, you might be able to configure an Oracle CEP server resource or a default data cartridge option and associate this application context information with a particular data cartridge instance.

For more information, see "Understanding Data Cartridge Application Context" in the Oracle Fusion Middleware Developer's Guide for Oracle Complex Event Processing for Eclipse.

14.2 Oracle CQL Data Cartridge Types

How you access data cartridge types, methods, fields, and constructors using Oracle CQL is the same for all data cartridge implementations.

You may reference a data-cartridge function by using the func_expr, which may optionally take a link name.

To reference the members of a complex type, Oracle CQL provides the object_expr production.

For more information, see:

What you access is, of course, unique to each data cartridge implementation. For more information, see:


Note:

To simplify Oracle data cartridge type names, you can use aliases as Section 2.7.2, "Defining Aliases Using the Aliases Element" describes.


PKs8PKO_\EOEBPS/conditions.htm Conditions

6 Conditions

This chapter provides a reference to conditions in Oracle Continuous Query Language (Oracle CQL). A condition specifies a combination of one or more expressions and logical operators and returns a value of TRUE, FALSE, or UNKNOWN.

6.1 Introduction to Conditions

You must use appropriate condition syntax whenever condition appears in Oracle CQL statements.

You can use a condition in the WHERE clause of these statements:

  • SELECT

You can use a condition in any of these clauses of the SELECT statement:

  • WHERE

  • HAVING


See Also:

"Query"


A condition could be said to be of a logical datatype.

The following simple condition always evaluates to TRUE:

1 = 1 

The following more complex condition adds the salary value to the commission_pct value (substituting the value 0 for null using the nvl function) and determines whether the sum is greater than the number constant 25000:

NVL(salary, 0) + NVL(salary + (salary*commission_pct, 0) > 25000)

Logical conditions can combine multiple conditions into a single condition. For example, you can use the AND condition to combine two conditions:

(1 = 1) AND (5 < 7) 

Here are some valid conditions:

name = 'SMITH' 
S0.department_id = S2.department_id 
hire_date > '01-JAN-88' 
commission_pct IS NULL AND salary = 2100

6.1.1 Condition Precedence

Precedence is the order in which Oracle CEP evaluates different conditions in the same expression. When evaluating an expression containing multiple conditions, Oracle CEP evaluates conditions with higher precedence before evaluating those with lower precedence. Oracle CEP evaluates conditions with equal precedence from left to right within an expression.

Table 6-1 lists the levels of precedence among Oracle CQL condition from high to low. Conditions listed on the same line have the same precedence. As the table indicates, Oracle evaluates operators before conditions.

Table 6-1 Oracle CQL Condition Precedence

Type of ConditionPurpose

Oracle CQL operators are evaluated before Oracle CQL conditions

See Section 4.1.2, "What You May Need to Know About Operator Precedence".

=, <>, <, >, <=, >=

comparison

IS NULL, IS NOT NULL, LIKE, BETWEEN, IN, NOT IN

comparison

NOT

exponentiation, logical negation

AND

conjunction

OR

disjunction

XOR

disjunction


6.2 Comparison Conditions

Comparison conditions compare one expression with another. The result of such a comparison can be TRUE, FALSE, or NULL.

When comparing numeric expressions, Oracle CEP uses numeric precedence to determine whether the condition compares INTEGER, FLOAT, or BIGINT values.

Two objects of nonscalar type are comparable if they are of the same named type and there is a one-to-one correspondence between their elements.

A comparison condition specifies a comparison with expressions or view results.

Table 6-2 lists comparison conditions.

Table 6-2 Comparison Conditions

Type of ConditionPurposeExample

=


Equality test.

<query id="Q1"><![CDATA[ 
    SELECT *
    FROM S0
    WHERE salary = 2500
]]></query>

<>

Inequality test.

<query id="Q1"><![CDATA[ 
    SELECT *
    FROM S0
    WHERE salary <> 2500
]]></query>

>

<

Greater-than and less-than tests.

<query id="Q1"><![CDATA[
    SELECT * FROM S0
    WHERE salary > 2500
]]></query>
<query id="Q1"><![CDATA[
    SELECT * FROM S0
    WHERE salary < 2500
]]></query>

>=

<=

Greater-than-or-equal-to and less-than-or-equal-to tests.

<query id="Q1"><![CDATA[
    SELECT * FROM S0
    WHERE salary >= 2500
]]></query>
<query id="Q1"><![CDATA[
    SELECT * FROM S0
    WHERE salary <= 2500
]]></query>

like

Pattern matching tests on character data.

For more information, see Section 6.4, "LIKE Condition".

<query id="q291"><![CDATA[
    select * from SLk1 
    where first1 like "^Ste(v|ph)en$"
]]></query>

is [not] null

Null tests.

For more information, see Section 6.6, "Null Conditions".

<query id="Q1"><![CDATA[
    SELECT last_name
  FROM S0
  WHERE commission_pct
  IS NULL
]]></query>
<query id="Q2"><![CDATA[
    SELECT last_name
  FROM S0
  WHERE commission_pct
  IS NOT NULL
]]></query>

[not] in

Set and membership tests.

For more information, see Section 6.8, "IN Condition".

<query id="Q1"><![CDATA[
  SELECT * FROM S0
  WHERE job_id NOT IN
  ('PU_CLERK','SH_CLERK')
]]></query>
<view id="V1" schema="salary"><![CDATA[ 
   SELECT salary 
   FROM S0
   WHERE department_id = 30
]]></view>
<view id="V2" schema="salary"><![CDATA[ 
   SELECT salary 
   FROM S0
   WHERE department_id = 20
]]></view>
<query id="Q2"><![CDATA[
  V1 IN V2
]]></query>

condition::=

Surrounding text describes condition.png.

(arith_expr::=, const_string::=, non_mt_arg_list::=, non_mt_arg_list_set::=, sfw_block::=)

6.3 Logical Conditions

A logical condition combines the results of two component conditions to produce a single result based on them or to invert the result of a single condition. Table 6-3 lists logical conditions.

Table 6-3 Logical Conditions

Type of ConditionOperationExamples
NOT 

Returns TRUE if the following condition is FALSE. Returns FALSE if it is TRUE. If it is UNKNOWN, then it remains UNKNOWN.

<query id="Q1"><![CDATA[ 
    SELECT *
    FROM S0
    WHERE NOT (job_id IS NULL)
]]></query>
AND 

Returns TRUE if both component conditions are TRUE. Returns FALSE if either is FALSE. Otherwise returns UNKNOWN.

<query id="Q1"><![CDATA[ 
    SELECT *
    FROM S0
    WHERE job_id = 'PU_CLERK'
    AND dept_id = 30
]]></query>
OR 

Returns TRUE if either component condition is TRUE. Returns FALSE if both are FALSE. Otherwise returns UNKNOWN.

<query id="Q1"><![CDATA[ 
    SELECT *
    FROM S0
    WHERE job_id = 'PU_CLERK'
    OR department_id = 10
]]></query>
XOR 

Returns TRUE if either component condition is TRUE. Returns FALSE if both are FALSE. Otherwise returns UNKNOWN.

<query id="Q1"><![CDATA[ 
    SELECT *
    FROM S0
    WHERE job_id = 'PU_CLERK'
    XOR department_id = 10
]]></query>

Table 6-4 shows the result of applying the NOT condition to an expression.

Table 6-4 NOT Truth Table

--TRUEFALSEUNKNOWN

NOT

FALSE

TRUE

UNKNOWN


Table 6-5 shows the results of combining the AND condition to two expressions.

Table 6-5 AND Truth Table

ANDTRUEFALSEUNKNOWN

TRUE

TRUE

FALSE

UNKNOWN

FALSE

FALSE

FALSE

FALSE

UNKNOWN

UNKNOWN

FALSE

UNKNOWN


For example, in the WHERE clause of the following SELECT statement, the AND logical condition returns values only when both product.levelx is BRAND and v1.prodkey equals product.prodkey:

<view id="v2" schema="region, dollars, month_"><![CDATA[ 
    select 
        v1.region, 
        v1.dollars, 
        v1.month_ 
    from 
        v1, 
        product 
    where 
        product.levelx = "BRAND" and v1.prodkey = product.prodkey
]]></view>

Table 6-6 shows the results of applying OR to two expressions.

Table 6-6 OR Truth Table

ORTRUEFALSEUNKNOWN

TRUE

TRUE

TRUE

TRUE

FALSE

TRUE

FALSE

UNKNOWN

UNKNOWN

TRUE

UNKNOWN

UNKNOWN


For example, the following query returns the internal account identifier for RBK or RBR accounts with a risk of type 2:

<view id="ValidAccounts" schema="ACCT_INTRL_ID"><![CDATA[ 
    select ACCT_INTRL_ID from Acct 
    where (
        ((MANTAS_ACCT_BUS_TYPE_CD = "RBK") OR (MANTAS_ACCT_BUS_TYPE_CD = "RBR")) AND 
        (ACCT_EFCTV_RISK_NB != 2)
    )
]]></view>

Table 6-7 shows the results of applying XOR to two expressions.

Table 6-7 XOR Truth Table

XORTRUEFALSEUNKNOWN

TRUE

FALSE

TRUE

UNKNOWN

FALSE

TRUE

FALSE

UNKNOWN

UNKNOWN

UNKNOWN

UNKNOWN

UNKNOWN


For example, the following query returns c1 and c2 when c1 is 15 and c2 is 0.14 or when c1 is 20 and c2 is 100.1, but not both:

<query id="q6"><![CDATA[ 
    select 
        S2.c1, 
        S3.c2 
    from 
        S2[range 1000], S3[range 1000] 
    where
        (S2.c1 = 15 and S3.c2 = 0.14) xor (S2.c1 = 20 and S3.c2 = 100.1)
]]></query>

6.4 LIKE Condition

The LIKE condition specifies a test involving regular expression pattern matching. Whereas the equality operator (=) exactly matches one character value to another, the LIKE conditions match a portion of one character value to another by searching the first value for the regular expression pattern specified by the second. LIKE calculates strings using characters as defined by the input character set.

like_condition::=

Surrounding text describes like_condition.png.

(arith_expr::=, const_string::=)

In this syntax:

  • arith_expr is an arithmetic expression whose value is compared to const_string.

  • const_string is a constant value regular expression to be compared against the arith_expr.

If any of arith_expr or const_string is null, then the result is unknown.

The const_string can contain any of the regular expression assertions and quantifiers that java.util.regex supports: that is, a regular expression that is specified in string form in a syntax similar to that used by Perl.

Table 6-8 describes the LIKE conditions.

Table 6-8 LIKE Conditions

Type of ConditionOperationExample
x LIKE y

TRUE if x does match the pattern y, FALSE otherwise.

<query id="q291"><![CDATA[ 
    select * from SLk1 where first1 like "^Ste(v|ph)en$"
]]></query>
<query id="q292"><![CDATA[ 
    select * from SLk1 where first1 like ".*intl.*"
]]></query>


See Also:

"lk"


For more information on Perl regular expressions, see http://perldoc.perl.org/perlre.html.

6.4.1 Examples

This condition is true for all last_name values beginning with Ma:

last_name LIKE '^Ma' 

All of these last_name values make the condition true:

Mallin, Markle, Marlow, Marvins, Marvis, Matos 

Case is significant, so last_name values beginning with MA, ma, and mA make the condition false.

Consider this condition:

last_name LIKE 'SMITH[A-Za-z]' 

This condition is true for these last_name values:

SMITHE, SMITHY, SMITHS 

This condition is false for SMITH because the [A-Z] must match exactly one character of the last_name value.

Consider this condition:

last_name LIKE 'SMITH[A-Z]+' 

This condition is false for SMITH but true for these last_name values because the [A-Z]+ must match 1 or more such characters at the end of the word.

SMITHSTONIAN, SMITHY, SMITHS 

For more information, see http://java.sun.com/j2se/1.5.0/docs/api/java/util/regex/Pattern.html.

6.5 Range Conditions

A range condition tests for inclusion in a range.

between_condition::=

Surrounding text describes between_condition.png.

(arith_expr::=)

Table 6-9 describes the range conditions.

Table 6-9 Range Conditions

Type of ConditionOperationExample
BETWEEN x AND y

Greater than or equal to x and less than or equal to y.

<query id="Q1"><![CDATA[ 
    SELECT * FROM S0
    WHERE salary
    BETWEEN 2000 AND 3000
]]></query>

6.6 Null Conditions

A NULL condition tests for nulls. This is the only condition that you should use to test for nulls.

null_conditions::=

Surrounding text describes null_conditions.png.

(Chapter 5, "Expressions")

Table 6-10 lists the null conditions.

Table 6-10 Null Conditions

Type of ConditionOperationExample
IS [NOT] NULL 

Tests for nulls.

See Also: Section 2.5, "Nulls"

<query id="Q1"><![CDATA[ 
    SELECT last_name
    FROM S0
    WHERE commission_pct
    IS NULL
]]></query>
<query id="Q2"><![CDATA[ 
    SELECT last_name
    FROM S0
    WHERE commission_pct
    IS NOT NULL
]]></query>

6.7 Compound Conditions

A compound condition specifies a combination of other conditions.

compound_conditions::=

Surrounding text describes compound_conditions.png.

See Also:

Section 6.3, "Logical Conditions" for more information about NOT, AND, and OR conditions


6.8 IN Condition

You can use the IN and NOT IN condition in the following ways:


Note:

You cannot combine these two usages.


When using the NOT IN condition, be aware of the effect of null values as Section 6.8.3, "NOT IN and Null Values" describes.

6.8.1 Using IN and NOT IN as a Set Operation

See "BINARY Example: IN and NOT IN".

6.8.2 Using IN and NOT IN as a Membership Condition

In this usage, the query will be a SELECT-FROM-WHERE query that either tests whether or not one argument is a member of a list of arguments of the same type or tests whether or not a list of arguments is a member of a set of similar lists.

in_condition_membership::=

Surrounding text describes in_condition_membership.png.

(arith_expr::=, non_mt_arg_list::=, non_mt_arg_list_set::=)

non_mt_arg_list_set::=

Surrounding text describes non_mt_arg_list_set.png.

(non_mt_arg_list::=)

When you use IN or NOT IN to test whether or not a non_mt_arg_list is a member of a set of similar lists, then you must use a non_mt_arg_list_set. Each non_mt_arg_list in the non_mt_arg_list_set must match the non_mt_arg_list to the left of the condition in number and type of arguments.


Note:

You cannot combine this usage with in_condition_set as Section 6.8.1, "Using IN and NOT IN as a Set Operation" describes.


Consider the query Q1 in Example 6-1 and the data stream S0 in Example 6-2. Stream S0 has schema (c1 integer, c2 integer). Example 6-3 shows the relation that the query returns. In Q1, the non_mt_arg_list_set is ((50,4),(4,5)). Note that each non_mt_arg_list that it contains matches the number and type of arguments in the non_mt_arg_list to the left of the condition, (c1, c2).

Example 6-1 S [range C on E] INTERVAL Value: Query

<query id="Q1"><![CDATA[ 
    select c1,c2 from S0[range 1] where (c1,c2) in ((50,4),(4,5)) 
]]></query>

Example 6-2 S [range C on E] INTERVAL Value: Stream Input

Timestamp   Tuple
1000        50, 4
2000        30, 6
3000          , 5
4000        22,
h 200000000

Example 6-3 S [range C on E] INTERVAL Value: Relation Output

Timestamp   Tuple Kind  Tuple
1000:       +           50,4
2000:       -           50,4

6.8.3 NOT IN and Null Values

If any item in the list following a NOT IN operation evaluates to null, then all stream elements evaluate to FALSE or UNKNOWN, and no rows are returned. For example, the following statement returns c1 and c2 if c1 is neither 50 nor 30:

<query id="check_notin1"><![CDATA[ 
    select c1,c2 from S0[range 1] 
    where 
        c1 not in (50, 30)
]]></query>

However, the following statement returns no stream elements:

<query id="check_notin1"><![CDATA[ 
    select c1,c2 from S0[range 1] 
    where 
        c1 not in (50, 30, NULL)
]]></query>

The preceding example returns no stream elements because the WHERE clause condition evaluates to:

c1 != 50 AND c1 != 30 AND c1 != null 

Because the third condition compares c1 with a null, it results in an UNKNOWN, so the entire expression results in FALSE (for stream elements with c1 equal to 50 or 30). This behavior can easily be overlooked, especially when the NOT IN operator references a view.

Moreover, if a NOT IN condition references a view that returns no stream elements at all, then all stream elements will be returned, as shown in the following example. Since V1 returns no stream elements at all, Q1 will return

<view id="V1" schema="c1"><![CDATA[ 
    IStream(select * from S1[range 10 slide 10] where 1=2) 
]]></view>
<view id="V2" schema="c1"><![CDATA[ 
    IStream(select * from S1[range 10 slide 10] where c1=2) 
]]></view>
<query id="Q1"><![CDATA[ 
    V1 not in V2
]]></query>
PK̫PKO_\E OEBPS/lot.htm List of Tables

List of Tables

PKtPKO_\EOEBPS/pattern_recog.htm Pattern Recognition With MATCH_RECOGNIZE

19 Pattern Recognition With MATCH_RECOGNIZE

This chapter provides reference and usage information about the MATCH_RECOGNIZE clause in Oracle Continuous Query Language (Oracle CQL). This clause and its sub-clauses perform pattern recognition in Oracle CQL queries.

19.1 Understanding Pattern Recognition With MATCH_RECOGNIZE

The MATCH_RECOGNIZE clause performs pattern recognition in an Oracle CQL query as Example 19-1 shows. This query will export (make available for inclusion in the SELECT) the MEASURES clause values for events (tuples) that satisfy the PATTERN clause regular expression over the DEFINE clause conditions.

Example 19-1 Pattern Matching With MATCH_RECOGNIZE

<query id="detectPerish"><![CDATA[ 
  select its.badItemId
  from tkrfid_ItemTempStream 
  MATCH_RECOGNIZE (
      PARTITION BY itemId
      MEASURES A.itemId as badItemId
      PATTERN (A B* C)
      DEFINE
          A  AS  (A.temp >= 25),
          B  AS  ((B.temp >= 25) and (to_timestamp(B.element_time) - to_timestamp(A.element_time) < INTERVAL "0 00:00:05.00" DAY TO SECOND)),
          C  AS  (to_timestamp(C.element_time) - to_timestamp(A.element_time) >= INTERVAL "0 00:00:05.00" DAY TO SECOND)
  ) as its
]]></query>

pattern_recognition_clause::=

Surrounding text describes pattern_recognition_clause.png.

(pattern_partition_clause::=, pattern_measures_clause::=, pattern_def_dur_clause::=)

pattern_def_dur_clause::=

Surrounding text describes pattern_def_dur_clause.png.

(pattern_clause::=, pattern_skip_match_clause::=, pattern_definition_clause::=, duration_clause::=, subset_clause::=)

Using MATCH_RECOGNIZE, you define conditions on the attributes of incoming events and identify these conditions by using identifiers called correlation variables. Example 19-1 defines correlation variables A, B, and C. A sequence of consecutive events in the input stream satisfying these conditions constitutes a pattern.

The output of a MATCH_RECOGNIZE query is always a stream.

The principle MATCH_RECOGNIZE sub-clauses are:

To refine pattern recognition, you may use the optional MATCH_RECOGNIZE sub-clauses, including:

For more information, see:

19.1.1 MATCH_RECOGNIZE and the WHERE Clause

In Oracle CQL (as in SQL), the FROM clause is evaluated before the WHERE clause.

Consider the following Oracle CQL query:

SELECT ... FROM S MATCH_RECOGNIZE ( .... ) as T WHERE ...

In this query, the S MATCH_RECOGNIZE ( .... ) as T is like a subquery in the FROM clause and is evaluated first, before the WHERE clause.

Consequently, you rarely use both a MATCH_RECOGNIZE clause and a WHERE clause in the same Oracle CQL query. Instead, you typically use a view to apply the required WHERE clause to a stream and then select from the view in a query that applies the MATCH_RECOGNIZE clause.

Example 19-2 shows two views, e1p1 and e2p2, each applying a WHERE clause to stream S to pre-filter the stream for the required events. The query q then selects from these two views and applies the MATCH_RECOGNIZE on this filtered stream of events.

Example 19-2 MATCH_RECOGNIZE and the WHERE Clause

<view id="e1p1">
    SELECT * FROM S WHERE eventName = 'E1' and path = 'P1' and statName = 'countValue'
</view>
<view id="e2p2">
    SELECT * FROM S WHERE eventName = 'E2' and path = 'P2' and statName = 'countValue'
</view>

<query id="q">
    SELECT 
        T.e1p1Stat as e1p1Stat, T.e2p2Stat as e2p2Stat
    FROM
        e1p1, e2p2
    MATCH_RECOGNIZE(
        ALL MATCHES
        PATTERN(A+)
        DURATION 60 MINUTES
        DEFINE
            A as (A.e1p1Stat < 1000 and A.e2p2Stat > 2000 and count(A) > 3)
        ) as T
</query>

For more information, see opt_where_clause::=

19.1.2 Referencing Singleton and Group Matches

The MATCH_RECOGNIZE clause identifies the following types of matches:

  • singleton: a correlation variable is a singleton if it occurs exactly once in a pattern, is not defined by a SUBSET, is not in the scope of an alternation, and is not quantified by a pattern quantifier.

    References to such a correlation variable refer to this single event.

  • group: a correlation variable is a group if it occurs in more than one pattern, is defined by a SUBSET, is in the scope of an alternation, or is quantified by a pattern quantifier.

    References to such a correlation variable refer to this group of events.

When you reference singleton and group correlation variables in the MEASURES and DEFINE clauses, observe the following rules:

  • For singleton correlation variables, you may reference individual event attributes only, not aggregates.

  • For group correlation variables:

    • If you reference an individual event attribute, then the value of the last event to match the correlation variable is returned.

      If the correlation variable is not yet matched, NULL is returned. In the case of count(A.*), if the correlation variable A is not yet matched, 0 is returned.

      If the correlation variable is being referenced in a definition of the same variable (such as DEFINE A as A.balance > 1000), then the value of the current event is returned.

    • If you reference an aggregate, then the aggregate is performed over all events that have matched the correlation variable so far.

For more information, see:

19.1.3 Referencing Aggregates

You can use any built-in, Colt, or user-defined aggregate function in the MEASURES and DEFINE clause of a MATCH_RECOGNIZE query.

When using aggregate functions, consider the following:

For more information, see:

19.1.3.1 Running Aggregates and Final Aggregates

In the DEFINE clause, any aggregate function on a correlation variable X is a running aggregate: that is, the aggregate includes all preceding matches of X up to and including the current match. If the correlation variable X has been completely matched so far, then the aggregate is final, otherwise it is running.

In the MEASURES clause, because it is evaluated after the match has been found, all aggregates are final because they are computed over the final match.

When using a SUBSET clause, be aware of the fact that you may inadvertently imply a running aggregate as Example 19-3 shows.

Example 19-3 Implied Running Aggregate

...
PATTERN (X+ Y+)
SUBSET Z = (X, Y)
DEFINE
    X AS X.price > 100,
    Y AS sum(Z.price) < 1000
...

Because correlation variable Z involves Y, the definition of Y involves a running aggregate on Y.

For more information, see:

19.1.3.2 Operating on the Same Correlation Variable

In both the MEASURES and DEFINE clause, you may only apply an aggregate function to attributes of the same correlation variable.

For example: the use of aggregate function correlation in Example 19-4 is invalid.

Example 19-4 Invalid Use of Aggregate Function

...
MEASURES xycorr AS correlation(X.price, Y.price)
PATTERN (X+ Y+)
DEFINE 
    X AS X.price <= 10,
    Y AS Y.price > 10
...

The correlation aggregate function may not operate on more than one correlation variable.

19.1.3.3 Referencing Variables That Have not Been Matched Yet

In the DEFINE clause, you may reference a correlation variable that has not been matched yet. However, you should use caution when doing so. Consider Example 19-5.

Example 19-5 Referencing a Variable That has not Been Matched Yet: Invalid

PATTERN (X+ Y+)
DEFINE
    X AS count(Y.*) >= 3
    Y AS Y.price > 10,

Although this syntax is legal, note that in this particular example, the pattern will never match because at the time X is matched, Y has not yet been matched, and count(Y.*) is 0.

To implement the desired behavior ("Match when the price of Y has been greater than 10, 3 or more times in a row"), implement this pattern as Example 19-6 shows.

Example 19-6 Referencing a Variable That has not Been Matched Yet: Valid

PATTERN (Y+ X+)
DEFINE
    Y AS Y.price > 10,
    X AS count(Y.*) >= 3

For more information, see Section 19.1.3.5, "Using count With *, identifier.*, and identifier.attr".

19.1.3.4 Referencing Attributes not Qualified by Correlation Variable

In the DEFINE clause, if you apply an aggregate function to an event attribute not qualified by correlation variable, the aggregate is a running aggregate as Example 19-7 shows.

Example 19-7 Referencing Attributes not Qualified by Correlation Variable

PATTERN ((RISE FALL)+)
DEFINE
    RISE AS count(RISE.*) = 1 or RISE.price > FALL.price,
    FALL AS FALL.price < RISE.price and count(*) > 1000

This query detects a pattern in which a price alternately goes up and down, for as long as possible, but for at least more than 1000 matches.

For more information, see:

19.1.3.5 Using count With *, identifier.*, and identifier.attr

The built-in aggregate function count has syntax:

Surrounding text describes count.png.

(arith_expr::=, attr::=, identifier::=)

The return value of count depends on the argument as Table 19-1 shows.

Table 19-1 Return Values for count Aggregate Function

Input ArgumentReturn Value

arith_expr

The number of tuples where arith_expr is not NULL.

*


The number of all tuples, including duplicates and nulls.

identifier.*

The number of all tuples that match the correlation variable identifier, including duplicates and nulls.

Note the following:

  • count(A.*) = 1 is true for the first event that matches A.

  • count(A.*) = 0 is true while A has not been matched yet.

identifier.attr

The number of tuples that match correlation variable identifier, where attr is not NULL.


Consider Example 19-8. Assume that the schema of S includes attributes account and balance. This query returns an event for each account that has not received 3 or more events in 60 minutes.

Example 19-8 MATCH_RECOGNIZE Query Using count(A.*)

select 
    T.account,
    T.Atime 
FROM S 
    MATCH_RECOGNIZE(
        PARTITION BY account
        MEASURES
            A.account has account
            A.ELEMENT_TIME as Atime
        ALL MATCHES
        INCLUDE TIMER EVENTS
        PATTERN (A+) 
        DURATION 60 MINUTES
        DEFINE
            A AS count(A.*) < 3
    ) as T

The PATTERN (A+) specifies the pattern "Match A one or more times".

The DEFINE clause specifies the condition:

A AS count(A.*) < 3

This condition for A places no restrictions on input tuples (such as A.balance > 1000). The only restrictions are imposed by the PARTITION BY account and DURATION 60 MINUTES clauses. In the DEFINE clause, the A.* means, "Match all input tuples for the group A+". This group includes the one or more input tuples with a particular account received in the 60 minutes starting with the first input tuple. The count(A.*) is a running aggregate that returns the total number of events in this group.

If the DEFINE clause specifies the condition:

A AS A.balance > 1000 and count(A.*) < 3

Then A.* still means "Match all input tuples for the group A+". In this case, this group includes the one or more input tuples with a particular account received in the 60 minutes starting with the first input tuple and with balance > 1000.

In contrast:

  • count(*) means "The number of all tuples, including duplicates and nulls". That is, the number of all tuples received on S, whether they satisfy the MATCH_RECOGNIZE clause or not.

  • count(A.balance) means "The number of all tuples that match the correlation variable A where the balance is not NULL".

For more information, see:

19.1.3.6 Using first and last

Use the first and last built-in aggregate functions to access event attributes of the first or last event match, respectively:

first returns the value of the first match of a group in the order defined by the ORDER BY clause or the default order.

last returns the value of the last match of a group in the order defined by the ORDER BY clause or the default order.

The first and last functions accept an optional non-negative, constant integer argument (N) that indicates the offset following the first and the offset preceding the last match of the variable, respectively. If you specify this offset, the first function returns the N-th matching event following the first match and the last function returns the N-th matching event preceding the last match. If the offset does not fall within the match of the variable, the first and last functions return NULL.

For more information, see:

19.1.4 Using prev

Use the prev built-in single-row function to access event attributes of a previous event match. If there is no previous event match, the prev function returns NULL.

The prev function accepts an optional non-negative, constant integer argument (N) that indicates the offset to a previous match. If you specify this offset, the prev function returns the N-th matching event preceding the current match. If there is no such previous match, the prev functions returns NULL.

When you use the prev function in the DEFINE clause, this function may only access the currently defined correlation variable.

For example: the correlation variable definition in Example 19-9 is valid:

Example 19-9 Use of the prev Function: Valid

Y AS Y.price < prev(Y.price, 2)

However, the correlation variable definition in Example 19-10 is invalid because while defining correlation variable Y, it references correlation variable X inside the prev function.

Example 19-10 Use of the prev Function: Invalid

Y AS Y.price < prev(X.price, 2)

For more information, see:

19.2 MEASURES Clause

The MEASURES clause exports (makes available for inclusion in the SELECT) attribute values of events that successfully match the pattern you specify.

You may specify expressions over correlation variables that reference partition attributes, order by attributes, singleton variables and aggregates on group variables, and aggregates on the attributes of the stream that is the source of the MATCH_RECOGNIZE clause.

You qualify attribute values by correlation variable to export the value of the attribute for the event that matches the correlation variable's condition. For example, within the MEASURES clause, A.c1 refers to the value of event attribute c1:

  • In the tuple that last matched the condition corresponding to correlation variable A, if A is specified in the DEFINE clause.

  • In the last processed tuple, if A is not specified in the DEFINE clause.

    This is because if A is not specified in the DEFINE clause, then A is considered as TRUE always. So effectively all the tuples in the input match to A.

You may include in the SELECT statement only attributes you specify in the MEASURES clause.

pattern_measures_clause::=

Surrounding text describes pattern_measures_clause.png.

(non_mt_measure_list::=)

non_mt_measure_list::=

Surrounding text describes non_mt_measure_list.png.

(measure_column::=)

measure_column::=

Surrounding text describes measure_column.png.

(arith_expr::=, identifier::=)

In Example 19-1, the pattern_measures_clause is:

MEASURES
    A.itemId as itemId

This section describes:

For more information, see:

19.2.1 Functions Over Correlation Variables in the MEASURES Clause

In the MEASURES clause, you may apply any single-row or aggregate function to the attributes of events that match a condition.

Example 19-11 applies the last function over correlation variable Z.c1 in the MEASURES clause.

Example 19-11 Using Functions Over Correlation Variables

<query id="tkpattern_q41"><![CDATA[ 
    select 
        T.firstW, T.lastZ 
    from 
        tkpattern_S11 
    MATCH_RECOGNIZE ( 
        MEASURES A.c1 as firstW, last(Z.c1) as lastZ 
        ALL MATCHES 
        PATTERN(A W+ X+ Y+ Z+) 
        DEFINE 
            W as W.c2 < prev(W.c2), 
            X as X.c2 > prev(X.c2), 
            Y as Y.c2 < prev(Y.c2), 
            Z as Z.c2 > prev(Z.c2)
    ) as T
]]></query>

Note the following in the MEASURES clause in Example 19-11:

  • A.c1 will export the value of c1 in the first and only the first event that the query processes because:

    • A is not specified in the DEFINE clause, therefor it is always true.

    • A has no pattern quantifiers, therefor it will match exactly once.

  • The built-in aggregate function last will export the value of c1 in the last event that matched Z at the time the PATTERN clause was satisfied.

For more information, see:

19.3 PATTERN Clause

The PATTERN clause specifies the pattern to be matched as a regular expression over one ore more correlation variables.

Incoming events must match these conditions in the order given (from left to right).

The regular expression may contain correlation variables that are:

  • Defined in the DEFINE clause: such correlation variables are considered true only if their condition definition evaluates to TRUE.

    See Section 19.4, "DEFINE Clause".

  • Not defined in the DEFINE clause: such correlation variables are considered as always TRUE; that is, they match every input.

pattern_clause::=

Surrounding text describes pattern_clause.png.

(regexp::=, within_clause::=)

This section describes:

For more information, see:

19.3.1 Pattern Quantifiers and Regular Expressions

You express the pattern as a regular expression composed of correlation variables and pattern quantifiers.

regexp::=

Surrounding text describes regexp.png.

(correlation_name::=, pattern_quantifier::=)

correlation_name::=

Surrounding text describes correlation_name.png.

(const_string::=)

pattern_quantifier::=

Surrounding text describes pattern_quantifier.png.

Table 19-2 lists the pattern quantifiers (pattern_quantifier::=) Oracle CQL supports.

Table 19-2 MATCH_RECOGNIZE Pattern Quantifiers

MaximalMinimalDescription

*

*?

0 or more times

+

+?

1 or more times.

?

??

0 or 1 time.

None

None

An unquantified pattern, such as A, is assumed to have a quantifier that requires exactly 1 match.


Use the pattern quantifiers to specify the pattern as a regular expression, such as A* or A+?.

The one-character pattern quantifiers are maximal or "greedy"; they will attempt to match as many instances of the regular expression on which they are applied as possible.

The two-character pattern quantifiers are minimal or "reluctant"; they will attempt to match as few instances of the regular expression on which they are applied as possible.

Consider the following pattern_clause:

PATTERN (A B* C)

This pattern clause means a pattern match will be recognized when the following conditions are met by consecutive incoming input tuples:

  1. Exactly one tuple matches the condition that defines correlation variable A, followed by

  2. Zero or more tuples that match the correlation variable B, followed by

  3. Exactly one tuple that matches correlation variable C.

While in state 2, if a tuple arrives that matches both the correlation variables B and C (since it satisfies the defining conditions of both of them) then as the quantifier * for B is greedy that tuple will be considered to have matched B instead of C. Thus due to the greedy property B gets preference over C and we match a greater number of B. Had the pattern expression be A B*? C, one that uses a lazy or reluctant quantifier over B, then a tuple matching both B and C will be treated as matching C only. Thus C would get preference over B and we will match fewer B.

For more information, see:

19.3.2 Grouping and Alternation in the PATTERN Clause

As shown in the regexp_grp_alt syntax, you can use:

  • open and close round brackets (( and )) to group correlation variables

  • alternation operators (|) to match either one correlation variable (or group of correlation variables) or another

regexp_grp_alt::=

Surrounding text describes regexp_grp_alt.png.

(correlation_name::=, pattern_quantifier::=, regexp::=)

Consider the following pattern_clause:

PATTERN (A+ B+)

This means "A one or more times followed by B one or more times".

You can group correlation variables. For example:

PATTERN (A+ (C+ B+)*)

This means "A one or more times followed by zero or more occurrences of C one or more times and B one or more times".

Using the PATTERN clause alternation operator (|), you can refine the sense of the pattern_clause. For example:

PATTERN (A+ | B+)

This means "A one or more times or B one or more times, whichever comes first".

Similarly, you can both group correlation variables and use the alternation operator. For example:

PATTERN (A+ (C+ | B+))

This means "A one or more times followed by either C one or more times or B one or more times, whichever comes first".

To match every permutation you can use:

PATTERN ((A B) | (B A))

This means "A followed by B or B followed by A, which ever comes first".

For more information, see:

19.4 DEFINE Clause

The DEFINE clause specifies the boolean condition for each correlation variable.

You may specify any logical or arithmetic expression and apply any single-row or aggregate function to the attributes of events that match a condition.

On receiving a new tuple from the base stream, the conditions of the correlation variables that are relevant at that point in time are evaluated. A tuple is said to have matched a correlation variable if it satisfies its defining condition. A particular input can match zero, one, or more correlation variables. The relevant conditions to be evaluated on receiving an input are determined by logic governed by the PATTERN clause regular expression and the state in pattern recognition process that we have reached after processing the earlier inputs.

The condition can refer to any of the attributes of the schema of the stream or view that evaluates to a stream on which the MATCH_RECOGNIZE clause is being applied.

A correlation variable in the PATTERN clause need not be specified in the DEFINE clause: the default for such a correlation variable is a predicate that is always true. Such a correlation variable matches every event. It is an error to specify a correlation variable in the DEFINE clause which is not used in a PATTERN clause

No correlation variable defined by a SUBSET clause may be defined in the DEFINE clause.

pattern_definition_clause::=

Surrounding text describes pattern_definition_clause.png.

(non_mt_corrname_definition_list::=)

non_mt_corrname_definition_list::=

Surrounding text describes non_mt_corrname_def_list.png.

(correlation_name_definition::=)

correlation_name_definition::=

Surrounding text describes correlation_name_definition.png.

(correlation_name::=, non_mt_cond_list::=)

This section describes:

For more information, see:

19.4.1 Functions Over Correlation Variables in the DEFINE Clause

You can use functions over the correlation variables while defining them.

Example 19-12 applies the to_timestamp function to correlation variables.

Example 19-12 Using Functions Over Correlation Variables: to_timestamp

...
      PATTERN (A B* C)
      DEFINE
          A  AS  (A.temp >= 25),
          B  AS  ((B.temp >= 25) and (to_timestamp(B.element_time) - to_timestamp(A.element_time) < INTERVAL "0 00:00:05.00" DAY TO SECOND)),
          C  AS  (to_timestamp(C.element_time) - to_timestamp(A.element_time) >= INTERVAL "0 00:00:05.00" DAY TO SECOND)
...

Example 19-13 applies the count function to correlation variable B to count the number of times its definition was satisfied. A match is recognized when totalCountValue is less than 1000 two or more times in 30 minutes.

Example 19-13 Using Functions Over Correlation Variables: count

...
    MATCH_RECOGNIZE(
        ...
        PATTERN(B*)
        DURATION 30 MINUTES
        DEFINE
            B as (B.totalCountValue < 1000 and count(B.*) >= 2)
...

For more information, see:

19.4.2 Referencing Attributes in the DEFINE Clause

You can refer to the attributes of a base stream:

  • Without a correlation variable: c1 < 20.

  • With a correlation variable: A.c1 < 20.

When you refer to the attributes without a correlation variable, a tuple that last matched any of the correlation variables is consulted for evaluation.

Consider the following definitions:

  • DEFINE A as c1 < 20

  • DEFINE A as A.c1 < 20

Both refer to c1 in the same tuple which is the latest input tuple. This is because on receiving an input we evaluate the condition of a correlation variable assuming that the latest input matches that correlation variable.

If you specify a correlation name that is not defined in the DEFINE clause, it is considered to be true for every input.

In Example 19-14, correlation variable A appears in the PATTERN clause but is not specified in the DEFINE clause. This means the correlation name A is true for every input. It is an error to define a correlation name which is not used in a PATTERN clause.

Example 19-14 Undefined Correlation Name

<query id="q"><![CDATA[ 
    SELECT
        T.firstW,
        T.lastZ
    FROM
        S2
    MATCH_RECOGNIZE (
        MEASURES
            A.c1 as firstW,
            last(Z) as lastZ
        PATTERN(A W+ X+ Y+ Z+)
        DEFINE 
            W as W.c2 < prev(W.c2),
            X as X.c2 > prev(X.c2),
            Y as Y.c2 < prev(Y.c2),
            Z as Z.c2 > prev(Z.c2)
    ) as T
]]></query>

For more information, see:

19.4.3 Referencing One Correlation Variable From Another in the DEFINE Clause

A definition of one correlation variable can refer to another correlation variable. Consider the query that Example 19-15 shows:

Example 19-15 Referencing One Correlation Variable From Another

...
Select
    a_firsttime, d_lasttime, b_avgprice, d_avgprice
FROM
    S
MATCH_RECOGNIZE (
    PARTITION BY symbol
    MEASURES
        first(a.time) as a_firsttime,
        last(d.time) as d_lasttime,
        avg(b.price) as b_avgprice,
        avg(d.price) as d_avgprice
    PATTERN (A B+ C+ D)
    DEFINE
        A as A.price > 100,
        B as B.price > A.price,
        C as C.price < avg(B.price),
        D as D.price > prev(D.price)
)
...

Note the following:

  • Because correlation variable A defines a single attribute, B can refer to this single attribute.

  • Because B defines more than one attribute, C cannot reference a single attribute of B. In this case, C may only reference an aggregate of B.

  • D is defined in terms of itself: in this case, you may refer to a single attribute or an aggregate. In this example, the prev function is used to access the match of D prior to the current match.

For more information, see:

19.5 PARTITION BY Clause

Use this optional clause to specify the stream attributes by which a MATCH_RECOGNIZE clause should partition its results.

Without a PARTITION BY clause, all stream attributes belong to the same partition.

pattern_partition_clause::=

Surrounding text describes pattern_partition_clause.png.

(non_mt_attr_list::=)

In Example 19-1, the pattern_partition_clause is:

PARTITION BY 
    itemId

The partition by clause in pattern means the input stream is logically divided based on the attributes mentioned in the partition list and pattern matching is done within a partition.

Consider a stream S with schema (c1 integer, c2 integer) with the input data that Example 19-16 shows.

Example 19-16 Input Stream S1

     c1  c2
1000 10, 1
2000 10, 2
3000 20, 2
4000 20, 1

Consider the MATCH_RECOGNIZE query that Example 19-17 shows.

Example 19-17 MATCH_RECOGNIZE Query Using Input Stream S1

select T.p1, T.p2, T.p3 from S MATCH_RECOGNIZE(
    MEASURES
        A.ELEMENT_TIME as p1,
        B.ELEMENT_TIME as p2
        B.c2 as p3
    PATTERN (A B)
    DEFINE
        A as A.c1 = 10,
        B as B.c1 = 20
) as T

This query would output the following:

3000:+ 2000, 3000, 2

If we add PARTITION BY c2 to the query that Example 19-17 shows, then the output would change to:

3000:+ 2000, 3000, 2
4000:+ 1000, 4000, 1

This is because by adding the PARTITION BY clause, matches are done within partition only. Tuples at 1000 and 4000 belong to one partition and tuples at 2000 and 3000 belong to another partition owing to the value of c2 attribute in them. In the first partition A matches tuple at 1000 and B matches tuple at 4000. Even though a tuple at 3000 matches the B definition, it is not presented as a match for the first partition since that tuple belongs to different partition.

When you partition by more than one attribute, you can control the order of partitions using the ORDER BY clause. For more information, see Section 19.6, "ORDER BY Clause".

19.6 ORDER BY Clause

Use this optional clause to specify the stream attributes by which a MATCH_RECOGNIZE clause should order partitions when using a PARTITION BY clause.

Without an ORDER BY clause, the results of MATCH_RECOGNIZE are nondeterministic.

pattern_order_by_top_clause::=

Surrounding text describes pattern_order_by_top_clause.png.<br/>

You may only use the ORDER BY clause with a PARTITION BY clause.

For more information, see Section 19.5, "PARTITION BY Clause,"pattern_partition_clause::=, and order_by_list::=.

19.7 ALL MATCHES Clause

Use this optional clause to configure Oracle CEP to match overlapping patterns.

With the ALL MATCHES clause, Oracle CEP finds all possible matches. Matches may overlap and may start at the same event. In this case, there is no distinction between greedy and reluctant pattern quantifiers. For example, the following pattern:

ALL MATCHES
PATTERN (A* B)

produces the same result as:

ALL MATCHES
PATTERN (A*? B)

Without the ALL MATCHES clause, overlapping matches are not returned, and quantifiers such as the asterisk determine which among a set of candidate (and overlapping) matches is the preferred one for output. The rest of the overlapping matches are discarded.

pattern_skip_match_clause::=

Surrounding text describes pattern_skip_match_clause.png.

Consider the query tkpattern_q41 in Example 19-18 that uses ALL MATCHES and the data stream tkpattern_S11 in Example 19-19. Stream tkpattern_S11 has schema (c1 integer, c2 integer). The query returns the stream in Example 19-20.

The query tkpattern_q41 in Example 19-18 will report a match when the input stream values, when plotted, form the shape of the English letter W. The relation in Example 19-20 shows an example of overlapping instances of this W-pattern match.

There are two types of overlapping pattern instances:

  • Total: Example of total overlapping: Rows from time 3000-9000 and 4000-9000 in the input, both match the given pattern expression. Here the longest one (3000-9000) will be preferred if ALL MATCHES clause is not present.

  • Partial: Example of Partial overlapping: Rows from time 12000-21000 and 16000-23000 in the input, both match the given pattern expression. Here the one which appears earlier is preferred when ALL MATCHES clause is not present. This is because when ALL MATCHES clause is omitted, we start looking for the next instance of pattern match at a tuple which is next to the last tuple in the previous matched instance of the pattern.

Example 19-18 ALL MATCHES Clause Query

<query id="tkpattern_q41"><![CDATA[ 
    select 
        T.firstW, T.lastZ 
    from 
        tkpattern_S11 
    MATCH_RECOGNIZE ( 
        MEASURES A.c1 as firstW, last(Z.c1) as lastZ 
        ALL MATCHES 
        PATTERN(A W+ X+ Y+ Z+) 
        DEFINE 
            W as W.c2 < prev(W.c2), 
            X as X.c2 > prev(X.c2), 
            Y as Y.c2 < prev(Y.c2), 
            Z as Z.c2 > prev(Z.c2)
    ) as T
]]></query>

Example 19-19 ALL MATCHES Clause Stream Input

Timestamp   Tuple
 1000         1,8
 2000         2,8
 3000         3,8
 4000         4,6
 5000         5,3
 6000         6,7
 7000         7,6
 8000         8,2
 9000         9,6
10000        10,2
11000        11,9
12000        12,9
13000        13,8
14000        14,5
15000        15,0
16000        16,9
17000        17,2
18000        18,0
19000        19,2
20000        20,3
21000        21,8
22000        22,5
23000        23,9
24000        24,9
25000        25,4
26000        26,7
27000        27,2
28000        28,8
29000        29,0
30000        30,4
31000        31,4
32000        32,7
33000        33,8
34000        34,6
35000        35,4
36000        36,5
37000        37,1
38000        38,7
39000        39,5
40000        40,8
41000        41,6
42000        42,6
43000        43,0
44000        44,6
45000        45,8
46000        46,4
47000        47,3
48000        48,8
49000        49,2
50000        50,5
51000        51,3
52000        52,3
53000        53,9
54000        54,8
55000        55,5
56000        56,5
57000        57,9
58000        58,7
59000        59,3
60000        60,3

Example 19-20 ALL MATCHES Clause Stream Output

Timestamp   Tuple Kind  Tuple
 9000:      +      3,9
 9000:      +      4,9
11000:      +      6,11
11000:      +      7,11
19000:      +     12,19
19000:      +     13,19
19000:      +     14,19
20000:      +     12,20
20000:      +     13,20
20000:      +     14,20
21000:      +     12,21
21000:      +     13,21
21000:      +     14,21
23000:      +     16,23
23000:      +     17,23
28000:      +     24,28
30000:      +     26,30
38000:      +     33,38
38000:      +     34,38
40000:      +     36,40
48000:      +     42,48
50000:      +     45,50
50000:      +     46,50

As Example 19-20 shows, the ALL MATCHES clause reports all the matched pattern instances on receiving a particular input. For example, at time 20000, all of the tuples {12,20}, {13,20}, and {14,20} are output.

For more information, see Section 19.3.1, "Pattern Quantifiers and Regular Expressions".

19.8 WITHIN Clause

The WITHIN clause is an optional clause that outputs a pattern_clause match if and only if the match occurs within the specified time duration.

within_clause::=

Surrounding text describes within_clause.png.

(time_spec::=)

That is, if and only if:

TL - TF < WD

Where:

  • TL - Timestamp of last event matching the pattern.

  • TF - Timestamp of first event matching the pattern.

  • WD - Duration specified in the WITHIN clause.

The WITHIN INCLUSIVE clause tries to match events at the boundary case as well. That is, it outputs a match if and only if:

TL - TF <= WD

If the match completes within the specified time duration, then the event is output as soon as it happens. That is, if the match can be output, it is output with the timestamp at which it completes. The WITHIN clause does not wait for the time duration to expire as the DURATION clause does.

When the WITHIN clause duration expires, it discards any potential candidate matches which are incomplete.

For more information, see Section 19.12.4, "Pattern Detection With the WITHIN Clause".


Note:

You cannot use a WITHIN clause with a DURATION clause. For more information, see Section 19.9, "DURATION 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::=

Surrounding text describes duration_clause_fixed.png.

(time_unit::=)

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:


Note:

You cannot use a DURATION clause with a WITHIN clause. For more information, see Section 19.8, "WITHIN Clause".


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::=); 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 
        PATTERN(A 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".

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.

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, sum(B.c1) as p3 
        ALL MATCHES 
        include timer events 
        PATTERN(A 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"). 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.

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::=

Surrounding text describes pattern_inc_tim_evs_cl.png.

(pattern_clause::=, pattern_skip_match_clause::=, pattern_definition_clause::=, duration_clause::=, subset_clause::=)

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::=

Surrounding text describes subset_clause.png.

(non_mt_subset_definition_list::=)

non_mt_subset_definition_list::=

Surrounding text describes non_mt_subset_def_list.png.

(subset_definition::=)

subset_definition::=

Surrounding text describes subset_definition.png.

(subset_name::=, non_mt_corr_list::=)

subset_name::=

Surrounding text describes subset_name.png.

(const_string::=)

non_mt_corr_list::=

Surrounding text describes non_mt_corr_list.png.

(correlation_name::=)

Consider the query q55 in Example 19-27 and the data stream S11 in Example 19-28. Stream S11 has schema (c1 integer, c2 integer). This example defines subsets S1 through S6. This query outputs a match if the c2 attribute values in the input stream form the shape of the English letter W. Now suppose we want to know the sum of the values of c2 for those tuples which form the incrementing arms of this W shape. The correlation variable X represents tuples that are part of the first incrementing arm and Z represent the tuples that are part of the second incrementing arm. So we need some way to group the tuples that match both. Such a requirement can be captured by defining a SUBSET clause as the example shows.

Subset S4 is defined as (X,Z). It refers to the tuples in the input stream that match either X or Z. This subset is used in the MEASURES clause statement sum(S4.c2) as sumIncrArm. This computes the sum of the value of c2 attribute in the tuples that match either X or Z. A reference to S4.c2 in a DEFINE clause like S4.c2 = 10 will refer to the value of c2 in the latest among the last tuple that matched X and the last tuple that matched Z.

Subset S6 is defined as (Y). It refers to all the tuples that match correlation variable Y.

The query returns the stream in Example 19-29.

Example 19-27 MATCH_RECOGNIZE with SUBSET Clause Query

<query id="q55"><![CDATA[ 
    select
        T.firstW,
        T.lastZ,
        T.sumDecrArm,
        T.sumIncrArm,
        T.overallAvg 
    from 
        S11 
    MATCH_RECOGNIZE ( 
        MEASURES 
            S2.c1 as firstW, 
            last(S1.c1) as lastZ, 
            sum(S3.c2) as sumDecrArm, 
            sum(S4.c2) as sumIncrArm, 
            avg(S5.c2) as overallAvg 
        PATTERN(A W+ X+ Y+ Z+) 
        SUBSET S1 = (Z) S2 = (A) S3 = (A,W,Y) S4 = (X,Z) S5 = (A,W,X,Y,Z) S6 = (Y) 
        DEFINE 
            W as W.c2 < prev(W.c2), 
            X as X.c2 > prev(X.c2), 
            Y as S6.c2 < prev(Y.c2), 
            Z as Z.c2 > prev(Z.c2)
    ) as T
]]></query>

Example 19-28 MATCH_RECOGNIZE with SUBSET Clause Stream Input

Timestamp   Tuple
 1000        1,8
 2000        2,8
 3000        3,8
 4000        4,6
 5000        5,3
 6000        6,7
 7000        7,6
 8000        8,2
 9000        9,6
10000       10,2
11000       11,9
12000       12,9
13000       13,8
14000       14,5
15000       15,0
16000       16,9
17000       17,2
18000       18,0
19000       19,2
20000       20,3
21000       21,8
22000       22,5
23000       23,9
24000       24,9
25000       25,4
26000       26,7
27000       27,2
28000       28,8
29000       29,0
30000       30,4
31000       31,4
32000       32,7
33000       33,8
34000       34,6
35000       35,4
36000       36,5
37000       37,1
38000       38,7
39000       39,5
40000       40,8
41000       41,6
42000       42,6
43000       43,0
44000       44,6
45000       45,8
46000       46,4
47000       47,3
48000       48,8
49000       49,2
50000       50,5
51000       51,3
52000       52,3
53000       53,9
54000       54,8
55000       55,5
56000       56,5
57000       57,9
58000       58,7
59000       59,3
60000       60,3

Example 19-29 MATCH_RECOGNIZE with SUBSET Clause Stream Output

Timestamp   Tuple Kind  Tuple
 9000:      +           3,9,25,13,5.428571
21000:      +           12,21,24,22,4.6
28000:      +           24,28,15,15,6.0
38000:      +           33,38,19,12,5.1666665
48000:      +           42,48,13,22,5.0

For more information, see:

19.12 MATCH_RECOGNIZE Examples

The following examples illustrate basic MATCH_RECOGNIZE practices:

For more examples, see Oracle Fusion Middleware Getting Started Guide for Oracle Complex Event Processing.

19.12.1 Pattern Detection

Consider the stock fluctuations that Figure 19-1 shows. This data can be represented as a stream of stock ticks (index number or time) and stock price. Figure 19-1 shows a common trading behavior known as a double bottom pattern between days 1 and 9 and between days 12 and 19. This pattern can be visualized as a W-shaped change in stock price: a fall (X), a rise (Y), a fall (W), and another rise (Z).

Figure 19-1 Pattern Detection: Double Bottom Stock Fluctuations

Description of Figure 19-1 follows

Example 19-30 shows a query q on stream S2 of stock price events with schema symbol, stockTick, and price. This query detects double bottom patterns on the incoming stock trades using the PATTERN clause (A W+ X+ Y+ Z+). The correlation names in this clause are:

  • A: corresponds to the start point of the double bottom pattern.

    Because correlation name A is true for every input, it is not defined in the DEFINE clause. If you specify a correlation name that is not defined in the DEFINE clause, it is considered to be true for every input.

  • W+: corresponds to the first decreasing arm of the double bottom pattern.

    It is defined by W.price < prev(W.price). This definition implies that the current price is less than the previous one.

  • X+: corresponds to the first increasing arm of the double bottom pattern.

  • Y+: corresponds to the second decreasing arm of the double bottom pattern.

  • Z+: corresponds to the second increasing arm of the double bottom pattern.

Example 19-30 Simple Pattern Detection: Query

<query id="q"><![CDATA[ 
    SELECT
        T.firstW,
        T.lastZ
    FROM
        S2
    MATCH_RECOGNIZE (
        MEASURES
            A.stockTick as firstW,
            last(Z) as lastZ
        PATTERN(A W+ X+ Y+ Z+)
        DEFINE 
            W as W.price < prev(W.price),
            X as X.price > prev(X.price),
            Y as Y.price < prev(Y.price),
            Z as Z.price > prev(Z.price)
    ) as T
    WHERE
        S2.symbol = "oracle"
]]></query>

19.12.2 Pattern Detection With PARTITION BY

Consider the stock fluctuations that Figure 19-2 shows. This data can be represented as a stream of stock ticks (index number or time) and stock price. In this case, the stream contains data for more than one stock ticker symbol. Figure 19-2 shows a common trading behavior known as a double bottom pattern between days 1 and 9 and between days 12 and 19 for stock BOFA. This pattern can be visualized as a W-shaped change in stock price: a fall (X), a rise (Y), a fall (W), and another rise (Z).

Figure 19-2 Pattern Detection With Partition By: Stock Fluctuations

Description of Figure 19-2 follows

Example 19-31 shows a query q on stream S2 of stock price events with schema symbol, stockTick, and price. This query detects double bottom patterns on the incoming stock trades using the PATTERN clause (A W+ X+ Y+ Z+). The correlation names in this clause are:

  • A: corresponds to the start point of the double bottom pattern.

  • W+: corresponds to the first decreasing arm of the double bottom pattern as defined by W.price < prev(W.price), which implies that the current price is less than the previous one.

  • X+: corresponds to the first increasing arm of the double bottom pattern.

  • Y+: corresponds to the second decreasing arm of the double bottom pattern.

  • Z+: corresponds to the second increasing arm of the double bottom pattern.

The query partitions the input stream by stock ticker symbol using the PARTITION BY clause and applies this PATTERN clause to each logical stream.

Example 19-31 Pattern Detection With PARTITION BY: Query

<query id="q"><![CDATA[ 
    SELECT
        T.firstW,
        T.lastZ
    FROM
        S2
    MATCH_RECOGNIZE (
        PARTITION BY
            A.symbol
        MEASURES
            A.stockTick as firstW,
            last(Z) as lastZ
        PATTERN(A W+ X+ Y+ Z+)
        DEFINE
            W as W.price < prev(W.price),
            X as X.price > prev(X.price),
            Y as Y.price < prev(Y.price),
            Z as Z.price > prev(Z.price)
    ) as T
]]></query>

19.12.3 Pattern Detection With Aggregates

Consider the query q1 in Example 19-32 and the data stream S in Example 19-33. Stream S has schema (c1 integer). The query returns the stream in Example 19-34.

Example 19-32 Pattern Detection With Aggregates: Query

<query id="q1"><![CDATA[ 
    SELECT 
        T.sumB 
    FROM 
        S 
    MATCH_RECOGNIZE ( 
        MEASURES 
            sum(B.c1) as sumB 
        PATTERN(A B* C) 
        DEFINE 
            A as ((A.c1 < 50) AND (A.c1 > 35)), 
            B as B.c1 > avg(A.c1), 
            C as C.c1 > prev(C.c1)
    ) as T
]]></query>

Example 19-33 Pattern Detection With Aggregates: Stream Input

Timestamp   Tuple
 1000       40
 2000       52
 3000       60
 4000       58
 5000       57
 6000       56
 7000       55
 8000       59
 9000       30
10000       40
11000       52
12000       60
13000       58
14000       57
15000       56
16000       55
17000       30
18000       10
19000       20
20000       30
21000       10
22000       25
23000       25
24000       25
25000       25

Example 19-34 Pattern Detection With Aggregates: Stream Output

Timestamp   Tuple
8000        338
12000       52

19.12.4 Pattern Detection With the WITHIN Clause

Consider the queries in Example 19-35 and Example 19-36 and the data stream S in Example 19-37. Stream S has schema (c1 integer, c2 integer). Table 19-3 compares the output of these queries.

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

Table 19-3 WITHIN and WITHIN INCLUSIVE Query Output

Query queryWithinQuery queryWithinInclusive
Timestamp   Tuple Kind  Tuple
3000:      +           100,300,
6000:      +           400,600,
9000:      +           800,900,
Timestamp   Tuple Kind  Tuple
 4000:      +           100,400,
11000:      +           800,1000,

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.

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:

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

Description of Figure 19-3 follows

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.

Example 19-38 Fixed Duration Non-Event Detection: Query

<query id="q"><![CDATA[ 
select T.Atime FROM S
    MATCH_RECOGNIZE(
        MEASURES
            A.ELEMENT_TIME as Atime
       INCLUDE TIMER EVENTS
       PATTERN (A B*) 
       DURATION 5 MINUTES
       DEFINE
           A as A.c1 = 1,
           B as B.c1 != 5
    ) as T
]]></query>

For more information, see Section 19.9, "DURATION Clause".

PKjLq]PKO_\EOEBPS/intro.htm Introduction to Oracle CQL

1 Introduction to Oracle CQL

This chapter introduces Oracle Continuous Query Language (Oracle CQL), a query language based on SQL with added constructs that support streaming data. Using Oracle CQL, you can express queries on data streams with Oracle Complex Event Processing (Oracle CEP).

Oracle CEP (formally known as the WebLogic Event Server) is a Java server for the development of high-performance event driven applications. It is a lightweight Java application container based on Equinox OSGi, with shared services, including the Oracle CEP Service Engine, which provides a rich, declarative environment based on Oracle CQL to improve the efficiency and effectiveness of managing business operations. Oracle CEP supports ultra-high throughput and microsecond latency using JRockit Real Time and provides Oracle CEP Visualizer and Oracle CEP IDE for Eclipse developer tooling for a complete real time end-to-end Java Event-Driven Architecture (EDA) development platform.

1.1 Fundamentals of Oracle CQL

Databases are best equipped to run queries over finite stored data sets. However, many modern applications require long-running queries over continuous unbounded sets of data. By design, a stored data set is appropriate when significant portions of the data are queried repeatedly and updates are relatively infrequent. In contrast, data streams represent data that is changing constantly, often exclusively through insertions of new elements. It is either unnecessary or impractical to operate on large portions of the data multiple times.

Many types of applications generate data streams as opposed to data sets, including sensor data applications, financial tickers, network performance measuring tools, network monitoring and traffic management applications, and clickstream analysis tools. Managing and processing data for these types of applications involves building data management and querying capabilities with a strong temporal focus.

To address this requirement, Oracle introduces Oracle CEP, a data management infrastructure that supports the notion of streams of structured data records together with stored relations.

To provide a uniform declarative framework, Oracle offers Oracle Continuous Query Language (Oracle CQL), a query language based on SQL with added constructs that support streaming data.

Oracle CQL is designed to be:

  • Scalable with support for a large number of queries over continuous streams of data and traditional stored data sets.

  • Comprehensive to deal with complex scenarios. For example, through composability, you can create various intermediate views for querying.

Figure 1-1 shows a simplified view of the Oracle CEP architecture. Oracle CEP server provides the light-weight Spring container for Oracle CEP applications. The Oracle CEP application shown is composed of an event adapter that provides event data to an input channel. The input channel is connected to an Oracle CQL processor associated with one or more Oracle CQL queries that operate on the events offered by the input channel. The Oracle CQL processor is connected to an output channel to which query results are written. The output channel is connected to an event Bean: a user-written Plain Old Java Object (POJO) that takes action based on the events it receives from the output channel.

Figure 1-1 Oracle CEP Architecture

Description of Figure 1-1 follows

Using Oracle CEP, you can define event adapters for a variety of data sources including JMS, relational database tables, and files in the local filesystem. You can connect multiple input channels to an Oracle CQL processor and you can connect an Oracle CQL processor to multiple output channels. You can connect an output channel to another Oracle CQL processor, to an adapter, to a cache, or an event Bean.

Using Oracle CEP IDE for Eclipse and Oracle CEP Visualizer, you:

  • Create an Event Processing Network (EPN) as Figure 1-1 shows.

  • Associate one more Oracle CQL queries with the Oracle CQL processors in your EPN.

  • Package your Oracle CEP application and deploy it to Oracle CEP server for execution.

Consider the typical Oracle CQL statements that Example 1-1 shows.

Example 1-1 Typical Oracle CQL Statements

<?xml version="1.0" encoding="UTF-8"?>
<n1:config xsi:schemaLocation="http://www.bea.com/ns/wlevs/config/application wlevs_application_config.xsd" 
xmlns:n1="http://www.bea.com/ns/wlevs/config/application" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<processor>
    <name>cqlProcessor</name>
    <rules>
        <view id="lastEvents" schema="cusip bid ask"><![CDATA[ 
            select cusip, bid, srcId, bidQty, ask, askQty, seq 
            from inputChannel[partition by srcId, cusip rows 1]
        ]]></view>
        <view id="bidask" schema="cusip bid ask"><![CDATA[ 
            select cusip, max(bid), min(ask) 
            from lastEvents
            group by cusip
        ]]></view>
            <view ...><![CDATA[
                ...
        ]]></view>
        ...
        <view id="MAXBIDMINASK" schema="cusip bidseq bidSrcId bid askseq askSrcId ask bidQty askQty"><![CDATA[ 
            select bid.cusip, bid.seq, bid.srcId as bidSrcId, bid.bid, ask.seq, ask.srcId as askSrcId, ask.ask, bid.bidQty, ask.askQty 
            from BIDMAX as bid, ASKMIN as ask 
            where bid.cusip = ask.cusip
        ]]></view>
        <query id="BBAQuery"><![CDATA[ 
            ISTREAM(select bba.cusip, bba.bidseq, bba.bidSrcId, bba.bid, bba.askseq, bba.askSrcId, bba.ask, 
                bba.bidQty, bba.askQty, "BBAStrategy" as intermediateStrategy, p.seq as correlationId, 1 as priority 
            from MAXBIDMINASK as bba, inputChannel[rows 1] as p where bba.cusip = p.cusip)
        ]]></query>
    </rules>
</processor>

This example defines multiples views (the Oracle CQL-equivalent of subqueries) to create multiple relations, each building on previous views. Views always act on an inbound channel such as inputChannel. The first view, named lastEvents, selects directly from inputChannel. Subsequent views may select from inputChannel directly or select from previously defined views. The results returned by a view's select statement remain in the view's relation: they are not forwarded to any outbound channel. That is the responsibility of a query. This example defines query BBAQuery that selects from both the inputChannel directly and from previously defined views. The results returned from a query's select clause are forwarded to the outbound channel associated with it: in this example, to outputChannel. The BBAQuery uses a tuple-based stream-to-relation operator (or sliding window).

For more information on these elements, see:

For more information on Oracle CEP server and tools, see:

1.1.1 Streams and Relations

This section introduces the two fundamental Oracle CEP objects that you manipulate using Oracle CQL:

Using Oracle CQL, you can perform the following operations with streams and relations:

1.1.1.1 Streams

A stream is the principle source of data that Oracle CQL queries act on.

Stream S is a bag (or multi-set) of elements (s,T) where s is in the schema of S and T is in the time domain.

Stream elements are tuple-timestamp pairs, which can be represented as a sequence of timestamped tuple insertions. In other words, a stream is a sequence of timestamped tuples. There could be more than one tuple with the same timestamp. The tuples of an input stream are required to arrive at the system in the order of increasing timestamps. For more information, see Section 1.1.13, "Time".

A stream has an associated schema consisting of a set of named attributes, and all tuples of the stream conform to the schema.

The term "tuple of a stream" denotes the ordered list of data portion of a stream element, excluding timestamp data (the s of <s,t>). Example 1-2 shows how a stock ticker data stream might appear, where each stream element is made up of <timestamp value>, <stock symbol>, and <stock price>:

Example 1-2 Stock Ticker Data Stream

...
<timestampN>    NVDA,4
<timestampN+1>  ORCL,62
<timestampN+2>  PCAR,38
<timestampN+3>  SPOT,53
<timestampN+4>  PDCO,44
<timestampN+5>  PTEN,50
...

In the stream element <timestampN+1>  ORCL,62, the tuple is ORCL,62.

By definition, a stream is unbounded.

This section describes:

For more information, see:

1.1.1.1.1 Streams and Channels

Oracle CEP represents a stream as a channel as Figure 1-2 shows. Using Oracle CEP IDE for Eclipse, you connect the stream event source (PriceAdapter) to a channel (priceStream) and the channel to an Oracle CQL processor (filterFanoutProcessor) to supply the processor with events. You connect the Oracle CQL processor to a channel (filteredStream) to output Oracle CQL query results to down-stream components (not shown in Figure 1-2).

Figure 1-2 Stream in the Event Processing Network

Description of Figure 1-2 follows


Note:

In Oracle CEP, you must use a channel to connect an event source to an Oracle CQL processor and to connect an Oracle CQL processor to an event sink. A channel is optional with other Oracle CEP processor types.


1.1.1.1.2 Channel Schema

The event source you connect to a stream determines the stream's schema. In Figure 1-2, the PriceAdapter adapter determines the priceStream stream's schema. Example 1-3 shows the PriceAdapter Event Processing Network (EPN) assembly file: the eventTypeName property specifies event type PriceEvent. The event-type-repository defines the property names and types for this event.

Example 1-3 Channel Schema Definition

...
<wlevs:event-type-repository>
    <wlevs:event-type type-name="PriceEvent">
        <wlevs:properties>
            <wlevs:property name="cusip" type="char" />
            <wlevs:property name="bid" type="double" />
            <wlevs:property name="srcId" type="char" />
            <wlevs:property name="bidQty" type="int" />
            <wlevs:property name="ask" type="double" />
            <wlevs:property name="askQty" type="int" />
            <wlevs:property name="seq" type="bigint" />
            <wlevs:property name="sector" type="char" />
        </wlevs:properties>
    </wlevs:event-type>
</wlevs:event-type-repository>

<wlevs:adapter id="PriceAdapter" provider="loadgen">
    <wlevs:instance-property name="port" value="9011"/>
    <wlevs:listener ref="priceStream"/>
</wlevs:adapter>

<wlevs:channel id="priceStream" event-type="PriceEvent">
    <wlevs:listener ref="filterFanoutProcessor"/>
</wlevs:channel>

<wlevs:processor id="filterFanoutProcessor" provider="cql">
    <wlevs:listener ref="filteredStream"/>
</wlevs:processor>

...
1.1.1.1.3 Querying a Channel

Once the event source, channel, and processor are connected as Figure 1-2 shows, you can write Oracle CQL statements that make use of the stream. Example 1-4 shows the component configuration file that defines the Oracle CQL statements for the filterFanoutProcessr.

Example 1-4 filterFanoutProcessor Oracle CQL Query Using priceStream

<processor>
    <name>filterFanoutProcessor</name>
    <rules>
        <query id="Yr3Sector"><![CDATA[ 
            select cusip, bid, srcId, bidQty, ask, askQty, seq 
            from priceStream where sector="3_YEAR"
        ]]></query>
        <query id="Yr2Sector"><![CDATA[ 
            select cusip, bid, srcId, bidQty, ask, askQty, seq 
            from priceStream where sector="2_YEAR"
        ]]></query>
        <query id="Yr1Sector"><![CDATA[ 
            select cusip, bid, srcId, bidQty, ask, askQty, seq 
            from priceStream where sector="1_YEAR"
        ]]></query>
    </rules>
</processor>
1.1.1.1.4 Controlling Which Queries Output to a Downstream Channel

If you specify more than one query for a processor as Example 1-4 shows, then all query results are output to the processor's out-bound channel (filteredStream in Figure 1-2).

Optionally, in the component configuration file, you can use the channel element selector attribute to control which query's results are output as Example 1-5 shows. In this example, query results for query Yr3Sector and Yr2Sector are output to filteredStream but not query results for query Yr1Sector. For more information, see "Channel Component Configuration" in the Oracle Fusion Middleware Developer's Guide for Oracle Complex Event Processing for Eclipse.

Example 1-5 Using channel Element selector Child Element to Control Which Query Results are Output to a Channel

<channel>
    <name>filteredStream</name>
    <selector>Yr3Sector Yr2Sector</selector>
</channel>

You may configure a channel element with a selector before creating the queries in the upstream processor. In this case, you must specify query names that match the names in the selector.

For more information, see "Controlling Which Queries Output to a Downstream Channel" in the Oracle Fusion Middleware Developer's Guide for Oracle Complex Event Processing for Eclipse.

1.1.1.2 Relations

Time varying relation R is a mapping from the time domain to an unbounded bag of tuples to the schema of R.

A relation is an unordered, time-varying bag of tuples: in other words, an instantaneous relation. At every instant of time, a relation is a bounded set. It can also be represented as a sequence of timestamped tuples that includes insertions, deletions, and updates to capture the changing state of the relation.

Like streams, relations have a fixed schema to which all tuples conform.

Oracle CEP supports both base and derived streams and relations. The external sources supply data to the base streams and relations.

A base (explicit) stream is a source data stream that arrives at an Oracle CEP adapter so that time is non-decreasing. That is, there could be events that carry same value of time.

A derived (implicit) stream/relation is an intermediate stream/relation that query operators produce. Note that these intermediate operators can be named (through views) and can therefore be specified in further queries.

A base relation is an input relation.

A derived relation is an intermediate relation that query operators produce. Note that these intermediate operators can be named (through views) and can therefore be specified in further queries.

In Oracle CEP, you do not create base relations yourself. The Oracle CEP server creates base relations for you as required.

When we say that a relation is a time-varying bag of tuples, time refers to an instant in the time domain. Input relations are presented to the system as a sequence of timestamped updates which capture how the relation changes over time. An update is either a tuple insertion or deletion. The updates are required to arrive at the system in the order of increasing timestamps.

For more information, see:

1.1.1.3 Relations and Oracle CEP Tuple Kind Indicator

By default, Oracle CEP includes time stamp and an Oracle CEP tuple kind indicator in the relations it generates as Example 1-6 shows.

Example 1-6 Oracle CEP Tuple Kind Indicator in Relation Output

Timestamp   Tuple Kind  Tuple
 1000:      +           ,abc,abc
 2000:      +           hihi,abchi,hiabc
 6000:      -           ,abc,abc
 7000:      -           hihi,abchi,hiabc
 8000:      +           hi1hi1,abchi1,hi1abc
 9000:      +           ,abc,abc
13000:      -           hi1hi1,abchi1,hi1abc
14000:      -           ,abc,abc
15000:      +           xyzxyz,abcxyz,xyzabc
20000:      -           xyzxyz,abcxyz,xyzabc

The Oracle CEP tuple kind indicators are:

1.1.2 Relation-to-Relation Operators

The relation-to-relation operators in Oracle CQL are derived from traditional relational queries expressed in SQL.

Anywhere a traditional relation is referenced in a SQL query, a relation can be referenced in Oracle CQL.

Consider the following examples for a stream CarSegStr with schema: car_id integer, speed integer, exp_way integer, lane integer, dir integer, and seg integer.

In Example 1-7, at any time instant, the output relation of this query contains the set of vehicles having transmitted a position-speed measurement within the last 30 seconds.

Example 1-7 Relation-to-Relation Operation

<processor>
    <name>cqlProcessor</name>
    <rules>
        <view id="CurCarSeg" schema="car_id exp_way lane dir seg"><![CDATA[ 
            select distinct
                car_id, exp_way, lane, dir, seg 
            from 
                CarSegStr [range 30 seconds]
        ]]></query>
    </rules>
</processor>

The distinct operator is the relation-to-relation operator. Using distinct, Oracle CEP returns only one copy of each set of duplicate tuples selected. Duplicate tuples are those with matching values for each expression in the select list. You can use distinct in a select_clause and with aggregate functions.

For more information on distinct, see:

1.1.3 Stream-to-Relation Operators (Windows)

Oracle CQL supports stream-to-relation operations based on a sliding window. In general, S[W] is a relation. At time T the relation contains all tuples in window W applied to stream S up to T.

window_type::=

Surrounding text describes window_type.png.

Oracle CQL supports the following built-in window types:

  • Range: time-based

    S[Range T], or, optionally,

    S[Range T1 Slide T2]

  • Range: time-based unbounded

    S[Range Unbounded]

  • Range: time-based now

    S[Now]

  • Range: constant value

    S[Range C on ID]

  • Tuple-based:

    S[Rows N], or, optionally,

    S[Rows N1 Slide N2]

  • Partitioned:

    S[Partition By A1 ... Ak Rows N] or, optionally,

    S[Partition By A1 ... Ak Rows N Range T], or

    S[Partition By A1 ... Ak Rows N Range T1 Slide T2]

This section describes the following stream-to-relation operator properties:

For more information, see:

1.1.3.1 Range, Rows, and Slide

The keywords Range and Rows specify how much data you want to query:

  • Range specifies as many tuples as arrive in a given time period

  • Rows specifies a number of tuples

The keyword Slide refers to how often you want a result.

In Figure 1-3, the Range specification indicates "I want to look at 5 seconds worth of data" and the Slide specification indicates "I want a result every 5 seconds". In this case, the query returns a result at the end of each Range specification (except for certain conditions, as "Range, Rows, and Slide at Query Start-Up and for Empty Relations" describes).

Figure 1-3 Range and Slide: Equal (Steady-State Condition)

Description of Figure 1-3 follows

In Figure 1-4, the Range specification indicates "I want to look at 10 seconds worth of data" and the Slide specification indicates "I want a result every 5 seconds". In this case, the query returns a result twice during each Range specification (except for certain conditions, as Section 1.1.3.1.1, "Range, Rows, and Slide at Query Start-Up and for Empty Relations" describes)

Figure 1-4 Range and Slide: Different (Steady-State Condition)

Description of Figure 1-4 follows

Table 1-1 lists the default Range, Range unit, and Slide (where applicable) for range-based and tuple-based stream-to-relation window operators:

Table 1-1 Default Range and Tuple-Based Stream-to-Relation Operators

Window OperatorDefault RangeDefault Range UnitDefault Slide

Range-Based Stream-to-Relation Window Operators


Unbounded

seconds

1 nanosecond

Tuple-Based Stream-to-Relation Window Operators


N/A

N/A

1 tuple


1.1.3.1.1 Range, Rows, and Slide at Query Start-Up and for Empty Relations

The descriptions for Figure 1-3 and Figure 1-4 assume a steady-state condition, after the query has been running for some time. Table 1-2 lists the behavior of Range, Rows, and Slide for special cases such as query start-up time and for an empty relation.

Table 1-2 Range, Rows, and Slide at Query Start-Up and Empty Relations

Operator or FunctionResult

COUNT(*) or COUNT(expression)

Immediately returns 0 for an empty relation (when there is no GROUP BY), before Range or Rows worth of data has accumulated and before the first Slide.

SUM(attribute) and other aggregate functions

Immediately returns null for an empty relation, before Range or Rows worth of data has accumulated and before the first Slide.


For more information and detailed examples, see:

1.1.3.2 Partition

The keyword Partition By logically separates an event stream S into different substreams based on the equality of the attributes given in the Partition By specification. For example, the S[Partition By A,C Rows 2] partition specification creates a sub-stream for every unique combination of A and C value pairs and the Rows specification is applied on these sub-streams. The Rows specification indicates "I want to look at 2 tuples worth of data".

For more information, see Section 1.1.3.1, "Range, Rows, and Slide".

1.1.3.3 Default Stream-to-Relation Operator

When you reference a stream in an Oracle CQL query where a relation is expected (most commonly in the from clause), a Range Unbounded window is applied to the stream by default. For example, the queries in Example 1-8 and Example 1-9 are identical:

Example 1-8 Query Without Stream-to-Relation Operator

<query id="q1"><![CDATA[ 
    select * from InputChannel
]]></query>

Example 1-9 Equivalent Query

<query id="q1"><![CDATA[ 
    IStream(select * from InputChannel[RANGE UNBOUNDED])
]]></query>

For more information, see Section 1.1.4, "Relation-to-Stream Operators".

1.1.4 Relation-to-Stream Operators

You can convert the result of a stream-to-relation operation back into a stream for further processing.

In Example 1-10, the select will output a stream of tuples satisfying the filter condition (viewq3.ACCT_INTRL_ID = ValidLoopCashForeignTxn.ACCT_INTRL_ID). The now window converts the viewq3 into a relation, which is kept as a relation by the filter condition. The IStream relation-to-stream operator converts the output of the filter back into a stream.

Example 1-10 Relation-to-Stream Operation

<processor>
    <name>cqlProcessor</name>
    <rules>
        <query id="q3Txns"><![CDATA[ 
            IStream(
                select 
                    TxnId, 
                    ValidLoopCashForeignTxn.ACCT_INTRL_ID, 
                    TRXN_BASE_AM, 
                    ADDR_CNTRY_CD, 
                    TRXN_LOC_ADDR_SEQ_ID 
                from 
                    viewq3[NOW], ValidLoopCashForeignTxn 
                where 
                    viewq3.ACCT_INTRL_ID = ValidLoopCashForeignTxn.ACCT_INTRL_ID
            )
        ]]></query>
    </rules>
</processor>

Oracle CQL supports the following relation-to-stream operators:

By default, Oracle CEP includes an operation indicator in the relations it generates so you can identify insertions, deletions, and, when using UPDATE SEMANTICS, updates. For more information, see Section 1.1.1.3, "Relations and Oracle CEP Tuple Kind Indicator".

1.1.4.1 Default Relation-to-Stream Operator

Whenever an Oracle CQL query produces a relation that is monotonic, Oracle CQL adds an IStream operator by default.

A relation R is monotonic if and only if R(t1) is a subset of R(t2) whenever t1 <= t2.

Oracle CQL use a conservative static monotonicity test. For example, a base relation is monotonic if it is known to be append-only: S[Range Unbounded] is monotonic for any stream S; and the join of two monotonic relations is also monotonic.

If a relation is not monotonic (for example, it has a window like S[range 10 seconds]), it is impossible to determine what the query author intends (IStream, DStream, or RStream), so Oracle CQL does not add a relation-to-stream operator by default in this case.

1.1.5 Stream-to-Stream Operators

Typically, you perform stream to stream operations using the following:

However, some relation-relation operators (like filter and project) can also act as stream-stream operators. Consider the query that Example 1-11 shows: assuming that the input S is a stream, the query will produce a stream as an output where stream element c1 is greater than 50.

Example 1-11 Stream-to-Stream Operation

<processor>
    <name>cqlProcessor</name>
    <rules>
        <query id="q0"><![CDATA[ 
            select * from S where c1 > 50
        ]]></query>
    </rules>
</processor>

This is a consequence of the application of the default stream-to-relation and relation-to-stream operators. The stream S in Example 1-11 gets a default [Range Unbounded] window added to it. Since this query then evaluates to a relation that is monotonic, an IStream gets added to it.

For more information, see:

In addition, Oracle CQL supports the following direct stream-to-stream operators:

1.1.6 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 retrieve data from one or more streams, relations, or views. A top-level SELECT statement that you create in a <query> element is called a query. 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. A top-level SELECT statement that you create in a <view> element is called a view. For more information, see Section 18.3, "Views".

Each query and view must have an identifier unique to the processor that contains it. Example 1-12 shows a query with an id of q0. The id value must conform with the specification given by identifier::=.

Example 1-12 Query and View id Attribute

<processor>
    <name>cqlProcessor</name>
    <rules>
        <query id="q0"><![CDATA[ 
            select * from S where c1 > 50
        ]]></query>
    </rules>
</processor>

A join is a query that combines rows from two or more streams, views, or relations. For more information, see Section 18.4, "Joins".

For more information, see Chapter 18, "Oracle CQL Queries, Views, and Joins".

1.1.7 Pattern Recognition

The Oracle CQL MATCH_RECOGNIZE construct is the principle means of performing pattern recognition.

A sequence of consecutive events or tuples in the input stream, each satisfying certain conditions constitutes a pattern. The pattern recognition functionality in Oracle CQL allows you to define conditions on the attributes of incoming events or tuples and to identify these conditions by using String names called correlation variables. The pattern to be matched is specified as a regular expression over these correlation variables and it determines the sequence or order in which conditions should be satisfied by different incoming tuples to be recognized as a valid match.

For more information, see Chapter 19, "Pattern Recognition With MATCH_RECOGNIZE".

1.1.8 Event Sources and Event Sinks

An Oracle CEP event source identifies a producer of data that your Oracle CQL queries operate on. An Oracle CQL event sink identifies a consumer of query results.

This section explains the types of event sources and sinks you can access in your Oracle CQL queries and how you connect event sources and event sinks.

1.1.8.1 Event Sources

An Oracle CEP event source identifies a producer of data that your Oracle CQL queries operate on.

In Oracle CEP, the following elements may be event sources:

  • adapter (JMS, HTTP, and file)

  • channel

  • processor

  • table

  • cache


Note:

In Oracle CEP, you must use a channel to connect an event source to an Oracle CQL processor and to connect an Oracle CQL processor to an event sink. A channel is optional with other Oracle CEP processor types. For more information, see Section 1.1.1, "Streams and Relations".


Oracle CEP event sources are typically push data sources: that is, Oracle CEP expects the event source to notify it when the event source has data ready.

Oracle CEP relational database table and cache event sources are pull data sources: that is, Oracle CEP polls the event source on arrival of an event on the data stream.

For more information, see:

1.1.8.2 Event Sinks

An Oracle CQL event sink connected to a CQL processor is a consumer of query results.

In Oracle CEP, the following elements may be event sinks:

  • adapter (JMS, HTTP, and file)

  • channel

  • processor

  • cache

You can associate the same query with more than one event sink and with different types of event sink.

1.1.8.3 Connecting Event Sources and Event Sinks

In Oracle CEP, you define event sources and event sinks using Oracle CEP IDE for Eclipse to create the Event Processing Network (EPN) as Figure 1-5 shows. In this EPN, adapter PriceAdapter is the event source for channel priceStream; channel priceStream is the event source for Oracle CQL processor filterFanoutProcessor. Similarly, Oracle CQL processor filterFanoutProcessor is the event sink for channel priceStream.

Figure 1-5 Event Sources and Event Sinks in the Event Processing Network

Description of Figure 1-5 follows

For more information, see:

1.1.9 Table Event Sources

Using Oracle CQL, you can access tabular data, including:

For more information, see Section 1.1.8, "Event Sources and Event Sinks"

1.1.9.1 Relational Database Table Event Sources

Using an Oracle CQL processor, you can specify a relational database table as an event source. You can query this event source, join it with other event sources, and so on.

For more information, see Section 18.6, "Oracle CQL Queries and Relational Database Tables".

1.1.9.2 XML Table Event Sources

Using the Oracle CQL XMLTABLE clause, you can parse data from an xmltype stream into columns using XPath expressions and conveniently access the data by column name.

For more information, see Section 18.2.6, "XMLTable Query".

1.1.9.3 Function Table Event Sources

Use the TABLE clause to access, as a relation, the multiple rows returned by a built-in or user-defined function, as an array or Collection type, in the FROM clause of an Oracle CQL query.

For more information, see:

1.1.10 Cache Event Sources

Using an Oracle CQL processor, you can specify an Oracle CEP cache as an event source. You can query this event source and join it with other event sources using a now window only.

For more information, see:

1.1.11 Functions

Functions are similar to operators in that they manipulate data items and return a result. Functions differ from operators in the format of their arguments. This format enables them to operate on zero, one, two, or more arguments:

function(argument, argument, ...) 

A function without any arguments is similar to a pseudocolumn (refer to Chapter 3, "Pseudocolumns"). However, a pseudocolumn typically returns a different value for each tuple in a relation, whereas a function without any arguments typically returns the same value for each tuple.

Oracle CQL provides a wide variety of built-in functions to perform operations on stream data, including:

  • single-row functions that return a single result row for every row of a queried stream or view

  • aggregate functions that return a single aggregate result based on group of tuples, rather than on a single tuple

  • single-row statistical and advanced arithmetic operations based on the Colt open source libraries for high performance scientific and technical computing.

  • aggregate statistical and advanced arithmetic operations based on the Colt open source libraries for high performance scientific and technical computing.

  • statistical and advanced arithmetic operations based on the java.lang.Math class

If Oracle CQL built-in functions do not provide the capabilities your application requires, you can easily create user-defined functions in Java by using the classes in the oracle.cep.extensibility.functions package. You can create aggregate and single-row user-defined functions. You can create overloaded functions and you can override built-in functions.

If you call an Oracle CQL function with an argument of a datatype other than the datatype expected by the Oracle CQL function, then Oracle CEP attempts to convert the argument to the expected datatype before performing the Oracle CQL function.


Note:

Function names are case sensitive:

  • Built-in functions: lower case.

  • User-defined functions: welvs:function element function-name attribute determines the case you use.


For more information, see:

1.1.12 Data Cartridges

The Oracle CQL data cartridge framework allows you to tightly integrate arbitrary domain objects with the Oracle CQL language and use domain object fields, methods, and constructors within Oracle CQL queries in the same way you use Oracle CQL native types.

Currently, Oracle CEP provides the following data cartridges:

  • Oracle Java data cartridge: this data cartridge exposes Java types, methods, fields, and constructors that you can use in Oracle CQL queries and views as you would Oracle CQL native types.

    See Chapter 15, "Oracle Java Data Cartridge".

  • Oracle Spatial: this data cartridge exposes Oracle Spatial types, methods, fields, and constructors that you can use in Oracle CQL queries and views as you would Oracle CQL native types.

    See Chapter 16, "Oracle Spatial".

  • Oracle JDBC data cartridge: this data cartridge allows you to incorporate arbitrary SQL functions against multiple tables and data sources in Oracle CQL queries and views as you would Oracle CQL native types.

    See Chapter 17, "Oracle CEP JDBC Data Cartridge".

For more information, see:

1.1.13 Time

Timestamps are an integral part of an Oracle CEP stream. However, timestamps do not necessarily equate to clock time. For example, time may be defined in the application domain where it is represented by a sequence number. Timestamp^Ls need only guarantee that updates arrive at the system in the order of increasing timestamp values.

Note that the timestamp ordering requirement is specific to one stream or a relation. For example, tuples of different streams could be arbitrarily interleaved.

Oracle CEP can observe application time or system time.

To configure application timestamp or system timestamp operation, see child element application-timestamped in "wlevs:channel" in the Oracle Fusion Middleware Developer's Guide for Oracle Complex Event Processing for Eclipse.

For system timestamped relations or streams, time is dependent upon the arrival of data on the relation or stream data source. Oracle CEP generates a heartbeat on a system timestamped relation or stream if there is no activity (no data arriving on the stream or relation's source) for more than a specified time: for example, 1 minute. Either the relation or stream is populated by its specified source or Oracle CEP generates a heartbeat every minute. This way, the relation or stream can never be more than 1 minute behind.

To configure a heartbeat, see "heartbeat" in the Oracle Fusion Middleware Developer's Guide for Oracle Complex Event Processing for Eclipse.

For system timestamped streams and relations, the system assigns time in such a way that no two events will have the same value of time. However, for application timestamped streams and relations, events could have same value of time.

If you know that the application timestamp will be strictly increasing (as opposed to non-decreasing) you may set wlevs:channel attribute is-total-order to true. This enables the Oracle CEP engine to do certain optimizations and typically leads to reduction in processing latency.

To configure is-total-order, see "wlevs:application-timestamped" in the Oracle Fusion Middleware Developer's Guide for Oracle Complex Event Processing for Eclipse.

The Oracle CEP scheduler is responsible for continuously executing each Oracle CQL query according to its scheduling algorithm and frequency.

For more information on the scheduler, see "scheduler" in the Oracle Fusion Middleware Developer's Guide for Oracle Complex Event Processing for Eclipse.

1.2 Oracle CQL Statements

Oracle CQL provides statements for creating queries and views.

This section describes:

For more information, see:

1.2.1 Lexical Conventions

Using Oracle CEP IDE for Eclipse or Oracle CEP Visualizer, you write Oracle CQL statements in the XML configuration file associated with an Oracle CEP CQL processor. This XML file is called the configuration source.

The configuration source must conform with the wlevs_application_config.xsd schema and may contain only rule, view, or query elements as Example 1-13 shows.

Example 1-13 Typical Oracle CQL Processor Configuration Source File

<?xml version="1.0" encoding="UTF-8"?>
<n1:config xsi:schemaLocation="http://www.bea.com/ns/wlevs/config/application wlevs_application_config.xsd" 
    xmlns:n1="http://www.bea.com/ns/wlevs/config/application" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<processor>
    <name>cqlProcessor</name>
    <rules>
        <view id="lastEvents" schema="cusip bid srcId bidQty ask askQty seq"><![CDATA[ 
            select cusip, bid, srcId, bidQty, ask, askQty, seq 
            from inputChannel[partition by srcId, cusip rows 1]
        ]]></view>
        <view id="bidask" schema="cusip bid ask"><![CDATA[ 
            select cusip, max(bid), min(ask) 
            from lastEvents
            group by cusip
        ]]></view>
            <view ...><![CDATA[
                ...
        ]]></view>
        ...
        <view id="MAXBIDMINASK" schema="cusip bidseq bidSrcId bid askseq askSrcId ask bidQty askQty"><![CDATA[ 
            select bid.cusip, bid.seq, bid.srcId as bidSrcId, bid.bid, ask.seq, ask.srcId as askSrcId, ask.ask, bid.bidQty, ask.askQty 
            from BIDMAX as bid, ASKMIN as ask 
            where bid.cusip = ask.cusip
        ]]></view>
        <query id="BBAQuery"><![CDATA[ 
            ISTREAM(select bba.cusip, bba.bidseq, bba.bidSrcId, bba.bid, bba.askseq, 
                bba.askSrcId, bba.ask, bba.bidQty, bba.askQty, "BBAStrategy" as intermediateStrategy, 
                p.seq as correlationId, 1 as priority 
            from MAXBIDMINASK as bba, inputChannel[rows 1] as p where bba.cusip = p.cusip)
        ]]></query>
    </rules>
</processor>

When writing Oracle CQL queries in an Oracle CQL processor component configuration file, observe the following rules:

  • You may specify one Oracle CQL statement per view or query element.

  • You must not terminate Oracle CQL statements with a semicolon (;).

  • You must enclose each Oracle CQL statement in <![CDATA[ and ]]> as Example 1-13 shows.

  • When you issue an Oracle CQL statement, you can include one or more tabs, carriage returns, or spaces anywhere a space occurs within the definition of the statement. Thus, Oracle CEP evaluates the Oracle CQL statement in Example 1-14 and Example 1-15 in the same manner.

    Example 1-14 Oracle CQL: Without Whitespace Formatting

    <processor>
        <name>cqlProcessor</name>
        <rules>
            <query id="QTollStr"><![CDATA[ 
                RSTREAM(select cars.car_id, SegToll.toll from CarSegEntryStr[now] as cars, SegToll 
                    where (cars.exp_way = SegToll.exp_way and cars.lane = SegToll.lane 
                        and cars.dir = SegToll.dir and cars.seg = SegToll.seg))
            ]]></query>
        </rules>
    </processor>
    

    Example 1-15 Oracle CQL: With Whitespace Formatting

    <processor>
        <name>cqlProcessor</name>
        <rules>
            <query id="QTollStr"><![CDATA[ 
                RSTREAM(
                    select
                        cars.car_id, 
                        SegToll.toll 
                    from 
                        CarSegEntryStr[now]
                    as
                        cars, SegToll 
                    where (
                        cars.exp_way = SegToll.exp_way and 
                        cars.lane = SegToll.lane and 
                        cars.dir = SegToll.dir and 
                        cars.seg = SegToll.seg
                    )
                )
            ]]></query>
        </rules>
    </processor>
    
  • Case is insignificant in reserved words, keywords, identifiers and parameters. However, case is significant in function names, text literals, and quoted names.

    For more information, see:

  • Comments are not permitted in Oracle CQL statements. For more information, see Section 2.6, "Comments".


Note:

Throughout the Oracle Fusion Middleware CQL Language Reference for Oracle Complex Event Processing, Oracle CQL statements are shown only with their view or query element for clarity.


1.2.2 Syntactic Shortcuts and Defaults

When writing Oracle CQL queries, views, and joins, consider the syntactic shortcuts and defaults that Oracle CQL provides to simplify your queries.

For more information, see:

1.2.3 Documentation Conventions

All Oracle CQL statements in this reference (see Chapter 20, "Oracle CQL Statements") are organized into the following sections:

Syntax The syntax diagrams show the keywords and parameters that make up the statement.


Caution:

Not all keywords and parameters are valid in all circumstances. Be sure to refer to the "Semantics" section of each statement and clause to learn about any restrictions on the syntax.


Purpose The "Purpose" section describes the basic uses of the statement.

Prerequisites The "Prerequisites" section lists privileges you must have and steps that you must take before using the statement.

Semantics The "Semantics" section describes the purpose of the keywords, parameter, and clauses that make up the syntax, and restrictions and other usage notes that may apply to them. (The conventions for keywords and parameters used in this chapter are explained in the Preface of this reference.)

Examples The "Examples" section shows how to use the various clauses and parameters of the statement.

1.3 Oracle CQL and SQL Standards

Oracle CQL is a new technology but it is based on a subset of SQL99.

Oracle strives to comply with industry-accepted standards and participates actively in SQL standards committees. Oracle is actively pursuing Oracle CQL standardization.

1.4 Oracle CEP Server and Tools Support

Using the Oracle CEP server and tools, you can efficiently create, package, deploy, debug, and manage Oracle CEP applications that use Oracle CQL.

1.4.1 Oracle CEP Server

Oracle CEP server provides the light-weight Spring container for Oracle CEP applications and manages server and application lifecycle, provides a JRockit real-time JVM with deterministic garbage collection, and a wide variety of essential services such as security, Jetty, JMX, JDBC, HTTP publish-subscribe, and logging and debugging.

For more information on Oracle CEP server, see Oracle Fusion Middleware Administrator's Guide for Oracle Complex Event Processing.

1.4.2 Oracle CEP Tools

Oracle CEP provides the following tools to facilitate your Oracle CQL development process:

1.4.2.1 Oracle CEP IDE for Eclipse

Oracle CEP IDE for Eclipse is targeted specifically to programmers that want to develop Oracle CEP applications as Figure 1-6 shows.

Figure 1-6 Oracle CEP IDE for Eclipse

Description of Figure 1-6 follows

The Oracle CEP IDE for Eclipse is a set of plugins for the Eclipse IDE designed to help develop, deploy, and debug Oracle CEP applications.

The key features of Oracle CEP IDE for Eclipse are:

  • Project creation wizards and templates to quickly get started building event driven applications.

  • Advanced editors for source files including Java and XML files common to Oracle CEP applications.

  • Integrated server management to seamlessly start, stop, and deploy to Oracle CEP server instances all from within the IDE.

  • Integrated debugging.

  • Event Processing Network (EPN) visual design views for orienting and navigating in event processing applications.

  • Integrated support for the Oracle CEP Visualizer so you can use the Oracle CEP Visualizer from within the IDE (see Section 1.4.2.2, "Oracle CEP Visualizer").

For details, see:

1.4.2.2 Oracle CEP Visualizer

Oracle provides an advanced run-time administration console called the Oracle CEP Visualizer as Figure 1-7 shows.

Figure 1-7 Oracle CEP Visualizer

Description of Figure 1-7 follows

Using Oracle CEP Visualizer, you can manage, tune, and monitor Oracle CEP server domains and the Oracle CEP applications you deploy to them all from a browser. Oracle CEP Visualizer provides a variety of sophisticated run-time administration tools, including support for Oracle CQL and EPL rule maintenance and creation.

For details, see Oracle Fusion Middleware Visualizer User's Guide for Oracle Complex Event Processing

PKmL^LPKO_\EOEBPS/cqlstatements.htm Oracle CQL Statements

20 Oracle CQL Statements

This chapter describes data definition language (DDL) statements in Oracle Continuous Query Language (Oracle CQL).

20.1 Introduction to Oracle CQL Statements

Oracle CQL supports the following DDL statements:


Note:

In stream input examples, lines beginning with h (such as h 3800) are heartbeat input tuples. These inform Oracle CEP that no further input will have a timestamp lesser than the heartbeat value.


For more information, see:


Query

Purpose

Use the query statement to define a Oracle CQL query that you reference by identifier in subsequent Oracle CQL statements.

Prerequisites

If your query references a stream or view, then the stream or view must already exist.

If the query already exists, Oracle CEP server throws an exception.

For more information, see:

Syntax

You express a query in a <query></query> element as Example 20-1 shows.

The query element has one attribute:

  • id: Specify the identifier as the query element id attribute.

    The id value must conform with the specification given by identifier::=.

Example 20-1 Query in a <query></query> Element

<query id="q0"><![CDATA[ 
    select * from OrderStream where orderAmount > 10000.0 
]]></query>

query::=

Surrounding text describes query.png.

(sfw_block::=, idstream_clause::=, binary::=, using_clause::=)

sfw_block::=

Surrounding text describes sfw_block.png.

(select_clause::=, from_clause::=, opt_where_clause::=, opt_group_by_clause::=, order_by_clause::=, order_by_top_clause::=, opt_having_clause::=)

select_clause::=

Surrounding text describes select_clause.png.

(non_mt_projterm_list::=)

non_mt_projterm_list::=

Surrounding text describes non_mt_projterm_list.png.

(projterm::=)

projterm::=

Surrounding text describes projterm.png.

(arith_expr, identifier::=)

from_clause::=

Surrounding text describes from_clause.png.

(non_mt_relation_list::=, relation_variable::=, non_mt_cond_list::=)

non_mt_relation_list::=

Surrounding text describes non_mt_relation_list.png.

(relation_variable::=)

relation_variable::=

Surrounding text describes relation_variable.png.

(identifier::=, window_type::=, pattern_recognition_clause::=, xmltable_clause::=, object_expr::=, datatype::=, table_clause::=)

window_type::=

Surrounding text describes window_type.png.

(identifier::=, non_mt_attr_list::=, time_spec::=)

table_clause::=

Surrounding text describes table_clause.png.

(object_expr::=, identifier::=, datatype::=)

opt_where_clause::=

Surrounding text describes opt_where_clause.png.

(non_mt_cond_list::=)

opt_group_by_clause::=

Surrounding text describes opt_group_by_clause.png.

(non_mt_attr_list::=)

order_by_clause::=

Surrounding text describes order_by_clause.png.

(order_by_list::=)

order_by_top_clause::=

Surrounding text describes order_by_top_clause.png.

(pattern_partition_clause::=, order_by_list::=)

order_by_list::=

Surrounding text describes order_by_list.png.

(orderterm::=)

orderterm::=

Surrounding text describes orderterm.png.

(order_expr::=, null_spec::=, asc_desc::=)

null_spec::=

Surrounding text describes null_spec.png.

asc_desc::=

Surrounding text describes asc_desc.png.

opt_having_clause::=

Surrounding text describes opt_having_clause.png.

(non_mt_cond_list::=)

binary::=

Surrounding text describes binary.png.

idstream_clause::=

Surrounding text describes idstream_clause.png.

using_clause::=

Surrounding text describes using_clause.png.

(usinglist::=)

usinglist::=

Surrounding text describes usinglist.png.

(usingterm::=)

usingterm::=

Surrounding text describes usingterm.png.

(usingexpr::=)

usingexpr::=

Surrounding text describes usingexpr.png.

(attr::=, const_int::=)

xmltable_clause::=

Surrounding text describes xmltable_clause.png.

(xmlnamespace_clause::=, const_string::=, xqryargs_list::=, xtbl_cols_list::=)

xmlnamespace_clause::=

Surrounding text describes xmlnamespace_clause.png.

(xmlnamespaces_list::=)

xmlnamespaces_list::=

Surrounding text describes xmlnamespaces_list.png.

(xml_namespace::=)

xml_namespace::=

Surrounding text describes xml_namespace.png.

(const_string::=)

xtbl_cols_list::=

Surrounding text describes xtbl_cols_list.png.

(xtbl_col::=)

xtbl_col::=

Surrounding text describes xtbl_col.png.

Semantics

named_query

Specify the Oracle CQL query statement itself (see "query").

For syntax, see "Query".

query

You can create an Oracle CQL query from any of the following clauses:

  • sfw_block: a select, from, and other optional clauses (see "sfw_block").

  • binary: an optional set operation clause (see "binary").

  • xstream_clause: apply an optional relation-to-stream operator to your sfw_block or binary clause to control how the query returns its results (see "idstream_clause").

For syntax, see query::=.

sfw_block

Specify the select, from, and other optional clauses of the Oracle CQL query. You can specify any of the following clauses:

  • select_clause: the stream elements to select from the stream or view you specify (see "select_clause").

  • from_clause: the stream or view from which your query selects (see "from_clause").

  • opt_where_clause: optional conditions your query applies to its selection (see "opt_where_clause")

  • opt_group_by_clause: optional grouping conditions your query applies to its results (see "opt_group_by_clause")

  • order_by_clause: optional ordering conditions your query applies to its results (see "order_by_clause")

  • order_by_top_clause: optional ordering conditions your query applies to the top-n elements in its results (see "order_by_top_clause")

  • opt_having_clause: optional clause your query uses to restrict the groups of returned stream elements to those groups for which the specified condition is TRUE (see "opt_having_clause")

For syntax, see sfw_block::= (parent: query::=).

select_clause

Specify the select clause of the Oracle CQL query statement.

If you specify the asterisk (*), then this clause returns all tuples, including duplicates and nulls.

Otherwise, specify the individual stream elements you want (see "non_mt_projterm_list").

Optionally, specify distinct if you want Oracle CEP to return only one copy of each set of duplicate tuples selected. Duplicate tuples are those with matching values for each expression in the select list. For an example, see "Select and Distinct Examples".

For syntax, see select_clause::= (parent: sfw_block::=).

non_mt_projterm_list

Specify the projection term ("projterm") or comma separated list of projection terms in the select clause of the Oracle CQL query statement.

For syntax, see non_mt_projterm_list::= (parent: select_clause::=).

projterm

Specify a projection term in the select clause of the Oracle CQL query statement. You can select any element from any of stream or view in the from_clause (see "from_clause") using the identifier of the element.

Optionally, you can specify an arithmetic expression on the projection term.

Optionally, use the AS keyword to specify an alias for the projection term instead of using the stream element name as is.

For syntax, see projterm::= (parent: non_mt_projterm_list::=).

from_clause

Specify the from clause of the Oracle CQL query statement by specifying the individual streams or views from which your query selects (see "non_mt_relation_list").

To perform an outer join, use the LEFT or RIGHT OUTER JOIN ... ON syntax. To perform an inner join, use the WHERE clause.

For more information, see:

For syntax, see from_clause::= (parent: sfw_block::=).

non_mt_relation_list

Specify the stream or view ("relation_variable") or comma separated list of streams or views in the from clause of the Oracle CQL query statement.

For syntax, see non_mt_relation_list::= (parent: from_clause::=).

relation_variable

Use the relation_variable statement to specify a stream or view from which the Oracle CQL query statement selects.

You can specify a previously registered or created stream or view directly by its identifier you used when you registered or created the stream or view. Optionally, use the AS keyword to specify an alias for the stream or view instead of using its name as is.

To specify a built-in stream-to-relation operator, use a window_type clause (see "window_type"). Optionally, use the AS keyword to specify an alias for the stream or view instead of using its name as is.

To apply advanced comparisons optimized for data streams to the stream or view, use a pattern_recognition_clause (see "pattern_recognition_clause"). Optionally, use the AS keyword to specify an alias for the stream or view instead of using its name as is.

To process xmltype stream elements using XPath and XQuery, use an xmltable_clause (see "xmltable_clause"). Optionally, use the AS keyword to specify an alias for the stream or view instead of using its name as is.

To access, as a relation, the multiple rows returned by a data cartridge function in the FROM clause of an Oracle CQL query, use a table_clause (see "table_clause").

For more information, see:

For syntax, see relation_variable::= (parent: non_mt_relation_list::=).

window_type

Specify a built-in stream-to-relation operator.

For more information, see Section 1.1.3, "Stream-to-Relation Operators (Windows)".

For syntax, see window_type::= (parent: relation_variable::=).

table_clause

Use the data cartridge TABLE clause to access the multiple rows returned by a data cartridge function in the FROM clause of an Oracle CQL query.

The TABLE clause converts the set of returned rows into an Oracle CQL relation. Because this is an external relation, you must join the TABLE function clause with a stream. Oracle CEP invokes the data cartridge method only on the arrival of elements on the joined stream.

Use the optional OF keyword to specify the type contained by the returned array type or Collection type.

Use the AS keyword to specify an alias for the object_expr and for the returned relation.

Note the following:

  • The data cartridge method must return an array type or Collection type.

  • You must join the TABLE function clause with a stream.

For examples, see:

For more information, see:

For syntax, see table_clause::= (parent: relation_variable::=).

time_spec

Specify the time over which a range or partitioned range sliding window should slide.

Default: if units are not specified, Oracle CEP assumes [second|seconds].

For more information, see "Range-Based Stream-to-Relation Window Operators" and "Partitioned Stream-to-Relation Window Operators".

For syntax, see time_spec::= (parent: window_type::=).

opt_where_clause

Specify the (optional) where clause of the Oracle CQL query statement.

Because Oracle CQL applies the WHERE clause before GROUP BY or HAVING, if you specify an aggregate function in the SELECT clause, you must test the aggregate function result in a HAVING clause, not the WHERE clause.

In Oracle CQL (as in SQL), the FROM clause is evaluated before the WHERE clause. Consider the following Oracle CQL query:

SELECT ... FROM S MATCH_RECOGNIZE ( .... ) as T WHERE ...

In this query, the S MATCH_RECOGNIZE ( .... ) as T is like a subquery in the FROM clause and is evaluated first, before the WHERE clause. Consequently, you rarely use both a MATCH_RECOGNIZE clause and a WHERE clause in the same Oracle CQL query. Instead, you typically use views to apply the required WHERE clause to a stream and then select from the views in a query that applies the MATCH_RECOGNIZE clause.

For more information, see:

For syntax, see opt_where_clause::= (parent: sfw_block::=).

opt_group_by_clause

Specify the (optional) GROUP BY clause of the Oracle CQL query statement. Use the GROUP BY clause if you want Oracle CEP to group the selected stream elements based on the value of expr(s) and return a single (aggregate) summary result for each group.

Expressions in the GROUP BY clause can contain any stream elements or views in the FROM clause, regardless of whether the stream elements appear in the select list.

The GROUP BY clause groups stream elements but does not guarantee the order of the result set. To order the groupings, use the ORDER BY clause.

Because Oracle CQL applies the WHERE clause before GROUP BY or HAVING, if you specify an aggregate function in the SELECT clause, you must test the aggregate function result in a HAVING clause, not the WHERE clause.

For more information, see:

For syntax, see opt_group_by_clause::= (parent: sfw_block::=).

order_by_clause

Specify the ORDER BY clause of the Oracle CQL query statement as a comma-delimited list ("order_by_list") of one or more order terms (see "orderterm"). Use the ORDER BY clause to specify the order in which stream elements on the left-hand side of the rule are to be evaluated. The expr must resolve to a dimension or measure column.

For more information, see Section 18.2.9, "Sorting Query Results".

For syntax, see order_by_clause::= (parent: sfw_block::=).

order_by_top_clause

Specify the ORDER BY clause of the Oracle CQL query statement as a comma-delimited list ("order_by_list") of one or more order terms (see "orderterm") followed by a ROWS keyword and integer number (n) of elements. Use this form of the ORDER BY clause to select the top-n elements over a stream or relation. This clause always returns a relation.

Consider the following example queries:

  • At any point of time, the output of the following example query will be a relation having top 10 stock symbols throughout the stream.

    select stock_symbols from StockQuotes order by stock_price rows 10
    
  • At any point of time, the output of the following example query will be a relation having top 10 stock symbols from last 1 hour of data.

    select stock_symbols from StockQuotes[range 1 hour] order by stock_price rows 10
    

For more information, see

For syntax, see order_by_top_clause::= (parent: sfw_block::=).

order_by_list

Specify a comma-delimited list of one ore more order terms (see "orderterm") in an (optional) ORDER BY clause.

For syntax, see order_by_list::= (parent: order_by_clause::=).

orderterm

A stream element (attr::=) or positional index (constant int) to a stream element. Optionally, you can configure whether or not nulls are ordered first or last using the NULLS keyword (see "null_spec").

order_expr (order_expr::=) can be an attr or constant_int. The attr (attr::=) can be any stream element or pseudo column.

For syntax, see orderterm::= (parent: order_by_list::=).

null_spec

Specify whether or not nulls are ordered first (NULLS FIRST) or last (NULLS LAST) for a given order term (see "orderterm").

For syntax, see null_spec::= (parent: orderterm::=).

asc_desc

Specify whether an order term is ordered in ascending (ASC) or descending (DESC) order.

For syntax, see asc_desc::= (parent: orderterm::=).

opt_having_clause

Use the HAVING clause to restrict the groups of returned stream elements to those groups for which the specified condition is TRUE. If you omit this clause, then Oracle CEP returns summary results for all groups.

Specify GROUP BY and HAVING after the opt_where_clause. If you specify both GROUP BY and HAVING, then they can appear in either order.

Because Oracle CQL applies the WHERE clause before GROUP BY or HAVING, if you specify an aggregate function in the SELECT clause, you must test the aggregate function result in a HAVING clause, not the WHERE clause.

For more information, see:

For an example, see "HAVING Example".

For syntax, see opt_having_clause::= (parent: sfw_block::=).

binary

Use the binary clause to perform set operations on the tuples that two streams or views return.

For examples, see:

For syntax, see binary::= (parent: query::=).

idstream_clause

Use an idstream_clause to specify an IStream or DStream relation-to-stream operator that applies to the query.

For more information, see Section 1.1.4, "Relation-to-Stream Operators".

For syntax, see idstream_clause::= (parent: query::=).

using_clause

Use a DIFFERENCE USING clause to succinctly detect differences in the IStream or DStream of a query.

For more information, see Section 18.2.10, "Detecting Differences in Query Results".

For syntax, see using_clause::= (parent: query::=).

usinglist

Use a usinglist clause to specify the columns to use to detect differences in the IStream or DStream of a query. You may specify columns by:

  • attribute name: use this option when you are selecting by attribute name.

    Example 20-2 shows attribute name c1 in the DIFFERENCE USING clause usinglist.

  • alias: use this option when you want to include the results of an expression where an alias is specified.

    Example 20-2 shows alias logval in the DIFFERENCE USING clause usinglist.

  • position: use this option when you want to include the results of an expression where no alias is specified.

    Specify position as a constant, positive integer starting at 1, reading from left to right.

    Example 20-2 specifies the result of expression funct(c2, c3) by its position (3) in the DIFFERENCE USING clause usinglist.

Example 20-2 Specifying the usinglist in a DIFFERENCE USING Clause

<query id="q1">
    ISTREAM (
        SELECT c1, log(c4) as logval, funct(c2, c3) FROM S [RANGE 1 NANOSECONDS]
    )    DIFFERENCE USING (c1, logval, 3)
</query>

For more information, see Section 18.2.10, "Detecting Differences in Query Results".

For syntax, see usinglist::= (parent: using_clause::=).

xmltable_clause

Use an xmltable_clause to process xmltype stream elements using XPath and XQuery. You can specify a comma separated list (see xtbl_cols_list::=) of one or more XML table columns (see xtbl_col::=), with or without an XML namespace.

For examples, see:

For syntax, see xmltable_clause::= (parent: relation_variable::=).

pattern_recognition_clause

Use a pattern_recognition_clause to perform advanced comparisons optimized for data streams.

For more information and examples, see Chapter 19, "Pattern Recognition With MATCH_RECOGNIZE".

For syntax, see pattern_recognition_clause::= (parent: relation_variable::=).

Examples

The following examples illustrate the various semantics that this statement supports:

For more examples, see Chapter 18, "Oracle CQL Queries, Views, and Joins".

Simple Query Example

Example 20-3 shows how to register a simple query q0 that selects all (*) tuples from stream OrderStream where stream element orderAmount is greater than 10000.

Example 20-3 REGISTER QUERY

<query id="q0"><![CDATA[ 
    select * from OrderStream where orderAmount > 10000.0 
]]></query>

HAVING Example

Consider the query q4 in Example 20-4 and the data stream S2 in Example 20-5. Stream S2 has schema (c1 integer, c2 integer). The query returns the relation in Example 20-6.

Example 20-4 HAVING Query

<query id="q4"><![CDATA[ 
    select 
        c1,
        sum(c1) 
    from 
        S2[range 10] 
    group by 
        c1 
    having 
        c1 > 0 and sum(c1) > 1
]]></query>

Example 20-5 HAVING Stream Input

Timestamp   Tuple
1000        ,2
2000        ,4
3000        1,4
5000        1,
6000        1,6
7000        ,9
8000        ,

Example 20-6 HAVING Relation Output

Timestamp   Tuple Kind  Tuple
5000:       +           1,2
6000:       -           1,2
6000:       +           1,3

BINARY Example: UNION and UNION ALL

Given the relations R1 and R2 in Example 20-8 and Example 20-9, respectively, the UNION query q1 in Example 20-7 returns the relation in Example 20-10 and the UNION ALL query q2 in Example 20-7 returns the relation in Example 20-11.

Example 20-7 Set Operators: UNION Query

<query id="q1"><![CDATA[ 
    R1 UNION R2 
]]></query>
<query id="q2"><![CDATA[ 
    R1 UNION ALL R2 
]]></query>

Example 20-8 Set Operators: UNION Relation Input R1

Timestamp   Tuple Kind  Tuple
   200000:  +           20,0.2
   201000:  -           20,0.2
   400000:  +           30,0.3
   401000:  -           30,0.3
100000000:  +           40,4.04
100001000:  -           40,4.04

Example 20-9 Set Operators: UNION Relation Input R2

Timestamp   Tuple Kind  Tuple
     1002:  +           15,0.14
     2002:  -           15,0.14
   200000:  +           20,0.2
   201000:  -           20,0.2
   400000:  +           30,0.3
   401000:  -           30,0.3
100000000:  +           40,4.04
100001000:  -           40,4.04

Example 20-10 Set Operators: UNION Relation Output

Timestamp   Tuple Kind  Tuple
     1002:  +           15,0.14
     2002:  -           15,0.14
   200000:  +           20,0.2
   201000:  -           20,0.2
   400000:  +           30,0.3
   401000:  -           30,0.3
100000000:  +           40,4.04
100001000:  -           40,4.04

Example 20-11 Set Operators: UNION ALL Relation Output

Timestamp   Tuple Kind  Tuple
     1002:  +           15,0.14
     2002:  -           15,0.14
   200000:  +           20,0.2
   200000:  +           20,0.2
    20100:  -           20,0.2
   201000:  -           20,0.2
   400000:  +           30,0.3
   400000:  +           30,0.3
   401000:  -           30,0.3
   401000:  -           30,0.3
100000000:  +           40,4.04
100000000:  +           40,4.04
 10001000:  -           40,4.04
100001000:  -           40,4.04

BINARY Example: INTERSECT

Given the relations R1 and R2 in Example 20-13 and Example 20-14, respectively, the INTERSECT query q1 in Example 20-12 returns the relation in Example 20-15.

Example 20-12 Set Operators: INTERSECT Query

<query id="q1"><![CDATA[ 
    R1 INTERSECT R2 
]]></query>

Example 20-13 Set Operators: INTERSECT Relation Input R1

Timestamp   Tuple Kind  Tuple
1000:        +          10,30
1000:        +          10,40
2000:        +          11,20
3000:        -          10,30
3000:        -          10,40

Example 20-14 Set Operators: INTERSECT Relation Input R2

Timestamp   Tuple Kind  Tuple
1000:       +           10,40
2000:       +           10,30
2000:       -           10,40
3000:       -           10,30

Example 20-15 Set Operators: INTERSECT Relation Output

Timestamp   Tuple Kind  Tuple
1000:       +           10,30
1000:       +           10,40
1000:       -           10,30
1000:       -           10,40
1000:       +           10,40
2000:       +           11,20
2000:       -           11,20
2000:       +           10,30
2000:       -           10,40
3000:       -           10,30

BINARY Example: MINUS

Given the relations R1 and R2 in Example 20-17 and Example 20-18, respectively, the MINUS query q1 in Example 20-16 returns the relation in Example 20-19.

Example 20-16 Set Operators: MINUS Query

<query id="q1BBAQuery"><![CDATA[ 
    R1 MINUS R2 
]]></query>

Example 20-17 Set Operators: MINUS Relation Input R1

Timestamp   Tuple Kind  Tuple
1500:       +           10,40
2000:       +           10,30
2000:       -           10,40
3000:       -           10,30

Example 20-18 Set Operators: MINUS Relation Input R2

Timestamp   Tuple Kind  Tuple
1000:       +           11,20
2000:       +           10,40
3000:       -           10,30

Example 20-19 Set Operators: MINUS Relation Output

Timestamp   Tuple Kind  Tuple
1000:       +           10,40.0
2000:       -           10,40.0

BINARY Example: IN and NOT IN

In this usage, the query will be a binary query.

in_condition_set::=

Surrounding text describes in_condition_set.png.

Note:

You cannot combine this usage with in_condition_membership as Section 6.8.2, "Using IN and NOT IN as a Membership Condition" describes.


Consider the views V3 and V4 and the query Q1 in Example 20-20 and the data streams S3 in Example 20-21 (with schema (c1 ineNteger, c2 integer)) and S4 in Example 20-22 (with schema (c1 integer, c2 integer)). In this condition test, the numbers and data types of attributes in left relation should be same as number and types of attributes of the right relation. Example 20-23 shows the relation that the query returns.

Example 20-20 IN and NOT IN as a Set Operation: Query

<view id="V3" schema="c1 c2"><![CDATA[ 
    select * from S3[range 2] 
]]></query>
<view id="V4" schema="c1 d1"><![CDATA[ 
    select * from S4[range 1]
]]></query>
<query id="Q1"><![CDATA[ 
     v3 not in v4
]]></query>

Example 20-21 IN and NOT IN as a Set Operation: Stream S3 Input

Timestamp   Tuple
1000        10, 30
1000        10, 40
2000        11, 20
3000        12, 40
3000        12, 30
3000        15, 50
h 2000000

Example 20-22 IN and NOT IN as a Set Operation: Stream S4 Input

Timestamp   Tuple
1000        10, 40
2000        10, 30
2000        12, 40
h 2000000

Example 20-23 IN and NOT IN as a Set Operation: Relation Output

Timestamp   Tuple Kind  Tuple
1000:       +           10,30
1000:       +           10,40
1000:       -           10,30
1000:       -           10,40
2000:       +           11,20
2000:       +           10,30
2000:       +           10,40
2000:       -           10,30
2000:       -           10,40
3000:       +           15,50
3000:       +           12,40
3000:       +           12,30
4000:       -           11,20
5000:       -           12,40
5000:       -           12,30
5000:       -           15,50

Select and Distinct Examples

Consider the query q1 in Example 20-24. Given the data stream S in Example 20-25, the query returns the relation in Example 20-26.

Example 20-24 Select DISTINCT Query

<query id="q1"><![CDATA[ 
    SELECT DISTINCT FROM S WHERE c1 > 10 
]]></query>

Example 20-25 Select DISTINCT Stream Input

Timestamp   Tuple
 1000       23
 2000       14
 3000       13
 5000       22
 6000       11
 7000       10
 8000        9
10000        8
11000        7
12000       13
13000       14

Example 20-26 Select DISTINCT Stream Output

Timestamp   Tuple
1000        23
2000        14
3000        13
5000        22
6000        11

XMLTABLE Query Example

Consider the query q1 in Example 20-27 and the data stream S in Example 20-28. Stream S has schema (c1 xmltype). The query returns the relation in Example 20-29. For more information, see Section 18.2.6, "XMLTable Query".

Example 20-27 XMLTABLE Query

<query id="q1"><![CDATA[ 
    SELECT
        X.Name, 
        X.Quantity 
    from 
        S1 
    XMLTable (
        "//item" PASSING BY VALUE S1.c2 as "." 
        COLUMNS 
            Name CHAR(16) PATH "/item/productName", 
            Quantity INTEGER PATH "/item/quantity"
    ) AS X
]]></query>

Example 20-28 XMLTABLE Stream Input

Timestamp   Tuple
3000        "<purchaseOrder><shipTo><name>Alice Smith</name><street>123 Maple Street</street><city>Mill Valley</city><state>CA</state><zip>90952</zip> </shipTo><billTo><name>Robert Smith</name><street>8 Oak Avenue</street><city>Old Town</city><state>PA</state> <zip>95819</zip> </billTo><comment>Hurry, my lawn is going wild!</comment><items> <item><productName>Lawnmower </productName><quantity>1</quantity><USPrice>148.95</USPrice><comment>Confirm this is electric</comment></item><item> <productName>Baby Monitor</productName><quantity>1</quantity> <USPrice>39.98</USPrice> <shipDate>1999-05-21</shipDate></item></items> </purchaseOrder>"
4000        "<a>hello</a>"

Example 20-29 XMLTABLE Relation Output

Timestamp   Tuple Kind  Tuple
3000:       +           <productName>Lawnmower</productName>,<quantity>1</quantity>
3000:       +           <productName>Baby Monitor</productName>,<quantity>1</quantity>

XMLTABLE With XML Namespaces Query Example

Consider the query q1 in Example 20-30 and the data stream S1 in Example 20-31. Stream S1 has schema (c1 xmltype). The query returns the relation in Example 20-32. For more information, see Section 18.2.6, "XMLTable Query".

Example 20-30 XMLTABLE With XML Namespaces Query

<query id="q1"><![CDATA[ 
    SELECT * from S1 
    XMLTable ( 
        XMLNAMESPACES('http://example.com' as 'e'), 
        'for $i in //e:emps return $i/e:emp' PASSING BY VALUE S1.c1 as "." 
        COLUMNS 
            empName char(16) PATH 'fn:data(@ename)', 
            empId integer PATH 'fn:data(@empno)'
        ) AS X
]]></query>

Example 20-31 XMLTABLE With XML Namespaces Stream Input

Timestamp   Tuple
3000        "<emps xmlns=\"http://example.com\"><emp empno=\"1\" deptno=\"10\" ename=\"John\" salary=\"21000\"/><emp empno=\"2\" deptno=\"10\" ename=\"Jack\" salary=\"310000\"/><emp empno=\"3\" deptno=\"20\" ename=\"Jill\" salary=\"100001\"/></emps>"
h 4000

Example 20-32 XMLTABLE With XML Namespaces Relation Output

Timestamp   Tuple Kind  Tuple
3000:       +     John,1
3000:       +     Jack,2
3000:       +     Jill,3

Data Cartridge TABLE Query Example: Iterator

Consider a data cartridge (MyCartridge) with method getIterator as Example 20-33 shows.

Example 20-33 MyCartridge Method getIterator

...
    public static Iterator<Integer> getIterator() {
        ArrayList<Integer> list = new ArrayList<Integer>();
        list.add(1);
        list.add(2);
        return list.iterator();
    }
...

Consider the query q1 in Example 20-34. Given the data stream S0 in Example 20-35, the query returns the relation in Example 20-36.

Example 20-34 TABLE Query: Iterator

<query id="q1"><![CDATA[ 
    select S1.c1, S1.c2, S2.c1 
    from 
        S0[now] as S1, 
        table (com.acme.MyCartridge.getIterator() as c1) of integer as S2
]]></query>

Example 20-35 TABLE Query Stream Input: Iterator

Timestamp   Tuple
1           1, abc
2           2, ab
3           3, abc
4           4, a
h 200000000

Example 20-36 TABLE Query Output: Iterator

Timestamp   Tuple Kind  Tuple
1:          +           1,abc,1
1:          +           1,abc,2
1:          -           1,abc,1
1:          -           1,abc,2
2:          +           2,ab,1
2:          +           2,ab,2
2:          -           2,ab,1
2:          -           2,ab,2
3:          +           3,abc,1
3:          +           3,abc,2
3:          -           3,abc,1
3:          -           3,abc,2
4:          +           4,a,1
4:          +           4,a,2
4:          -           4,a,1
4:          -           4,a,2

Data Cartridge TABLE Query Example: Array

Consider a data cartridge (MyCartridge) with method getArray as Example 20-37 shows.

Example 20-37 MyCartridge Method getArray

...
    public static Integer[] getArray(int c1) {
        ArrayList<Integer> list = new ArrayList<Integer>();
        list.add(1);
        list.add(2);
        return list.toArray(new Integer[2]);;
    }
...

Consider the query q1 in Example 20-38. Given the data stream S0 in Example 20-39, the query returns the relation in Example 20-40.

Example 20-38 TABLE Query: Array

<query id="q1"><![CDATA[ 
    select S1.c1, S1.c2, S2.c1 
    from 
        S0[now] as S1, 
        table (com.acme.MyCartridge.getArrayS1.c1) as c1) of integer as S2
]]></query>

Example 20-39 TABLE Query Stream Input: Array

Timestamp   Tuple
1           1, abc
2           2, ab
3           3, abc
4           4, a
h 200000000

Example 20-40 TABLE Query Output: Array

Timestamp   Tuple Kind  Tuple
1:          +           1,abc,1
1:          +           1,abc,2
1:          -           1,abc,1
1:          -           1,abc,2
2:          +           2,ab,2
2:          +           2,ab,4
2:          -           2,ab,2
2:          -           2,ab,4
3:          +           3,abc,3
3:          +           3,abc,6
3:          -           3,abc,3
3:          -           3,abc,6
4:          +           4,a,4
4:          +           4,a,8
4:          -           4,a,4
4:          -           4,a,8

Data Cartridge TABLE Query Example: Collection

Consider a data cartridge (MyCartridge) with method getCollection as Example 20-41 shows.

Example 20-41 MyCartridge Method getCollection

...
    public HashMap<Integer,String> developers;
    developers = new HashMap<Integer,String>();
    developers.put(2, "Mohit");
    developers.put(4, "Unmesh");
    developers.put(3, "Sandeep");
    developers.put(1, "Swagat");

    public HashMap<Integer,String> qaengineers;
    qaengineers = new HashMap<Integer,String>();
    qaengineers.put(4, "Terry");
    qaengineers.put(5, "Tony");
    qaengineers.put(3, "Junger");
    qaengineers.put(1, "Arthur");
...
    public Collection<String> getEmployees(int exp_yrs) {
        LinkedList<String> employees = new LinkedList<String>();
        employees.add(developers.get(exp_yrs));    
        employees.add(qaengineers.get(exp_yrs));
        return employees;
  }
...

Consider the query q1 in Example 20-42. Given the data stream S0 in Example 20-43, the query returns the relation in Example 20-44.

Example 20-42 TABLE Query: Collection

<query id="q1"><![CDATA[ 
    RStream(
        select S1.c1, S2.c1 
        from 
            S0[now] as S1, 
            table(S1.c2.getEmployees(S1.c1) as c1) of char as S2
    )
]]></query>

Example 20-43 TABLE Query Stream Input: Collection

Timestamp   Tuple
1           1, abc
2           2, ab
3           3, abc
4           4, a
h 200000000

Example 20-44 TABLE Query Output: Collection

Timestamp   Tuple Kind  Tuple
1:          +           1,Swagat
1:          +           1,Arthur
2:          +           2,Mohit
3:          +           3,Sandeep
3:          +           3,Junger
4:          +           4,Unmesh
4:          +           4,Terry

ORDER BY ROWS Query Example

Consider the query q1 in Example 20-45. Given the data stream S0 in Example 20-46, the query returns the relation in Example 20-47.

Example 20-45 ORDER BY ROWS Query

<query id="q1"><![CDATA[ 
    select c1 ,c2 from S0 order by c1,c2 rows 5
]]></query>

Example 20-46 ORDER BY ROWS Stream Input

Timestamp   Tuple
1000        7, 15
2000        7, 14
2000        5, 23
2000        5, 15
2000        5, 15
2000        5, 25
3000        2, 13
3000        3, 19
4000        4, 17
5000        1, 9
h 1000000000

Example 20-47 ORDER BY ROWS Output

Timestamp   Tuple Kind  Tuple
1000:       +           7,15
2000:       +           7,14
2000:       +           5,23
2000:       +           5,15
2000:       +           5,15
2000:       -           7,15
2000:       +           5,25
3000:       -           7,14
3000:       +           2,13
3000:       -           5,25
3000:       +           3,19
4000:       -           5,23
4000:       +           4,17
5000:       -           5,15
5000:       +           1,9

View

Purpose

Use view statement to create a view over a base stream or relation that you reference by identifier in subsequent Oracle CQL statements.

Prerequisites

For more information, see:

Syntax

You express the a view in a <view></view> element as Example 20-48 shows.

The view element has two attributes:

  • id: Specify the identifier as the view element id attribute.

    The id value must conform with the specification given by identifier::=.

  • schema: Optionally, specify the schema of the view as a space delimited list of attribute names.

    Oracle CEP server infers the types.

Example 20-48 View in a <view></view> Element

<view id="v2" schema="cusip bid ask"><![CDATA[ 
    IStream(select * from S1[range 10 slide 10]) 
]]></view>

The body of the view has the same syntax as a query. For more information, see "Query".

Examples

The following examples illustrate the various semantics that this statement supports. For more examples, see Chapter 18, "Oracle CQL Queries, Views, and Joins".

Registering a View Example

Example 20-49 shows how to register view v2.

Example 20-49 REGISTER VIEW

<view id="v2" schema="cusip bid ask"><![CDATA[ 
    IStream(select * from S1[range 10 slide 10]) 
]]></view>
PK8AtNeNPKO_\E OEBPS/lof.htm< List of Figures

List of Figures

PK2A<PKO_\EOEBPS/funcbltsr.htm Built-In Single-Row Functions

8 Built-In Single-Row Functions

This chapter provides a reference to single-row functions in Oracle Continuous Query Language (Oracle CQL). Single-row functions return a single result row for every row of a queried stream or view.

For more information, see Section 1.1.11, "Functions".

8.1 Introduction to Oracle CQL Built-In Single-Row Functions

Table 8-1 lists the built-in single-row functions that Oracle CQL provides.

Table 8-1 Oracle CQL Built-in Single-Row Functions

TypeFunction

Character (returning character values)


Character (returning numeric values)


Datetime


Conversion


XML and SQLX


Encoding and Decoding


Null-related


Pattern Matching




Note:

Built-in function names are case sensitive and you must use them in the case shown (in lower case).



Note:

In stream input examples, lines beginning with h (such as h 3800) are heartbeat input tuples. These inform Oracle CEP that no further input will have a timestamp lesser than the heartbeat value.


For more information, see:


concat

Syntax

Surrounding text describes concat.png.

Purpose

concat returns char1 concatenated with char2 as a char[] or byte1 concatenated with byte2 as a byte[]. The char returned is in the same character set as char1. Its datatype depends on the datatypes of the arguments.

Using concat, you can concatenate any combination of character, byte, and numeric datatypes. The concat performs automatic numeric to string conversion.

This function is equivalent to the concatenation operator (||). For more information, see "Concatenation Operator".

To concatenate xmltype arguments, use xmlconcat. For more information, see "xmlconcat".

Examples

concat Function

Consider the query chr_concat in Example 8-1 and data stream S4 in Example 8-2. Stream S4 has schema (c1 char(10)). The query returns the relation in Example 8-3.

Example 8-1 concat Function Query

<query id="chr_concat"><![CDATA[ 
    select 
        concat(c1,c1),
        concat("abc",c1),
        concat(c1,"abc") 
    from 
        S4[range 5]
]]></query>

Example 8-2 concat Function Stream Input

Timestamp   Tuple
 1000
 2000       hi
 8000       hi1
 9000
15000       xyz
h 200000000

Example 8-3 concat Function Relation Output

Timestamp   Tuple Kind  Tuple
 1000:      +           ,abc,abc
 2000:      +           hihi,abchi,hiabc
 6000:      -           ,abc,abc
 7000:      -           hihi,abchi,hiabc
 8000:      +           hi1hi1,abchi1,hi1abc
 9000:      +           ,abc,abc
13000:      -           hi1hi1,abchi1,hi1abc
14000:      -           ,abc,abc
15000:      +           xyzxyz,abcxyz,xyzabc
20000:      -           xyzxyz,abcxyz,xyzabc

Concatenation Operator (||)

Consider the query q264 in Example 8-4 and the data stream S10 in Example 8-5. Stream S10 has schema (c1 integer, c2 char(10)). The query returns the relation in Example 8-6.

Example 8-4 Concatenation Operator (||) Query

<query id="q264"><![CDATA[ 
    select
        c2 || "xyz"
    from
        S10
]]></query>

Example 8-5 Concatenation Operator (||) Stream Input

Timestamp   Tuple
1           1,abc
2           2,ab
3           3,abc
4           4,a
h 200000000

Example 8-6 Concatenation Operator (||) Relation Output

Timestamp   Tuple Kind  Tuple
1:          +           abcxyz
2:          +           abxyz
3:          +           abcxyz
4:          +           axyz

hextoraw

Syntax

Surrounding text describes hextoraw.png.

Purpose

hextoraw converts char containing hexadecimal digits in the char character set to a raw value.


See Also:

"rawtohex"


Examples

Consider the query q6 in Example 8-7 and the data stream SinpByte1 in Example 8-8. Stream SinpByte1 has schema (c1 byte(10), c2 integer). The query returns the relation in Example 8-9.

Example 8-7 hextoraw Function Query

<query id="q6"><![CDATA[ 
    select * from SByt[range 2] 
    where 
        bytTest(c2) between hextoraw("5200") and hextoraw("5600")
]]></query>

Example 8-8 hextoraw Function Stream Input

Timestamp   Tuple
1000        1,"51c1"
2000        2,"52"
3000        3,"53aa"
4000        4,"5"
5000         ,"55ef"
6000        6,
h 8000
h 200000000

Example 8-9 hextoraw Function Relation Output

Timestamp   Tuple Kind  Tuple
2000        +           2,"52"
3000        +           3,"53aa"
4000        -           2,"52"
5000        -           3,"53aa"
5000        +            ,"55ef"
7000        -            ,"55ef"

length

Syntax

Surrounding text describes length.png.

Purpose

The length function returns the length of its char or byte expression as an int. length calculates length using characters as defined by the input character set.

For a char expression, the length includes all trailing blanks. If the expression is null, this function returns null.

Examples

Consider the query chr_len in Example 8-10 and the data stream S2 in Example 8-11. Stream S2 has schema (c1 integer, c2 integer). The query returns the relation that Example 8-12.

Example 8-10 length Function Query

<query id="chr_len"><![CDATA[ 
    select length(c1) from S4[range 5]
]]></query>

Example 8-11 length Function Stream Input

Timestamp   Tuple
 1000
 2000       hi
 8000       hi1
 9000
15000       xyz
h 200000000

Example 8-12 length Function Relation Output

Timestamp   Tuple Kind  Tuple
 1000:      +           0
 2000:      +           2
 6000:      -           0
 7000:      -           2
 8000:      +           3
 9000:      +           0
13000:      -           3
14000:      -           0
15000:      +           3
20000:      -           3

lk

Syntax

Surrounding text describes lk.png.

Purpose

lk boolean true if char1 matches the regular expression char2, otherwise it returns false.

This function is equivalent to the LIKE condition. For more information, see Section 6.4, "LIKE Condition".

Examples

Consider the query q291 in Example 8-13 and the data stream SLk1 in Example 8-14. Stream SLk1 has schema (first1 char(20), last1 char(20)). The query returns the relation in Example 8-15.

Example 8-13 lk Function Query

<query id="q291"><![CDATA[ 
    select * from SLk1 
    where 
        lk(first1,"^Ste(v|ph)en$")
]]></query>

Example 8-14 lk Function Stream Input

Timestamp   Tuple
1           Steven,King
2           Sten,Harley
3           Stephen,Stiles
4           Steven,Markles
h 200000000

Example 8-15 lk Function Relation Output

Timestamp   Tuple Kind  Tuple
1:          +           Steven,King
3:          +           Stephen,Stiles
4:          +           Steven,Markles

nvl

Syntax

Surrounding text describes nvl.png.

Purpose

nvl lets you replace null (returned as a blank) with a string in the results of a query. If expr1 is null, then NVL returns expr2. If expr1 is not null, then NVL returns expr1.

The arguments expr1 and expr2 can have any datatype. If their datatypes are different, then Oracle CEP implicitly converts one to the other. If they cannot be converted implicitly, Oracle CEP returns an error. The implicit conversion is implemented as follows:

  • If expr1 is character data, then Oracle CEP converts expr2 to character data before comparing them and returns VARCHAR2 in the character set of expr1.

  • If expr1 is numeric, then Oracle CEP determines which argument has the highest numeric precedence, implicitly converts the other argument to that datatype, and returns that datatype.

Examples

Consider the query q281 in Example 8-16 and the data stream SNVL in Example 8-17. Stream SNVL has schema (c1 char(20), c2 integer). The query returns the relation in Example 8-18.

Example 8-16 nvl Function Query

<query id="q281"><![CDATA[ 
    select nvl(c1,"abcd") from SNVL
]]></query>

Example 8-17 nvl Function Stream Input

Timestamp   Tuple
1              ,1
2            ab,2
3           abc,3
4              ,4
h 200000000

Example 8-18 nvl Function Relation Output

Timestamp   Tuple Kind  Tuple
1:          +           abcd
2:          +           ab
3:          +           abc
4:          +           abcd

prev

Syntax

Surrounding text describes prev.png.

Purpose

prev returns the value of the stream attribute (function argument identifier2) of the event that occurred previous to the current event and which belongs to the partition to which the current event belongs. It evaluates to NULL if there is no such previous event.

The type of the specified stream element may be any of:

  • integer

  • bigint

  • float

  • double

  • byte

  • char

  • interval

  • timestamp

The return type of this function depends on the type of the specified stream attribute (function argument identifier2).

This function takes the following arguments:

Where:

  • identifier1.identifier2 : identifier1 is the name of a correlation variable used in the PATTERN clause and defined in the DEFINE clause and identifier2 is the name of a stream attribute whose value in the previous event should be returned by prev.

  • const_int1: if this argument has a value n, then it specifies the nth previous event in the partition to which the current event belongs. The value of the attribute (specified in argument identifier2) in the nth previous event will be returned if such an event exists, NULL otherwise.

  • const_int2: specifies a time range duration in nanoseconds and should be used if you are interested in previous events that occurred only within a certain range of time before the current event.

Examples

prev(identifier1.identifier2)

Consider query q2 in Example 8-19 and the data stream S1 in Example 8-20. Stream S1 has schema (c1 integer). This example defines pattern A as A.c1 = prev(A.c1). In other words, pattern A matches when the value of c1 in the current stream element matches the value of c1 in the stream element immediately before the current stream element. The query returns the relation in Example 8-21.

Example 8-19 prev(identifier1.identifier2) Function Query

<query id="q2"><![CDATA[ 
    select 
        T.Ac1,
        T.Cc1 
    from 
        S1 
    MATCH_RECOGNIZE ( 
        MEASURES 
            A.c1 as Ac1, 
            C.c1 as Cc1 
        PATTERN(A B+ C) 
        DEFINE 
            A as A.c1 = prev(A.c1), 
            B as B.c1 = 10, 
            C as C.c1 = 7
    ) as T
]]></query>

Example 8-20 prev(identifier1.identifier2) Function Stream Input

Timestamp   Tuple
1000        35
3000        35
4000        10
5000         7

Example 8-21 prev(identifier1.identifier2) Function Relation Output

Timestamp   Tuple Kind  Tuple
5000:       +           35,7

prev(identifier1.identifier2, const_int1)

Consider query q35 in Example 8-22 and the data stream S15 in Example 8-23. Stream S15 has schema (c1 integer, c2 integer). This example defines pattern A as A.c1 = prev(A.c1,3). In other words, pattern A matches when the value of c1 in the current stream element matches the value of c1 in the third stream element before the current stream element. The query returns the relation in Example 8-24.

Example 8-22 prev(identifier1.identifier2, const_int1) Function Query

<query id="q35"><![CDATA[ 
    select T.Ac1 from S15 
    MATCH_RECOGNIZE ( 
        MEASURES 
            A.c1 as Ac1 
        PATTERN(A) 
        DEFINE 
            A as (A.c1 = prev(A.c1,3) )
    ) as T
]]></query>

Example 8-23 prev(identifier1.identifier2, const_int1) Function Stream Input

Timestamp   Tuple
 1000       45,20
 2000       45,30
 3000        45,30
 4000       45,30
 5000       45,30
 6000       45,20
 7000       45,20
 8000       45,20
 9000       43,40
10000       52,10
11000       52,30
12000       43,40
13000       52,50
14000       43,40
15000       43,40

Example 8-24 prev(identifier1.identifier2, const_int1) Function Relation Output

Timestamp   Tuple Kind  Tuple
 3000:       +          45
 4000:       +          45
 5000:       +          45
 6000:       +          45
 7000:       +          45
 8000:       +          45
13000:       +          52
15000:       +          43

prev(identifier1.identifier2, const_int1, const_int2)

Consider query q36 in Example 8-26 and the data stream S15 in Example 8-27. Stream S15 has schema (c1 integer, c2 integer). This example defines pattern A as A.c1 = prev(A.c1,3,5000000000L). In other words, pattern A matches when:

  • the value of c1 in the current event equals the value of c1 in the third previous event of the partition to which the current event belongs, and

  • the difference between the timestamp of the current event and that third previous event is less than or equal to 5000000000L nanoseconds.

The query returns the output relation that Example 8-28 shows. Notice that in the output relation, there is no output at 8000. Example 8-25 shows the contents of the partition (partitioned by the value of the c2 attribute) to which the event at 8000 belongs.

Example 8-25 Partition Containing the Event at 8000

Timestamp   Tuple
1000        45,20
6000        45,20
7000        45,20
8000        45,20

As Example 8-25 shows, even though the value of c1 in the third previous event (the event at 1000) is the same as the value c1 in the current event (the event at 8000), the range condition is not satisfied. This is because the difference in the timestamps of these two events is more than 5000000000 nanoseconds. So it is treated as if there is no previous tuple and prev returns NULL so the condition fails to match.

Example 8-26 prev(identifier1.identifier2, const_int1, const_int2) Function Query

<query id="q36"><![CDATA[ 
    select T.Ac1 from S15 
    MATCH_RECOGNIZE ( 
        PARTITION BY
            c2 
        MEASURES 
            A.c1 as Ac1 
        PATTERN(A) 
        DEFINE 
            A as (A.c1 = prev(A.c1,3,5000000000L) )
    ) as T
]]></query>

Example 8-27 prev(identifier1.identifier2, const_int1, const_int2) Function Stream Input

Timestamp   Tuple
 1000       45,20
 2000       45,30
 3000       45,30
 4000       45,30
 5000       45,30
 6000       45,20
 7000       45,20
 8000       45,20
 9000       43,40
10000       52,10
11000       52,30
12000       43,40
13000       52,50
14000       43,40
15000       43,40

Example 8-28 prev(identifier1.identifier2, const_int1, const_int2) Function Relation Output

Timestamp   Tuple Kind  Tuple
5000:       +           45

rawtohex

Syntax

Surrounding text describes rawtohex.png.

Purpose

rawtohex converts byte containing a raw value to hexadecimal digits in the CHAR character set.


See Also:

"hextoraw"


Examples

Consider the query byte_to_hex in Example 8-29 and the data stream S5 in Example 8-30. Stream S5 has schema (c1 integer, c2 byte(10)). This query uses the rawtohex function to convert a ten byte raw value to the equivalent ten hexidecimal digits in the character set of your current locale. The query returns the relation in Example 8-31.

Example 8-29 rawtohex Function Query

<query id="byte_to_hex"><![CDATA[ 
    select rawtohex(c2) from S5[range 4]
]]></query>

Example 8-30 rawtohex Function Stream Input

Timestamp   Tuple
1000        1,"51c1"
2000        2,"52"
2500        7,"axc"
3000        3,"53aa"
4000        4,"5"
5000         ,"55ef"
6000        6,
h 8000
h 200000000

Example 8-31 rawtohex Function Relation Output

Timestamp   Tuple Kind  Tuple
 1000:      +           51c1
 2000:      +           52
 3000:      +           53aa
 4000:      +           05
 5000:      -           51c1
 5000:      +           55ef
 6000:      -           52
 6000:      +
 7000:      -           53aa
 8000:      -           05
 9000:      -           55ef
10000:      -

systimestamp

Syntax

Surrounding text describes systimestamp.png.

Purpose

systimestamp returns the system date, including fractional seconds and time zone, of the system on which the Oracle CEP server resides. The return type is TIMESTAMP WITH TIME ZONE.

Examples

Consider the query q106 in Example 8-32 and the data stream S0 in Example 8-33. Stream S0 has schema (c1 float, c2 integer). The query returns the relation in Example 8-34. For more information about case, see "case_expr".

Example 8-32 systimestamp Function Query

<query id="q106"><![CDATA[ 
    select * from S0 
    where 
        case c2 
            when 10 then null 
            when 20 then null 
            else systimestamp() 
        end > "07/06/2007 14:13:33"
]]></query>

Example 8-33 systimestamp Function Stream Input

Timestamp   Tuple
     1000   0.1 ,10
     1002   0.14,15
   200000   0.2 ,20
   400000   0.3 ,30
   500000   0.3 ,35
   600000       ,35
h 800000
100000000   4.04,40
h 200000000

Example 8-34 systimestamp Function Relation Output

Timestamp   Tuple Kind  Tuple
     1002:  +           0.14,15
   400000:  +           0.3 ,30
   500000:  +           0.3 ,35
   600000:  +               ,35
100000000:  +           4.04,40

to_bigint

Syntax

Surrounding text describes to_bigint.png.

Purpose

to_bigint returns a bigint number equivalent of its integer argument.

For more information, see:

Examples

Consider the query q282 in Example 8-35 and the data stream S11 in Example 8-36. Stream S11 has schema (c1 integer, name char(10)). The query returns the relation in Example 8-37.

Example 8-35 to_bigint Function Query

<query id="q282"><![CDATA[ 
    select nvl(to_bigint(c1), 5.2) from S11
]]></query>

Example 8-36 to_bigint Function Stream Input

Timestamp   Tuple
  10        1,abc
2000         ,ab
3400        3,abc
4700         ,a
h 8000
h 200000000

Example 8-37 to_bigint Function Relation Output

Timestamp   Tuple Kind  Tuple
  10:       +           1
2000:       +           5.2
3400:       +           3
4700:       +           5.2

to_boolean

Syntax

Surrounding text describes to_boolean.png.

Purpose

to_boolean returns a value of true or false for its bigint or integer expression argument.

For more information, see:

Examples

Consider the query q282 in Example 8-35 and the data stream S11 in Example 8-36. Stream S11 has schema (c1 integer, name char(10)). The query returns the relation in Example 8-37.

Example 8-38 to_boolean Function Query

<view id="v2" schema="c1 c2" ><![CDATA[
    select to_boolean(c1), c1 from tkboolean_S3 [now] where c2 = 0.1
]]></view><query id="q1"><![CDATA[ 
    select * from v2
]]></query>

Example 8-39 to_boolean Function Stream Input

Timestamp   Tuple
1000        -2147483648, 0.1
2000        2147483647, 0.2
3000        12345678901, 0.3
4000        -12345678901, 0.1
5000        9223372036854775799, 0.2
6000        -9223372036854775799, 0.3
7000        , 0.1
8000        10000000000, 0.2
9000        60000000000, 0.3
h 200000000

Example 8-40 to_boolean Function Relation Output

Timestamp   Tuple Kind  Tuple
1000      +           true,-2147483648
1000      -           true,-2147483648
4000      +           true,-12345678901
4000      -           true,-12345678901
7000      +           ,
7000      -           ,

to_char

Syntax

Surrounding text describes to_char.png.

Purpose

to_char returns a char value for its integer, double, bigint, float, timestamp, or interval expression argument. If the bigint argument exceeds the char precision, Oracle CEP returns an error.

For more information, see:

Examples

Consider the query q282 in Example 8-35 and the data stream S11 in Example 8-36. Stream S11 has schema (c1 integer, name char(10)). The query returns the relation in Example 8-37.

Example 8-41 to_char Function Query

<query id="q1"><![CDATA[ 
    select to_char(c1), to_char(c2), to_char(c3), to_char(c4), to_char(c5), to_char(c6) 
    from S1
]]></query>

Example 8-42 to_char Function Stream Input

Timestamp   Tuple
1000        99,99999, 99.9, 99.9999, "4 1:13:48.10", "08/07/2004 11:13:48", cep

Example 8-43 to_char Function Relation Output

Timestamp   Tuple Kind  Tuple
1000:       +           99,99999,99.9,99.9999,4 1:13:48.10,08/07/2004 11:13:48

to_double

Syntax

Surrounding text describes to_double.png.

Purpose

to_double returns a double value for its bigint, integer, or float expression argument. If the bigint argument exceeds the double precision, Oracle CEP returns an error.

For more information, see:

Examples

Consider the query q282 in Example 8-35 and the data stream S11 in Example 8-36. Stream S11 has schema (c1 integer, name char(10)). The query returns the relation in Example 8-37.

Example 8-44 to_double Function Query

<query id="q282"><![CDATA[ 
    select nvl(to_double(c1), 5.2) from S11
]]></query>

Example 8-45 to_double Function Stream Input

Timestamp   Tuple
  10        1,abc
2000         ,ab
3400        3,abc
4700         ,a
h 8000
h 200000000

Example 8-46 to_double Function Relation Output

Timestamp   Tuple Kind  Tuple
  10:       +           1
2000:       +           5.2
3400:       +           3
4700:       +           5.2

to_float

Syntax

Surrounding text describes to_float.png.

Purpose

to_float returns a float number equivalent of its bigint or integer argument. If the bigint argument exceeds the float precision, Oracle CEP returns an error.

For more information, see:

Examples

Consider the query q1 in Example 8-47 and the data stream S11 in Example 8-48. Stream S1 has schema (c1 integer, name char(10)). The query returns the relation in Example 8-49.

Example 8-47 to_float Function Query

<query id="q1"><![CDATA[ 
    select nvl(to_float(c1), 5.2) from S11
]]></query>

Example 8-48 to_float Function Stream Input

Timestamp   Tuple
  10        1, abc
2000         , ab
3400        3, abc
4700         , a
h 8000
h 200000000

Example 8-49 to_float Function Relation Output

Timestamp   Tuple Kind  Tuple
10:+ 1.02000:+ 5.23400:+ 3.04700:+ 5.2

to_timestamp

Syntax

Surrounding text describes to_timestamp.png.

Purpose

to_timestamp converts char literals that conform to java.text.SimpleDateFormat format models to timestamp datatypes. There are two forms of the to_timestamp function distinguished by the number of arguments:

  • char: this form of the to_timestamp function converts a single char argument that contains a char literal that conforms to the default java.text.SimpleDateFormat format model (MM/dd/yyyy HH:mm:ss) into the corresponding timestamp datatype.

  • char1, char2: this form of the to_timestamp function converts the char1 argument that contains a char literal that conforms to the java.text.SimpleDateFormat format model specified in the second char2 argument into the corresponding timestamp datatype.

  • long: this form of the to_timestamp function converts a single long argument that represents the number of nanoseconds since the standard base time known as "the epoch", namely January 1, 1970, 00:00:00 GMT, into the corresponding timestamp datatype represented as a number in milliseconds since "the epoch" with a date format that conforms to the default java.text.SimpleDateFormat format model (MM/dd/yyyy HH:mm:ss).

For more information, see:

Examples

Consider the query q277 in Example 8-50 and the data stream STs2 in Example 8-51. Stream STs2 has schema (c1 integer, c2 char(20)). The query returns the relation that Example 8-52.

Example 8-50 to_timestamp Function Query

<query id="q277"><![CDATA[ 
    select * from STs2 
    where 
        to_timestamp(c2,"yyMMddHHmmss") = to_timestamp("09/07/2005 10:13:48")
]]></query>

Example 8-51 to_timestamp Function Stream Input

Timestamp   Tuple
1           1,"040807111348"
2           2,"050907101348"
3           3,"041007111348"
4           4,"060806111248"
h 200000000

Example 8-52 to_timestamp Function Relation Output

Timestamp   Tuple Kind  Tuple
2:          +           2,050907101348

xmlcomment

Syntax

Surrounding text describes xmlcomment.png.

Purpose

xmlcomment returns its double-quote delimited constant String argument as an xmltype.

Using xmlcomment, you can add a well-formed XML comment to your query results.

This function takes the following arguments:

  • quoted_string_double_quotes: a double-quote delimited String constant.

The return type of this function is xmltype. The exact schema depends on that of the input stream of XML data.

Examples

Consider the query tkdata64_q1 in Example 8-53 and data stream tkdata64_S in Example 8-54. Stream tkdata64_S has schema (c1 char(30)). The query returns the relation in Example 8-55.

Example 8-53 xmlcomment Function Query

<query id="tkdata64_q1"><![CDATA[ 
    xmlconcat(xmlelement("parent", c1), xmlcomment("this is a comment")) 
from tkdata64_S
]]></query>

Example 8-54 xmlcomment Function Stream Input

Timestamp   Tuple
c 30
1000        "san jose"
1000        "mountain view"
1000
1000        "sunnyvale"
1003
1004        "belmont"

Example 8-55 xmlcomment Function Relation Output

Timestamp   Tuple Kind  Tuple
1000:       +           <parent>san jose</parent>
                        <!--this is a comment-->
1000:       +           <parent>mountain view</parent>
                        <!--this is a comment-->
1000:       +           <parent/>
                        <!--this is a comment-->
1000:       +           <parent>sunnyvale</parent>
                        <!--this is a comment-->
1003:       +           <parent/>
                        <!--this is a comment-->
1004:       +           <parent>belmont</parent>
                        <!--this is a comment-->

xmlconcat

Syntax

Surrounding text describes xmlconcat.png.

Purpose

xmlconcat returns the concatenation of its comma-delimited xmltype arguments as an xmltype.

Using xmlconcat, you can concatenate any combination of xmltype arguments.

This function takes the following arguments:

  • non_mt_arg_list: a comma-delimited list of xmltype arguments. For more information, see non_mt_arg_list::=.

The return type of this function is xmltype. The exact schema depends on that of the input stream of XML data.

This function is especially useful when processing SQLX streams. For more information, see "SQL/XML (SQLX)".

To concatenate datatypes other than xmltype, use CONCAT. For more information, see "concat".


See Also:

"SQL/XML (SQLX)"


Examples

Consider the query tkdata64_q1 in Example 8-53 and the data stream tkdata64_S in Example 8-54. Stream tkdata64_S has schema (c1 char(30)). The query returns the relation in Example 8-55.

Example 8-56 xmlconcat Function Query

<query id="tkdata64_q1"><![CDATA[ 
    select 
        xmlconcat(xmlelement("parent", c1), xmlcomment("this is a comment")) 
    from tkdata64_S
]]></query>

Example 8-57 xmlconcat Function Stream Input

Timestamp   Tuple
c 30
1000        "san jose"
1000        "mountain view"
1000
1000        "sunnyvale"
1003
1004        "belmont"

Example 8-58 xmlconcat Function Relation Output

Timestamp   Tuple Kind  Tuple
1000:       +           <parent>san jose</parent>
                        <!--this is a comment-->
1000:       +           <parent>mountain view</parent>
                        <!--this is a comment-->
1000:       +           <parent/>
                        <!--this is a comment-->
1000:       +           <parent>sunnyvale</parent>
                        <!--this is a comment-->
1003:       +           <parent/>
                        <!--this is a comment-->
1004:       +           <parent>belmont</parent>
                        <!--this is a comment-->

xmlexists

Syntax

Surrounding text describes xmlexists.png.

Purpose

xmlexists creates a continuous query against a stream of XML data to return a boolean that indicates whether or not the XML data satisfies the XQuery you specify.

This function takes the following arguments:

  • const_string: An XQuery that Oracle CEP applies to the XML stream element data that you bind in xqryargs_list. For more information, see const_string::=.

  • xqryargs_list: A list of one or more bindings between stream elements and XQuery variables or XPath operators. For more information, see xqryargs_list::=.

The return type of this function is boolean: true if the XQuery is satisfied; false otherwise.

This function is especially useful when processing SQLX streams. For more information, see "SQL/XML (SQLX)".

Examples

Consider the query q1 in Example 8-59 and the XML data stream S in Example 8-60. Stream S has schema (c1 integer, c2 xmltype). In this example, the value of stream element c2 is bound to the current node (".") and the value of stream element c1 + 1 is bound to XQuery variable x. The query returns the relation in Example 8-61.

Example 8-59 xmlexists Function Query

<query id="q1"><![CDATA[ 
    SELECT 
        xmlexists(
            "for $i in /PDRecord WHERE $i/PDId <= $x RETURN $i/PDName" 
            PASSING BY VALUE  
                c2 as ".", 
               (c1+1) AS "x" 
            RETURNING CONTENT
        ) XMLData 
    FROM 
        S
]]></query>

Example 8-60 xmlexists Function Stream Input

Timestamp   Tuple
3           1, "<PDRecord><PDName>hello</PDName></PDRecord>"
4           2, "<PDRecord><PDName>hello</PDName><PDName>hello1</PDName></PDRecord>"
5           3, "<PDRecord><PDId>6</PDId><PDName>hello1</PDName></PDRecord>"
6           4, "<PDRecord><PDId>46</PDId><PDName>hello2</PDName></PDReNcord>"

Example 8-61 xmlexists Function Relation Output

Timestamp   Tuple Kind  Tuple
3:          +           false
4:          +           false
5:          +           true
6:          +           false

xmlquery

Syntax

Surrounding text describes xmlquery.png.

Purpose

xmlquery creates a continuous query against a stream of XML data to return the XML data that satisfies the XQuery you specify.

This function takes the following arguments:

  • const_string: An XQuery that Oracle CEP applies to the XML stream element data that you bind in xqryargs_list. For more information, see const_string::=.

  • xqryargs_list: A list of one or more bindings between stream elements and XQuery variables or XPath operators. For more information, see xqryargs_list::=.

The return type of this function is xmltype. The exact schema depends on that of the input stream of XML data.

This function is especially useful when processing SQLX streams. For more information, see "SQL/XML (SQLX)".

Examples

Consider the query q1 in Example 8-62 and the XML data stream S in Example 8-63. Stream S has schema (c1 integer, c2 xmltype). In this example, the value of stream element c2 is bound to the current node (".") and the value of stream element c1 + 1 is bound to XQuery variable x. The query returns the relation in Example 8-64.

Example 8-62 xmlquery Function Query

<query id="q1"><![CDATA[ 
    SELECT 
        xmlquery(
            "for $i in /PDRecord WHERE $i/PDId <= $x RETURN $i/PDName" 
            PASSING BY VALUE  
                c2 as ".", 
               (c1+1) AS "x" 
            RETURNING CONTENT
        ) XMLData 
    FROM 
        S
]]></query>

Example 8-63 xmlquery Function Stream Input

Timestamp   Tuple
3           1, "<PDRecord><PDName>hello</PDName></PDRecord>"
4           2, "<PDRecord><PDName>hello</PDName><PDName>hello1</PDName></PDRecord>"
5           3, "<PDRecord><PDId>6</PDId><PDName>hello1</PDName></PDRecord>"
6           4, "<PDRecord><PDId>46</PDId><PDName>hello2</PDName></PDRecord>"

Example 8-64 xmlquery Function Relation Output

Timestamp   Tuple Kind  Tuple
3:          +
4:          +
5:          +           "<PDName>hello1</PDName>"
6:          +           "<PDName>hello2</PDName>"
PK6.A]NPKO_\EOEBPS/datacartjdbc.htm Oracle CEP JDBC Data Cartridge

17 Oracle CEP JDBC Data Cartridge

This chapter describes the Oracle CEP JDBC data cartridge, an Oracle Continuous Query Language (Oracle CQL) extension through which you execute a SQL query against a database and use its returned results in a CQL query.

When using functionality provided by the cartridge, you are associating a SQL query with a JDBC cartridge function definition. Then, from a CQL query, you can call the JDBC cartridge function, which executes the associated SQL query against the database. The function call must be enclosed in the TABLE clause, which lets you use the SQL query results as a CQL relation in the CQL query making that function call.

For information the TABLE clause, see Section 17.2.2.2, "Using the TABLE Clause."

This chapter describes:

For more information, see:

17.1 Understanding the Oracle CEP JDBC Data Cartridge

Oracle CEP streams contain streaming data, and a database typically stores historical data. Use the Oracle CEP JDBC data cartridge to associate historical data (stored in one or more tables) with the streaming data coming from Oracle CEP streams. The Oracle CEP JDBC data cartridge executes arbitrary SQL query against a database and uses the results in the CQL query. This section describes how to associate streaming and historical data using the Oracle CEP JDBC data cartridge.

This section describes:

17.1.1 Data Cartridge Name

The Oracle CEP JDBC data cartridge uses the cartridge ID com.oracle.cep.cartrdige.jdbc. This ID is reserved and cannot be used by any other cartridges.

For more information, see Section 17.1.4, "Oracle CEP JDBC Data Cartridge Application Context".

17.1.2 Scope

The Oracle CEP JDBC data cartridge supports arbitrarily complex SQL statements with the following restrictions:

  • You may use only native SQL types in the SELECT list of the SQL query.

  • You may not use user-defined types and complex database types in the SELECT list.

  • You must provide alias names for every SELECT list column in the SQL query.

For more information, see Section 17.1.3, "Datatype Mapping".


Note:

To use the Oracle CEP JDBC data cartridge, your data source must use Oracle JDBC driver version 11.2 or higher.

For more information, see "Configuring Access to a Different Database Driver or Driver Version" in the Oracle Fusion Middleware Administrator's Guide for Oracle Complex Event Processing


17.1.3 Datatype Mapping

This section describes Oracle CEP JDBC data cartridge datatype mapping.

For reference, consider the Oracle CEP JDBC data cartridge context function that Example 17-1 shows.

Example 17-1 Oracle CEP JDBC Data Cartridge SQL Statement

...
<jc:jdbc-ctx>
    <name>JdbcCartridgeOne</name> 
    <data-source>StockDS</data-source>
    <function name="getDetailsByOrderIdName">
        <param name="inpOrderId" type="int" />
        <param name="inpName" type="char" />
        <return-component-type>
            com.oracle.cep.example.jdbc_cartridge.RetEvent
        </return-component-type>
        <sql><![CDATA[
            SELECT
                Employee.empName as employeeName,
                Employee.empEmail as employeeEmail,
                OrderDetails.description as description
            FROM
                 PlacedOrders, OrderDetails , Employee
            WHERE
                PlacedOrders.empId = Employee.empId AND
                PlacedOrders.orderId = OrderDetails.orderId AND
                Employee.empName = :inpName AND
                PlacedOrders.orderId = :inpOrderId
        ]]></sql>
    </function>
</jc:jdbc-ctx>
...

For more information, see Section 17.1.2, "Scope".

17.1.4 Oracle CEP JDBC Data Cartridge Application Context

To use the Oracle CEP JDBC data cartridge, you must declare and configure one or more application-scoped JDBC cartridge context while developing an application, as described in the following steps:

17.1.4.1 Declare a JDBC Cartridge Context in the EPN File

To declare a JDBC cartridge context in the EPN file:

  1. Edit your Oracle CEP application EPN assembly file to add the required namespace and schema location entries as shown in Example 17-2.

  2. Add an entry with the tag jdbc-context in the EPN file and specify the id attribute, as shown in Example 17-3. The id represents the name of this application-scoped context and is used in CQL queries that reference functions defined in this context. The id is also used when this context is configured in the application configuration file.

Example 17-2 EPN Assembly File: Oracle CEP JDBC Data Cartridge Namespace and Schema Location

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:osgi="http://www.springframework.org/schema/osgi"
       xmlns:wlevs="http://www.bea.com/ns/wlevs/spring"
       xmlns:jdbc="http://www.oracle.com/ns/ocep/jdbc"
       xsi:schemaLocation="
  http://www.springframework.org/schema/beans
  http://www.springframework.org/schema/beans/spring-beans.xsd
  http://www.springframework.org/schema/osgi
  http://www.springframework.org/schema/osgi/spring-osgi.xsd
  http://www.bea.com/ns/wlevs/spring
  http://www.bea.com/ns/wlevs/spring/spring-wlevs-v11_1_1_6.xsd"
  http://www.oracle.com/ns/ocep/jdbc
  http://www.oracle.com/ns/ocep/jdbc/ocep-jdbc.xsd">

Example 17-3 shows how to create an Oracle CEP JDBC data cartridge application context named JdbcCartridgeOne in an EPN assembly file.

Example 17-3 jdbc:jdbc-context Element in EPN Assembly File

<jdbc:jdbc-context id="JdbcCartridgeOne"/>

17.1.4.2 Configure the JDBC Cartridge Context in the Application Configuration File

To configure the JDBC cartridge context, add the configuration details in the component configuration file that is typically placed under the application's /wlevs directory. This configuration is similar to configuring other EPN components such as channel and processor.

To configure the JDBC cartridge context in the application configuration file:

  1. Before adding the JDBC context configuration, add the required namespace entry to the configuration XML file, as shown in the following example:

    <?xml version="1.0" encoding="UTF-8"?>
    <jdbcctxconfig:config xmlns:jdbcctxconfig="http://www.bea.com/ns/wlevs/config/application"
        xmlns:jc="http://www.oracle.com/ns/ocep/config/jdbc">
    
  2. The JDBC cartridge context configuration is done under the parent level tag jdbc-ctx. A context defines one or more functions, each of which is associated with a single SQL query. The configuration also specifies the data source representing the database against which the SQL queries are to be executed. Each function can have input parameters that are used to pass arguments to the SQL query defining the function, and each function specifies the return-component-type. Since the call to this function is always enclosed within a TABLE clause, the function always returns a Collection type. The return-component-type property indicates the type of the component of that collection.

    The value of the name property must match the value used for the id attribute in the EPN file, as shown in Example 17-3.

    Example 17-4 shows how to reference the jdbc:jbdc-context in an Oracle CQL query. In this case, the query uses link name JdbcCartridgeOne (defined in Example 17-3) to propagate this application context to the Oracle CEP JDBC data cartridge. The Oracle CQL query in Example 17-4 invokes the function getDetailsByOrderIdName associated with Oracle CEP JDBC data cartridge application context JdbcCartridgeOne.

    Example 17-4 jc:jdbc-ctx Element in Component Configuration File

    ...
    <jc:jdbc-ctx>
        <name>JdbcCartridgeOne</name> 
        <data-source>StockDS</data-source>
        <function name="getDetailsByOrderIdName">
            <param name="inpOrderId" type="int" />
            <param name="inpName" type="char" />
            <return-component-type>
                com.oracle.cep.example.jdbc_cartridge.RetEvent
            </return-component-type>
            <sql><![CDATA[
                SELECT
                    Employee.empName as employeeName,
                    Employee.empEmail as employeeEmail,
                    OrderDetails.description as description
                FROM
                     PlacedOrders, OrderDetails , Employee
                WHERE
                    PlacedOrders.empId = Employee.empId AND
                    PlacedOrders.orderId = OrderDetails.orderId AND
                    Employee.empName = :inpName AND
                    PlacedOrders.orderId = :inpOrderId
            ]]></sql>
        </function>
    </jc:jdbc-ctx>
    ...
    <processor>
            <name>Proc</name>
            <rules>
                <query id="q1"><![CDATA[
                    RStream(
                       select
                         currentOrder.orderId,
                         details.orderInfo.employeeName,
                         details.orderInfo.employeeemail,
                         details.orderInfo.description
                       from
                         OrderArrival[now] as currentOrder,
                         TABLE(getDetailsByOrderIdName@JdbcCartridgeOne(
                                   currentOrder.orderId, currentOrder.empName
                               ) as orderInfo
                         ) as details
                    )
                ]]></query>
            </rules>
    </processor>
    ...
    

For more information, see "How to Configure Oracle CEP JDBC Data Cartridge Application Context" in the Oracle Fusion Middleware Developer's Guide for Oracle Complex Event Processing for Eclipse.

17.2 Using the Oracle CEP JDBC Data Cartridge

In general, you use the Oracle CEP JDBC data cartridge as follows:

  1. Declare and define an Oracle CEP JDBC cartridge application-scoped context.

    For more information, see Section 17.1.4, "Oracle CEP JDBC Data Cartridge Application Context".

  2. Define one or more SQL statements in the jc:jdbc-ctx element in the component configuration file.

    For more information, see Section 17.2.1, "Defining SQL Statements: function Element."

  3. If you specify the function element return-component-type child element as a Java bean, implement the bean and ensure that the class is on your Oracle CEP application classpath.

    Example 17-5 shows a typical implementation.

    Example 17-5 Example return-component-type Class

    package com.oracle.cep.example.jdbc_cartridge;
     
    public class RetEvent
    {
        public String employeeName;
        public String employeeEmail;
        public String description;
    
        /* Default constructor is mandatory */
        public RetEvent1() {}
    
        /* May contain getters and setters for the fields */
    
        public String getEmployeeName() {
            return this.employeeName;
        }
    
        public void setEmployeeName(String employeeName) {
            this.employeeName = employeeName;
        }
    
        ...
    
        /* May contain other helper methods */
    
        public int getEmployeeNameLength() {
            return employeeName.length();
        }
    }
    

    You must declare the fields as public.

    The return-component-type class for a JDBC cartridge context function must have a one-to-one mapping for fields in the SELECT list of the SQL query that defines the function. In other words, every field in the SELECT list of the SQL query defining a function must have a corresponding field (matching name) in the Java class that is declared to be the return-component-type for that function; otherwise Oracle CEP throws an error. For example, note how the SELECT items in the function in Example 17-4 match the field names in Example 17-5.

    For more information, see:

  4. Define one or more Oracle CQL queries that call the SQL statements defined in the jc:jdbc-ctx element using the Oracle CQL TABLE clause and access the returned results by SQL SELECT list alias names.

    For more information, see Section 17.2.2, "Defining Oracle CQL Queries With the Oracle CEP JDBC Data Cartridge."

17.2.1 Defining SQL Statements: function Element

Within the jc:jdbc-cxt element in the component configuration file, you can define a JDBC cartridge context function using the function child element as Example 17-6 shows.

Example 17-6 Oracle CEP JDBC Data Cartridge SQL Statement

...
<jc:jdbc-ctx>
    <name>JdbcCartridgeOne</name> 
    <data-source>StockDS</data-source>
    <function name="getDetailsByOrderIdName">
        <param name="inpOrderId" type="int" />
        <param name="inpName" type="char" />
        <return-component-type>
            com.oracle.cep.example.jdbc_cartridge.RetEvent
        </return-component-type>
        <sql><![CDATA[
            SELECT
                Employee.empName as employeeName,
                Employee.empEmail as employeeEmail,
                OrderDetails.description as description
            FROM
                 PlacedOrders, OrderDetails , Employee
            WHERE
                PlacedOrders.empId = Employee.empId AND
                PlacedOrders.orderId = OrderDetails.orderId AND
                Employee.empName = :inpName AND
                PlacedOrders.orderId = :inpOrderId
        ]]></sql>
    </function>
</jc:jdbc-ctx>
...

You may define one or more function elements within a given jc:jdbc-cxt element.

This section describes:

17.2.1.1 function Element Attributes

Each function element supports the attributes that Table 17-1 lists.

Table 17-1 function Element Attributes

AttributeDescription

name

The name of the JDBC cartridge context function.

The combination of name and signature must be unique within a given Oracle CEP JDBC data cartridge application context. For more information, see Section 17.2.1.3.4, "Overloading JDBC Cartridge Context Functions".


17.2.1.2 function Element Child Elements

Each function element supports the following child elements:

17.2.1.2.1 param

The param child element specifies an optional input parameter.

The SQL statement may take zero or more parameters. Each parameter is defined in a param element.

The param child element supports the attributes that Table 17-2 lists.

Table 17-2 param Element Attributes

AttributeDescription

name

The name of the input parameter.

A valid parameter name is formed by a combination of A-Z,a-z,0-9 and _ (underscore).

type

The data type of the parameter.


Datatype Support – You may specify only Oracle CQL native com.bea.wlevs.ede.api.Type data types for the input parameter param element type attribute.


Note:

Datatype names are case sensitive. Use the case that the com.bea.wlevs.ede.api.Type class specifies.


For more information, see Table 17-3.

17.2.1.2.2 return-component-type

The return-component-type child element specifies the return type of the function. This child element is mandatory.

This represents the component type of the collection type returned by the JDBC data cartridge function. Because the function is always called from within an Oracle CQL TABLE clause, it always returns a collection type.

For more information, see Section 17.2.2.2, "Using the TABLE Clause."

Datatype Support – You may specify any one of the following types as the value of the return-component-type element:

  • Oracle CQL native com.bea.wlevs.ede.api.Type datatype.

  • Oracle CQL extensible Java cartridge type, such as a Java bean.

For more information, see:

17.2.1.2.3 sql

The sql child element specifies a SQL statement. This child element is mandatory.

Each function element may contain one and only one, single-line, SQL statement. You define the SQL statement itself within a <![CDATA[]]> block.

Within the SQL statement, you specify input parameters by param element name attribute using a colon (:) prefix as shown in Example 17-6.


Note:

You must provide alias names for every SELECT list column in the JDBC cartridge context function.


Datatype SupportTable 17-3 lists the SQL types you may use in your Oracle CEP JDBC data cartridge context functions and their corresponding Oracle CEP Java type and com.bea.wlevs.ede.api.Type type.

Table 17-3 SQL Column Types and Oracle CEP Type Equivalents

SQL TypeOracle CEP Java Typecom.bea.wlevs.ede.api.Type

NUMBER

java.math.BigDecimal

bigdecimal

NUMBER

long

bigint

RAW

byte[]

byte

CHAR, VARCHAR

java.lang.String

char

NUMBER

double

double

FLOAT, NUMBER

float

float

INTEGER, NUMBER

int

int

TIMESTAMP

java.sql.Timestamp

timestamp



Note:

In cases where the size of the Java type exceeds that of the SQL type, your Oracle CEP application must restrict values to the maximum size of the SQL type. The choice of type to use on the CSZQL side should be driven by the range of values in the database column. For example, if the SQL column is a number that contains values in the range of integer, use the "int" type on CQL side. If you choose an incorrect type and encounter out-of-range values, Oracle CEP throws a numeric overflow error.



Note:

The Oracle CEP JDBC data cartridge does not support Oracle Spatial data types.


For more information, see Section 17.2.1.3, "function Element Usage."

17.2.1.3 function Element Usage

This section provides examples of different JDBC cartridge context functions you can define using the Oracle CEP JDBC data cartridge, including:

17.2.1.3.1 Multiple Parameter JDBC Cartridge Context Functions

Using the Oracle CEP JDBC data cartridge, you can define JDBC cartridge context functions that take multiple input parameters.

Example 17-7 shows an Oracle CEP JDBC data cartridge application context that defines an JDBC cartridge context function that takes two input parameters.

Example 17-7 Oracle JDBC Data Cartridge Context Functions With Multiple Parameters

...
<function name="getDetailsByOrderIdName">
    <param name="inpOrderId" type="int" />
    <param name="inpName" type="char" />
    <return-component-type>
        com.oracle.cep.example.jdbc_cartridge.RetEvent
    </return-component-type>
    <sql><![CDATA[
              SELECT
                    Employee.empName as employeeName,
                    Employee.empEmail as employeeEmail,
                    OrderDetails.description as description
              FROM
                     PlacedOrders, OrderDetails , Employee
              WHERE
                    PlacedOrders.empId = Employee.empId AND
                    PlacedOrders.orderId = OrderDetails.orderId AND
                    Employee.empName = :inpName AND
                    PlacedOrders.orderId = :inpOrderId
    ]]></sql>
</function>
...
17.2.1.3.2 Invoking PL/SQL Functions

Using the Oracle CEP JDBC data cartridge, you can define JDBC cartridge context functions that invoke PL/SQL functions that the database defines.

Example 17-8 shows an Oracle CEP JDBC data cartridge application context that defines a JDBC cartridge context function that invokes PL/SQL function getOrderAmt.

Example 17-8 Oracle JDBC Data Cartridge Context Function Invoking PL/SQL Functions

...
<function name="getOrderAmount">
    <param name="inpId" type="int" />
    <return-component-type>
        com.oracle.cep.example.jdbc_cartridge.RetEvent
    </return-component-type>
    <sql><![CDATA[
            SELECT getOrderAmt(:inpId) as orderAmt
            FROM dual 
    ]]></sql>
</function>
...
17.2.1.3.3 Complex JDBC Cartridge Context Functions

Using the Oracle CEP JDBC data cartridge, you can define arbitrarily complex JDBC cartridge context functions including subqueries, aggregation, GROUP BY, ORDER BY, and HAVING.

Example 17-9 shows an Oracle CEP JDBC data cartridge application context that defines a complex JDBC cartridge context function.

Example 17-9 Oracle CEP JDBC Data Cartridge Complex JDBC Cartridge Context Function

...
<function name="getHighValueOrdersPerEmp">
    <param name="limit" type="int"/>
    <param name="inpName" type="char"/>
    <return-component-type>
        com.oracle.cep.example.jdbc_cartridge.RetEvent
    </return-component-type>
        <sql><![CDATA[
            select description as description,  sum(amt) as totalamt, count(*) as numTimes
            from  OrderDetails
                where orderid in (
                    select orderid from PlacedOrders where empid in (
                        select empid from Employee where  empName = :inpName
                    )
                )
            group by description 
            having sum(amt) > :limit
        ]]></sql>
</function> 
...
17.2.1.3.4 Overloading JDBC Cartridge Context Functions

Using the Oracle CEP JDBC data cartridge, you can define JDBC cartridge context functions with the same name in the same application context provided that each function has a unique signature.

Example 17-10 shows an Oracle CEP JDBC data cartridge application context that defines two JDBC cartridge context functions named getDetails. Each function is distinguished by a unique signature.

Example 17-10 Oracle JDBC Data Cartridge Context Function Overloading

<jc:jdbc-ctx>
    <name>JdbcCartridgeOne</name> 
    <data-source>StockDS</data-source>
         <function name="getDetails">
            <param name="inpName" type="char" />
            <return-component-type>
                com.oracle.cep.example.jdbc_cartridge.RetEvent
            </return-component-type>
            <sql><![CDATA[
                      SELECT
                             Employee.empName as employeeName,
                             Employee.empEmail as employeeEmail,
                             OrderDetails.description as description
                      FROM
                             PlacedOrders, OrderDetails , Employee
                      WHERE
                             PlacedOrders.empId = Employee.empId AND
                             PlacedOrders.orderId = OrderDetails.orderId AND
                             Employee.empName=:inpName
                      ORDER BY <!—SQL query using ORDER BY -->
                        description desc
            ]]></sql>
        </function>
        <function name="getDetails">
            <param name="inpOrderId" type="int" />
            <sql><![CDATA[
                      SELECT
                             Employee.empName as employeeName,
                             Employee.empEmail as employeeEmail,
                             OrderDetails.description as description
                      FROM
                             PlacedOrders, OrderDetails , Employee
                      WHERE
                             PlacedOrders.empId= Employee.empId AND
                             PlacedOrders.orderId = OrderDetails.orderId AND
                             PlacedOrders.orderId = :inpOrderId
            ]]></sql>
        </function>
</jc:jdbc-ctx>

17.2.2 Defining Oracle CQL Queries With the Oracle CEP JDBC Data Cartridge

This section describes how to define Oracle CQL queries that invoke SQL statements using the Oracle CEP JDBC data cartridge, including:

For more information, see "Configuring Oracle CQL Processors" in the Oracle Fusion Middleware Developer's Guide for Oracle Complex Event Processing for Eclipse.

17.2.2.1 Using SELECT List Aliases

Consider the Oracle CEP JDBC data cartridge context function that Example 17-11 shows.

Example 17-11 Oracle CEP JDBC Data Cartridge Context Function

<jc:jdbc-ctx>
    <name>JdbcCartridgeOne</name> 
    <data-source>StockDS</data-source>
        <function name="getDetailsByOrderIdName">
            <param name="inpOrderId" type="int" />
            <param name="inpName" type="char" />
            <return-component-type>
                com.oracle.cep.example.jdbc_cartridge.RetEvent
            </return-component-type>
            <sql><![CDATA[
                    SELECT
                            Employee.empName as employeeName,
                            Employee.empEmail as employeeEmail,
                            OrderDetails.description as description
                    FROM
                            PlacedOrders, OrderDetails , Employee
                    WHERE
                            PlacedOrders.empId = Employee.empId AND
                            PlacedOrders.orderId = OrderDetails.orderId AND
                            Employee.empName = :inpName AND
                            PlacedOrders.orderId = :inpOrderId
            ]]></sql>
        </function>
</jc:jdbc-ctx>

You must assign an alias to each column in the SELECT list. When you invoke the JDBC cartridge context function in an Oracle CQL query, you access the columns in the result set by their SQL SELECT list aliases.

For more information, see Section 17.2.2.2, "Using the TABLE Clause".

17.2.2.2 Using the TABLE Clause

Consider the Oracle CEP JDBC data cartridge SQL statement that Example 17-12 shows.

Example 17-12 Oracle CEP JDBC Data Cartridge SQL Statement

...
<jc:jdbc-ctx>
    <name>JdbcCartridgeOne</name> 
    <data-source>StockDS</data-source>
    <function name="getDetailsByOrderIdName">
        <param name="inpOrderId" type="int" />
        <param name="inpName" type="char" />
        <return-component-type>
            com.oracle.cep.example.jdbc_cartridge.RetEvent
        </return-component-type>
        <sql><![CDATA[
            SELECT
                Employee.empName as employeeName,
                Employee.empEmail as employeeEmail,
                OrderDetails.description as description
            FROM
                 PlacedOrders, OrderDetails , Employee
            WHERE
                PlacedOrders.empId = Employee.empId AND
                PlacedOrders.orderId = OrderDetails.orderId AND
                Employee.empName = :inpName AND
                PlacedOrders.orderId = :inpOrderId
        ]]></sql>
    </function>
</jc:jdbc-ctx>
...

The Oracle CQL query in Example 17-13 invokes the JDBC cartridge context function that Example 17-12 defines.

Example 17-13 Oracle CQL Query Invoking an Oracle CEP JDBC Data Cartridge Context Function

<processor>
        <name>Proc</name>
        <rules>
            <query id="q1"><![CDATA[
                RStream(
                   select
                     currentOrder.orderId,
                     details.orderInfo.employeeName,
                     details.orderInfo.employeeemail,
                     details.orderInfo.description
                     details.orderInfo.getEmployeeNameLength()
                   from
                     OrderArrival[now] as currentOrder,
                     TABLE(getDetailsByOrderIdName@JdbcCartridgeOne(
                               currentOrder.orderId, currentOrder.empName
                           ) as orderInfo
                     ) as details
                )
            ]]></query>
        </rules>
</processor>

You must wrap the Oracle CEP JDBC data cartridge context function invocation in an Oracle CQL query TABLE clause.

You access the result set using:

TABLE_CLAUSE_ALIAS.JDBC_CARTRIDGE_FUNCTION_ALIAS.SQL_SELECT_LIST_ALIAS
or
TABLE_CLAUSE_ALIAS.JDBC_CARTRIDGE_FUNCTION_ALIAS.METHOD_NAME

Where:

  • TABLE_CLAUSE_ALIAS: the outer AS alias of the TABLE clause.

    In Example 17-13, details.

  • JDBC_CARTRIDGE_FUNCTION_ALIAS: the inner AS alias of the JDBC cartridge context function.

    In Example 17-13, orderInfo.

  • SQL_SELECT_LIST_ALIAS: the JDBC cartridge context function SELECT list alias.

    In Example 17-12, employeeName, employeeEmail, and description.

  • METHOD_NAME: the name of the method that the return-component-type class provides.

    In Example 17-13, getEmployeeNameLength().

As Example 17-13 shows, you access the JDBC cartridge context function result set in the Oracle CQL query using:

details.orderInfo.employeeName
details.orderInfo.employeeemail
details.orderInfo.description
details.orderInfo.getEmployeeNameLength()

The component type of the collection type returned by the JDBC data cartridge function is defined by the function element return-component-type child element. Because the function is always called from within an Oracle CQL TABLE clause, it always returns a collection type. If the getDetailsByORderIdName JDBC cartridge context function called in Example 17-13 is defined as Example 17-12 shows, then orderInfo is of type com.oracle.cep.example.jdbc_cartridge.RetEvent.

You can access both fields and methods of the return-component-type in an Oracle CQL query. In Example 17-12, the return-component-type specifies a Java bean implemented as Example 17-14 shows.

Example 17-14 Example return-component-type Class

package com.oracle.cep.example.jdbc_cartridge;
 
public class RetEvent
{
    String employeeName;
    String employeeEmail;
    String description;

    /* Default constructor is mandatory */
    public RetEvent1() {}

    /* May contain getters and setters for the fields */

    public String getEmployeeName() {
        return this.employeeName;
    }

    public void setEmployeeName(String employeeName) {
        this.employeeName = employeeName;
    }

    ...

    /* May contain other helper methods */

    public int getEmployeeNameLength() {
        return employeeName.length();
    }
}

This class provides helper methods, like getEmployeeNameLength, that you can invoke within the Oracle CQL query.

For more information, see:

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

Following is a JDBC cartridge context that defines a function that has a native CQL type bigint as return-component-type.

Example 17-15 CQL Type bigint as a return-component-type

<jc:jdbc-ctx>
    <name>JdbcCartridgeOne</name>
    <data-source>myJdbcDataSource</data-source>
    <function name="getOrderAmt">
       <param name="inpId" type="int" />
       <return-component-type>bigint</return-component-type> <!-- native CQL as return component type -->
       <sql><![CDATA[
                SELECT
                  getOrderAmt(:inpId) as orderAmt
                FROM (select :inpId as iid from
                  dual)]]>
       </sql>
    </function>
</jc:jdbc-ctx>

Example 17-16 shows how the getOrderAmt function in Example 17-15 can be used in a CQL query.

Example 17-16 getOrderAmt Function in a CQL Query

<query id="q1"><![CDATA[
                 RStream(
                   select
                     currentOrder.orderId,
                     details.orderInfo as orderAmt
                   from
                     OrderArrival[now] as currentOrder,
                     TABLE(getOrderAmt@JdbcCartridgeTwo(currentOrder.orderId) as orderInfo of bigint) as details
                 )
 ]]></query>

Note that the alias orderInfo itself is of type bigint and can be accessed as details.orderInfo as orderAmt in the select list of the CQL query.

The "of bigint" clause used inside the TABLE construct is optional. If specified, the type mentioned should match the return-component-type, which is bigint in Example 17-15.

PK7PKO_\EOEBPS/index.htm Index

Index

A  B  C  D  E  F  G  H  I  J  K  L  M  N  O  P  Q  R  S  T  U  V  W  X  Y 

Symbols

-
arithmetic operator negative, 4.1.2
arithmetic operator subtraction, 4.1.2
relation deletion, 1.1.1.3
()
grouping pattern operator, 19.3.2
*
arithmetic operator multiply, 4.1.2
maximal pattern quantifier (0 or more times), 19.3.1
used with count function, 5.1, 5.1, 9.1.1, 9.1.1, 19.1.3.5, 19.1.3.5
used with select clause, 20.1
*?
minimal pattern quantifier (0 or more times), 19.3.1
+
arithmetic operator addition, 4.1.2
arithmetic operator positive, 4.1.2
maximal pattern quantifier (1 or more times), 19.3.1
relation insertion, 1.1.1.3
+?
minimal pattern quantifier (1 or more times), 19.3.1
:n
parameterized query placeholder, 18.2.11
?
maximal pattern quantifier (0 or 1 time), 19.3.1
??
minimal pattern quantifier (0 or 1 time), 19.3.1
|
alternation pattern operator, 19.3.2
||
concatenation operator, 4.1.2, 4.1.2

A

abs function, 12.1
abs1 function, 12.1
abs2 function, 12.1
abs3 function, 12.1
acos function, 12.1
aggr_distinct_expr syntax, 5.1
aggr_expr syntax, 5.1
aggregates
correlation variable restrictions, 19.1.3.2, 19.1.3.3, 19.1.3.4, 19.1.3.5
count in MATCH_RECOGNIZE clause, 19.1.3.5
expressions, 5.1, 5.1
final, 19.1.3.1
first in MATCH_RECOGNIZE clause, 19.1.3.6
functions, built-in, 9
functions, Colt built-in, 11
last in MATCH_RECOGNIZE clause, 19.1.3.6
prev in MATCH_RECOGNIZE clause, 19.1.4
referencing in MATCH_RECOGNIZE clause, 19.1.3
running, 19.1.3.1
XML aggregate expressions, 5.1
AggregationFunctionFactory, 13.2.2
aliases
about, 2.7
ALIASES element, 2.7.2
AS operator, 2.7.1
columns, 2.7.1.1
stream elements, 2.7.1.1
type aliases, 2.7.2.1
window operators, 2.7.1.2
ALL MATCHES clause
about, 19.7
partial overlapping patterns, 19.7
total overlapping patterns, 19.7
ALL operator, 6.2
alternation operator, 4.1.2
AND condition, 6.3, 6.3
ANY operator, 6.2
ANYINTERACT geometric relation operator, 16.2.7
API
AggregationFunctionFactory, 13.2.2
application context
data cartridges, 14.1.2
Oracle JDBC data cartridge, 17.1.4
Oracle Spatial, 16.1.4
application time, 1.1.13
application timestamped, 1.1.13
APPLICATION_NO_AUTO_IMPORT_CLASS_SPACE, 15.1.2.2
arguments of operators, 4
arith_expr syntax, 5.1
arith_expr_list syntax, 5.1
array_type
clause, 7.1
AS
alias operator, 2.7.1, 2.7.1.2
correlation_name_definition syntax, 19.4
measure_column syntax, 19.2
asc_desc syntax, 20.1
asin function, 12.1
atan function, 12.1
atan2 function, 12.1
attr
clause, 7.1
syntax, 7.1
attrspec
clause, 7.1
syntax, 7.1
autoCorrelation function, 11.1.2
avg function, 9.1.1

B

base relation, 1.1.1.2
base stream, 1.1.1.2
beta function, 10.1
beta1 function, 10.1
betaComplemented function, 10.1
BETWEEN conditions, 6.5
between_condition syntax, 6.5
BIGINT datatype, 2.1.1
binary
clause, 20.1
syntax, 20.1
binary operators, 4.1.1
bindings element, 18.2.11.2
binomial function, 10.1
binomial1 function, 10.1
binomial2 function, 10.1
binomialComplemented function, 10.1
bitMaskWithBitsSetFromTo function, 10.1
BOOLEAN datatype, 2.1.1
bufferPolygon Geometry method, 16.2.7
built-in datatypes, 2.1.1
built-in functions
about, 1.1.11
aggregate
about, 9
distinct, 9.1
nested, 9.1
where, group by, and having clause, 9.1.1, 9.1.1
Colt, 1.1.11, 1.1.11, 10, 11
where, group by, and having clause, 11.1.2
java.lang.Math, 1.1.11, 12
single-row
about, 8
built-in windows
about, 1.1.3
queries, 18.2.3
builtin_aggr syntax, 9.1
builtin_aggr_incr syntax, 9.1
BYTE datatype, 2.1.1

C

cache, 1.1.10
Oracle CQL queries, 18.5
Oracle CQL user-defined functions, 13.1.3
cache queries, 18.2.8
case_expr syntax, 5.1
cbrt function, 12.1
CDATA, 1.2.1
ceil function, 10.1
ceil1 function, 12.1
CEP DDL
use, 1.2.1
channels
query selector, 1.1.1.1.4
stream, 1.1.1.1.1
CHAR datatype, 2.1.1
character sets and multibyte characters, 2.8.1
chiSquare function, 10.1
chiSquareComplemented function, 10.1
class_name
clause, 7.1, 7.1
classpath
Oracle CEP Service Engine, 13.1, 13.2.1, 13.2.2
single-row user-defined functions, 13.2.1, 13.2.2
user-defined functions, 13.1
Colt built-in functions, 1.1.11, 1.1.11, 10, 11
where, group by, and having clause, 11.1.2
column aliases, 2.7.1.1
comments
CQL, 1.2.1, 2.6
XML, 8.1
comparison conditions
about, 6.2
simple, 6.2
comparison rules
character values, 2.2.3
datatypes, 2.2
date value, 2.2.2
complex_type
clause, 7.1
compound conditions, 6.7
compound_conditions syntax, 6.7
concat function, 8.1
concatenation operator, 4.1.2, 8.1
condition syntax, 6.2
conditions
about, 6
BETWEEN, 6.5
comparison
about, 6.2
simple, 6.2
compound, 6.7
compound_conditions syntax, 6.7
in, 6.8
logical
about, 6.3
AND, 6.3
NOT, 6.3
OR, 6.3
XOR, 6.3
nulls, 2.5.2, 6.6
pattern-matching
LIKE, 6.4
lk function, 8.1
precedence, 6.1.1
range, 6.5
const_bigint
clause, 7.1
syntax, 7.1
const_int
clause, 7.1
syntax, 7.1
const_string
clause, 7.1
quotation marks, 2.3.1
syntax, 7.1
text literals, 2.3.1
const_value
clause, 7.1
syntax, 7.1
CONTAIN geometric relation operator, 16.2.7
content, 5.1
Continuous Query Language. See CQL
conversion, 2.2.4
correlation function, 11.1.2
correlation variables, 19.1
correlation_name syntax, 19.3.1
correlation_name_definition syntax, 19.4
cos function, 12.1
cosh function, 12.1
count function, 9.1.1
covariance function, 11.1.2
CQL, 1.2.1, 1.2.1, 1.2.1, 1.2.1, 1.2.1
aliases
about, 2.7
ALIASES element, 2.7.2
AS operator, 2.7.1
type aliases, 2.7.2.1
comments, 1.2.1, 2.6
conditions, 6
.cqlx files, 1.2.1
datatype comparison rules, 2.2
datatypes, 2.1
expressions, 5
format models, 2.4
joins, 18
lexical conventions, 1.2.1
literals, 2.3
MATCH_RECOGNIZE, 19
naming rules, 2.8.1
nulls
about, 2.5
in comparison conditions, 2.5.2
in functions, 2.5.1
operators, 4
Oracle tools support of, 1.4
pattern recognition
about, 1.1.7, 19
pseudocolumns
about, 3
attr clause, 7.1
ELEMENT_TIME, 3.2
queries, 18
syntax, 1.2.3
views, 18
CQL data cartridge statements
array_type clause, 7.1
class_name clause, 7.1, 7.1
complex_type clause, 7.1
data_cartridge_name clause, 5.1
fieldname clause, 7.1, 7.1
link clause, 5.1
l-value clause, 7.1
methodname clause, 7.1
package_name clause, 7.1, 7.1
param_list clause, 7.1
qualified_type_name clause, 7.1
CQL statements
about, 1.2
array_type clause, 7.1
attr clause, 7.1
attrspec clause, 7.1
binary clause, 20.1
class_name clause, 7.1, 7.1
const_bigint clause, 7.1
const_int clause, 7.1
const_string clause, 7.1
const_value clause, 7.1
data_cartridge_name clause, 5.1
fieldname clause, 7.1, 7.1
identifier clause, 7.1
IN and NOT IN, 20.1
INTERSECT, 20.1
lexical conventions, 1.2.1
link clause, 5.1
l-value clause, 7.1
methodname clause, 7.1
MINUS, 20.1
non_mt_arg_list clause, 7.1
non_mt_attr_list clause, 7.1
non_mt_attrname_list clause, 7.1
non_mt_attrspec_list clause, 7.1
non_mt_cond_list clause, 7.1
package_name clause, 7.1, 7.1
param_list clause, 7.1
qualified_type_name clause, 7.1
query, 20.1
query_ref clause, 7.1
relation_variable, 20.1
set, 20.1
syntax conventions, 1.2.3
time_spec clause, 7.1
UNION and UNION ALL, 20.1
view, 20.1
xml_attr_list clause, 7.1
xml_attribute_list clause, 7.1
xqryargs_list clause, 7.1
.cqlx
case, 1.2.1
CDATA, 1.2.1
CEP DDL use, 1.2.1
comments, 1.2.1
lexical conventions, 1.2.1
rules, 1.2.1
statement terminator, 1.2.1
whitespace, 1.2.1
createElemInfo Geometry method, 16.2.7, 16.2.7
createGeometry Geometry method, 16.2.7
createLinearPolygon Geometry method, 16.2.7
createPoint Geometry method, 16.2.7
createRectangle Geometry method, 16.2.7

D

data cartridges
about, 1.1.12, 14.1
application context, 14.1.2
complex_type
constructor invocation, 7.1
field access, 7.1
instantiation, 7.1
method access, 7.1
data cartridge name
java, 15.1.1
jdbc, 17.1.1
spatial, 16.1.1
datatypes, and, 2.1.2
Oracle CQL queries, 18.7
Oracle JDBC data cartridge
application context, 17.1.4
Oracle Spatial
application context, 16.1.4
TABLE query, 18.2.7, 20.1
types
Java, 15.1
Oracle JDBC, 17.1
Oracle Spatial, 16.1
view schema, 20.1
data destinations
about, 1.1.8, 1.1.8.2
data sources
cache, 1.1.10
function table, 1.1.9.3
relational database table, 1.1.9.1
table, 1.1.9
XML table, 1.1.9.2
data_cartridge_name
clause, 5.1
datatype syntax, 2.1
datatypes
about, 2.1
aliases, 2.7.2.1
BIGINT, 2.1.1
BOOLEAN, 2.1.1
built-in, 2.1.1
BYTE, 2.1.1
CHAR, 2.1.1
comparison rules, 2.2.1
about, 2.2
character values, 2.2.3
conversion
about, 2.2.4
explicit, 2.2.4.2
implicit, 2.2.4.1
JDBC, 2.2.4.3
SQL, 2.2.4.3
user-defined functions, 2.2.4.4, 2.2.4.5, 13.1.2
data cartridges, 2.1.2
date value comparison rules, 2.2.2
DOUBLE, 2.1.1
enum, 2.1.3
evaluating with functions, 2.1.3
FLOAT, 2.1.1
format models
about, 2.4
datetime, 2.4.2, 8.1
number, 2.4.1
INTEGER, 2.1.1
INTERVAL, 2.1.1
literals
about, 2.3
float, 2.3.2.2
integer, 2.3.2.1
interval, 2.3.4
interval day to second, 2.3.4.1
text, 2.3.1
timestamp, 2.3.3
mapping in user-defined functions, 13.1.2
OBJECT, 2.1.1
opaque, 2.1.1
Oracle JDBC data cartridge, 17.1.2
Oracle Spatial, 16.1.2.1
other, 2.1.2, 2.1.3
TIMESTAMP, 2.1.1
type aliases, 2.7.2.1
unsupported, 2.1.2, 2.1.3
user-defined functions, 13.1.2
XMLTYPE, 2.1.1
datetime literals
about, 2.3.3
xsd
dateTime, 2.3.3
day, 7.1
days, 7.1
DDL
query, 20.1
view, 20.1
decimal characters, 2.3.2.2
decode
in arithmetic expressions, 5.1
nulls, 2.5.2
decode syntax, 5.1
DEFINE clause
about, 19.4
correlation names, 19.4.2, 19.4.3
derived stream, 1.1.1.2, 1.1.1.2
distance Geometry method, 16.2.7
distinct
aggregate expressions, 5.1
built-in aggregate functions, 9.1
function expressions, 5.1
relations, 1.1.2
select_clause, 20.1
document, 5.1
DOUBLE datatype, 2.1.1
double quotes, 2.3.1
Dstream relation-to-stream operator, 4.1.2
DURATION clause, 19.9
DURATION MULTIPLES OF clause, 19.9
duration_clause syntax, 19.9

E

Eclipse, 1.4.2
enum datatypes, 2.1.3
equality test, 6.2
errorFunction function, 10.1
errorFunctionComplemented function, 10.1
event sinks
about, 1.1.8, 1.1.8.2
event sources
about, 1.1.8, 1.1.8.1
cache, 1.1.10
function table, 1.1.9.3
pull, 1.1.8.1, 18.2.8, 18.6
push, 1.1.8.1
relational database table, 1.1.9.1
table, 1.1.9
XML table, 1.1.9.2
exp function, 12.1
expm1 function, 12.1
expressions
about, 5
aggr_distinct_expr, 5.1
aggr_expr, 5.1
aggregate, 5.1, 5.1
aggregate distinct, 5.1
arith_expr, 5.1
arith_expr_list, 5.1
arithmetic, 5.1, 5.1
case, 5.1
case_expr, 5.1
decode, 5.1, 5.1
func_expr, 5.1
function, 5.1, 5.1, 5.1, 5.1, 5.1
object, 5.1
object_expr, 5.1
order, 5.1
order_expr, 5.1
xml_agg_expr, 5.1
xml_parse_expr, 5.1
xmlcolattval_expr, 5.1
xmlelement_expr, 5.1
xmlforest_expr, 5.1
extended_builtin_aggr syntax, 9.1

F

factorial function, 10.1
fieldname
clause, 7.1, 7.1
FILTER geometric filter operator, 16.2.7
first function, 9.1.1
fixed duration non-event detection, 19.9.1
fixed_length_datatype syntax, 2.1
FLOAT datatype, 2.1.1
floor function, 10.1
floor1 function, 12.1
format models
about, 2.4
datetime, 2.4.2, 8.1
number, 2.4.1
from_clause syntax, 18.2.1.3, 18.4.2, 20.1
func_expr syntax, 5.1
func_name syntax, 5.1
functions
abs, 12.1
abs1, 12.1
abs2, 12.1
abs3, 12.1
acos, 12.1
asin, 12.1
atan, 12.1
atan2, 12.1
autoCorrelation, 11.1.2
avg, 9.1.1
beta, 10.1
beta1, 10.1
betaComplemented, 10.1
binomial, 10.1
binomial1, 10.1
binomial2, 10.1
binomialComplemented, 10.1
bitMaskWithBitsSetFromTo, 10.1
cbrt, 12.1
ceil, 10.1
ceil1, 12.1
chiSquare, 10.1
chiSquareComplemented, 10.1
concat, 8.1
correlation, 11.1.2
cos, 12.1
cosh, 12.1
count, 9.1.1
covariance, 11.1.2
errorFunction, 10.1
errorFunctionComplemented, 10.1
exp, 12.1
expm1, 12.1
factorial, 10.1
first, 9.1.1
floor, 10.1
floor1, 12.1
gamma, 10.1
gamma1, 10.1
gammaComplemented, 10.1
geometricMean, 11.1.2
geometricMean1, 11.1.2
getseedatrowcolumn, 10.1
harmonicMean, 11.1.2
hash, 10.1
hash1, 10.1
hash2, 10.1
hash3, 10.1
hextoraw, 8.1
hypot, 12.1
i0, 10.1
i0e, 10.1
i1, 10.1
i1e, 10.1
IEEERemainder, 12.1
incompleteBeta, 10.1
incompleteGamma, 10.1
incompleteGammaComplement, 10.1
j0, 10.1
j1, 10.1
jn, 10.1
k0, 10.1
k0e, 10.1
k1, 10.1
k1e, 10.1
kn, 10.1
kurtosis, 11.1.2
lag1, 11.1.2
last, 9.1.1
leastSignificantBit, 10.1
length, 8.1
lk, 8.1
log, 10.1
log1, 12.1
log10, 10.1
log101, 12.1
log1p, 12.1
log2, 10.1
logFactorial, 10.1
logGamma, 10.1
longFactorial, 10.1
max, 9.1.1
mean, 11.1.2
meanDeviation, 11.1.2
median, 11.1.2
min, 9.1.1
moment, 11.1.2
mostSignificantBit, 10.1
negativeBinomial, 10.1
negativeBinomialComplemented, 10.1
normal, 10.1
normal1, 10.1
normalInverse, 10.1
nvl, 8.1
ordsgenerator, 16.2.7
poisson, 10.1
poissonComplemented, 10.1
pooledMean, 11.1.2
pooledVariance, 11.1.2
pow, 12.1
prev, 8.1
product, 11.1.2
quantile, 11.1.2
quantileInverse, 11.1.2
rankInterpolated, 11.1.2
rawtohex, 8.1
rint, 12.1
rms, 11.1.2
round, 12.1
round1, 12.1
sampleKurtosis, 11.1.2
sampleKurtosisStandardError, 11.1.2
sampleSkew, 11.1.2
sampleSkewStandardError, 11.1.2
sampleVariance, 11.1.2
signum, 12.1
signum1, 12.1
sin, 12.1
sinh, 12.1
skew, 11.1.2
sqrt, 12.1
standardDeviation, 11.1.2
standardError, 11.1.2
stirlingCorrection, 10.1
studentT, 10.1
studentTInverse, 10.1
sum, 9.1.1
sumOfInversions, 11.1.2
sumOfLogarithms, 11.1.2
sumOfPowerDeviations, 11.1.2
sumOfPowers, 11.1.2
sumOfSquaredDeviations, 11.1.2
sumOfSquares, 11.1.2
systemtimestamp, 8.1
tables, 1.1.9.3
tan, 12.1
tanh, 12.1
to_bigint, 8.1
to_boolean, 8.1
to_char, 8.1
to_double, 8.1
to_float, 8.1
to_timestamp, 8.1
todegrees, 12.1
toradians, 12.1
trimmedMean, 11.1.2
ulp, 12.1
ulp1, 12.1
variance, 11.1.2
weightedMean, 11.1.2
winsorizedMean, 11.1.2
xmlagg, 9.1.1
xmlcomment, 8.1
xmlconcat, 8.1
xmlexists, 8.1
xmlquery, 8.1
y0, 10.1
y1, 10.1
yn, 10.1
functions about
AggregationFunctionFactory, 13.2.2
categories, 1.1.11
datatype mapping, 13.1.2
distinct and aggregate built-in functions, 9.1
java.lang.Math, 1.1.11
naming rules, 1.1.11, 2.8.1, 13.1.1
nested aggregates, 9.1
nulls, 2.5.1
overloading, 1.1.11, 2.8.1, 13.1.1
overriding, 1.1.11, 2.8.1, 13.1.1
single-row built-in, 1.1.11
user-defined, 1.1.11

G

gamma function, 10.1
gamma1 function, 10.1
gammacomplemented function, 10.1
geometricMean function, 11.1.2
geometricMean1 function, 11.1.2
Geometry class, 16.1.3
get2dMbr Geometry method, 16.2.7
getseedatrowcolumn function, 10.1
greater than or equal to tests, 6.2
greater than tests, 6.2
group by
ELEMENT_TIME, 3.2.2.2
GROUP BY clause, 20.1
ORDER BY clause, 19.6
PARTITION BY clause, 19.5
partitioned window, 4.1.2, 4.1.2, 4.1.2
group match, 19.1.2

H

harmonicMean function, 11.1.2
hash function, 10.1
hash1 function, 10.1
hash2 function, 10.1
hash3 function, 10.1
HAVING clause, 20.1
heartbeat
system timestamped relations, 1.1.13
system timestamped streams, 1.1.13
hextoraw function, 8.1
hour, 7.1
hours, 7.1
hypot function, 12.1

I

i0 function, 10.1
i0e function, 10.1
i1 function, 10.1
i1e function, 10.1
identifier
clause, 7.1
syntax, 7.1
IEEERemainder function, 12.1
IN clause, 20.1
in conditions, 6.8
in_condition_membership syntax, 6.8.2
in_condition_set syntax, 20.1
INCLUDE TIMER EVENTS clause, 19.10
incompleteBeta function, 10.1
incompleteGamma function, 10.1
incompleteGammaComplement function, 10.1
incremental computation
about, 13.1.1.2
implementing, 13.2.2
run-time behavior, 13.2.2
inequality test, 6.2
inner joins, 18.4.1
INSIDE geometric relation operator, 16.2.7
INTEGER datatype, 2.1.1
integer syntax, 2.3.2.1
integers
in CQL syntax, 2.3.2.1
precision of, 2.3.2.1
INTERSECT clause, 20.1
INTERVAL datatype, 2.1.1
interval_value syntax, 2.3.4.1, 7.1
IS NOT NULL condition, 6.6
IS NULL condition, 6.6
is-total-order, 1.1.13
Istream relation-to-stream operator, 4.1.2

J

j0 function, 10.1
j1 function, 10.1
Java data cartridge
about, 15.1
class loading
about, 15.1.2
application class space policy, 15.1.2.1
example, 15.1.2.4
method resolution, 15.1.3
no automatic import class space policy, 15.1.2.2
server class space policy, 15.1.2.3
data cartridge name, 15.1.1
datatype mapping, 15.1.4
default package name, 15.1.1
java.lang package, 15.1.1
limitations, 15.1.5
method resolution, 15.1.3
Oracle CQL query support, 15.1.5
queries
limitations, 15.1.5
using exported Java classes, 15.2.2
using the Java API, 15.2.1
unqualified types, 15.1.1
java.lang.Math built-in functions, 12
jc:jdbc-ctx, 17.1.4.2
jdbc:jdbc-context, 17.1.4.1
jn function, 10.1
joins
about, 18, 18.4
inner, 18.4.1
left outer, 18.4.2, 18.4.2.1
outer, 18.4.2, 18.4.2.1, 18.4.2.2, 18.4.2.3
outer join look-back, 18.4.2.3
right outer, 18.4.2, 18.4.2.2
simple, 18.4.1
views, 18.3.1

K

k0 function, 10.1
k0e function, 10.1
k1 function, 10.1
k1e function, 10.1
keywords in object names, 2.8.1, 7.1, 7.1
kn function, 10.1
kurtosis function, 11.1.2

L

lag1 function, 11.1.2
last function, 9.1.1
leastSignificantBit function, 10.1
left outer joins, 18.4.2, 18.4.2.1
length function, 8.1
less than tests, 6.2
lexical conventions
about, 1.2.1
case, 1.2.1, 1.2.1
CDATA, 1.2.1, 1.2.1
CEP DDL use, 1.2.1, 1.2.1
comments, 1.2.1
.cqlx, 1.2.1
query, 1.2.1
statement terminator, 1.2.1, 1.2.1
view, 1.2.1
whitespace, 1.2.1, 1.2.1
LIKE condition, 6.4, 8.1
like_condition syntax, 6.4
link
clause, 5.1
literals, 2.3
lk function, 8.1
locale
decimal characters, 2.3.2.2
nonquoted identifiers, 2.8.1
ORDER BY, 18.2.9
RAWTOHEX, 8.1
text literals, 2.3.1
log function, 10.1
log1 function, 12.1
log10 function, 10.1
log101 function, 12.1
log1p function, 12.1
log2 function, 10.1
logFactorial function, 10.1
logGamma function, 10.1
logical conditions, 6.3
AND, 6.3
NOT, 6.3
OR, 6.3
XOR, 6.3
longFactorial function, 10.1
l-value
clause, 7.1

M

MATCH_RECOGNIZE clause
about, 19
aggregates
about, 19.1.3
correlation variable restrictions, 19.1.3.2, 19.1.3.3, 19.1.3.4, 19.1.3.5
count, 19.1.3.5
count(*), 19.1.3.5
count(identifier.*), 19.1.3.5
count(identifier.attr), 19.1.3.5
final, 19.1.3.1
first, 19.1.3.6
last, 19.1.3.6
prev, 19.1.4
running, 19.1.3.1
ALL MATCHES clause
about, 19.7
partial overlapping patterns, 19.7
total overlapping patterns, 19.7
correlation variables, 19.1
DEFINE clause, 19.4
DURATION clause, 19.9
DURATION MULTIPLES OF clause, 19.9
examples
non-event detection, fixed duration, 19.12.5
pattern detection, 19.12.1
pattern detection with aggregates, 19.12.3
pattern detection with partition by, 19.12.2
WITHIN clause, 19.12.4
group match, 19.1.2
INCLUDE TIMER EVENTS clause, 19.10
MEASURES clause, 19.2
ORDER BY clause, 19.6
PARTITION BY clause, 19.5
PATTERN clause
about, 19.3
alternation operator, 19.3.2
default, 19.3.1
group matches, 19.1.2
grouping operator, 19.3.2
quantifiers, 19.3.1
regular expressions, 19.3.1
singleton matches, 19.1.2
queries, 18.2.4
singleton match, 19.1.2
sub-clauses
optional, 19.1
principle, 19.1
SUBSET clause, 19.11
WHERE clause, 19.1.1
WITHIN clause, 19.8
WITHIN INCLUSIVE clause, 19.8
max function, 9.1.1
MBR
geometric index, 16.1.2.4
get2dMbr method, 16.2.7
getMBR method, 16.1.2.7.2
mean function, 11.1.2
meanDeviation function, 11.1.2
measure_column syntax, 19.2
MEASURES clause, 19.2
median function, 11.1.2
methodname
clause, 7.1
millisecond, 7.1
milliseconds, 7.1
min function, 9.1.1
Minimum Bounding Rectangle. See MBR
MINUS clause, 20.1
minute, 7.1
minutes, 7.1
moment function, 11.1.2
mostSignificantBit function, 10.1
multibyte characters, 2.8.1

N

naming rules
about, 2.8.1
NaN, 9.1.1
nanosecond, 7.1
nanoseconds, 7.1
negativeBinomial function, 10.1
negativeBinomialComplemented function, 10.1
NN geometric relation operator, 16.2.7
non_mt_arg_list
clause, 7.1
syntax, 7.1
non_mt_arg_list_set syntax, 6.8.2
non_mt_attr_list
clause, 7.1
syntax, 7.1
non_mt_attrname_list
clause, 7.1
syntax, 7.1
non_mt_attrspec_list
clause, 7.1
syntax, 7.1
non_mt_cond_list
clause, 7.1
syntax, 7.1
non_mt_corr_list syntax, 19.11
non_mt_corrname_definition_list syntax, 19.4
non_mt_measure_list syntax, 19.2
non_mt_projterm_list syntax, 20.1
non_mt_relation_list syntax, 20.1
non_mt_subset_definition_list syntax, 19.11
non-event detection
about, 19.12.5
fixed duration, 19.9.1, 19.12.5
recurring, 19.9.2
non-events, 19.12.5
normal function, 10.1
normal1 function, 10.1
normalInverse function, 10.1
NOT condition, 6.3, 6.3
NOT IN clause, 20.1
null_conditions syntax, 6.6
null_spec syntax, 20.1
nulls
about, 2.5
conditions, 6.6
decode, 2.5.2
in conditions, 2.5.3, 2.5.3
in functions, 2.5.1
IS NOT NULL condition, 6.6
IS NULL condition, 6.6
nvl function, 8.1
value conversion, 8.1
with comparison conditions, 2.5.2
number precision, 2.3.2.2
number syntax, 2.3.2.2
numeric literals
NaN, 9.1.1
numeric values
about, 2.2.1
comparison rules, 2.2.1
nvl function, 8.1

O

OBJECT datatype, 2.1.1
object names and keywords, 2.8.1, 7.1, 7.1
object_expr syntax, 5.1
OCEP_JAVA_CARTRIDGE_CLASS_SPACE, 15.1.2.2, 15.1.2.3
ON clause, 18.4.2
opaque data type, 2.1.1
operands, 4
operations
relation-to-stream, 1.1.4
stream-to-stream, 1.1.5
operators, 4
arithmetic, 4.1.2
binary, 4.1.1
concatenation, 4.1.2, 4.1.2, 8.1, 8.1
precedence, 4.1.2
relation-to-stream
Dstream, 4.1.2
Istream, 4.1.2
Rstream, 4.1.2
stream-to-relation
about, 1.1.3
default, 1.1.3.3
partitioned S[Partition By A1 ... Ak Rows N Range T], 4.1.2
partitioned S[Partition By A1 ... Ak Rows N Range T1 Slide T2], 4.1.2
partitioned S[Partition By A1 ... Ak Rows N], 4.1.2
S[Now] time-based, 4.1.2
S[Range C on E] constant value-based, 4.1.2
S[Range T] time-based, 4.1.2
S[Range T1 Slide T2] time-based, 4.1.2
S[Range Unbounded] time-based, 4.1.2
S[Rows N] tuple-based, 4.1.2
S[Rows N1 slide N2] tuple-based, 4.1.2
unary, 4.1.1
opt_group_by_clause syntax, 20.1
opt_having_clause syntax, 20.1
opt_where_clause syntax, 20.1
OR condition, 6.3, 6.3
Oracle JDBC data cartridge
about, 17.1
application context
about, 17.1.4
jc:jdbc-ctx, 17.1.4.2
jdbc:jdbc-context, 17.1.4.1
data cartridge name, 17.1.1
datatype mapping
about, 17.1.3
param element, 17.2.1.2.1
return-component-type element, 17.2.1.2.2
sql element, 17.2.1.2.3
Oracle CQL queries, 17.2.2
scope, 17.1.2
SQL statements, 17.2.1
Oracle Spatial
about, 16.1
application context, 16.1.4
coordinate systems, 16.1.2.3
data cartridge name, 16.1.1
datatype mapping, 16.1.3
functions
ordsgenerator, 16.2.7
Geometry class, 16.1.3
Geometry methods
about, 16.1.2.7
bufferPolygon, 16.2.7
createElemInfo, 16.2.7, 16.2.7
createGeometry, 16.2.7
createLinearPolygon, 16.2.7
createPoint, 16.2.7
createRectangle, 16.2.7
distance, 16.2.7
get2dMbr, 16.2.7
to_Geometry, 16.2.7
to_JGeometry, 16.2.7
indexing, 16.1.2.4
MBR, 16.1.2.4, 16.1.2.7.2, 16.2.7
operators
ANYINTERACT, 16.2.7
CONTAIN, 16.2.7
FILTER, 16.2.7
filter, 16.1.2.6
INSIDE, 16.2.7
NN, 16.1.2.6, 16.2.7
relation, 16.1.2.5
WITHINDISTANCE, 16.2.7
ordinate systems, 16.1.2.3
scope
about, 16.1.2
coordinate systems, 16.1.2.3
datatypes, 16.1.2.1
element info array, 16.1.2.2
filter operators, 16.1.2.6
geometrix index, 16.1.2.4
Geometry methods, 16.1.2.7
MBR, 16.1.2.4
ordinate systems, 16.1.2.3
relation operators, 16.1.2.5
Oracle tools
about, 1.4
support of CQL, 1.4
ORDER BY clause, 19.6
about, 20.1, 20.1
data cartridge
field access, 7.1
of SELECT, 18.2.9
order by top, 20.1
rows, 20.1
ORDER BY ROWS clause, 20.1
order_by_clause syntax, 18.2.9, 20.1
order_by_list syntax, 20.1
order_by_top_clause syntax, 20.1
order_expr syntax, 5.1
orderterm syntax, 20.1
ordsgenerator function, 16.2.7
outer join look-back, 18.4.2.3
outer joins, 18.4.2, 18.4.2.1, 18.4.2.2, 18.4.2.3
ON clause, 18.4.2
overlapping patterns
partial, 19.7
total, 19.7
overloading functions, 1.1.11, 2.8.1, 13.1.1
overriding
functions, 1.1.11, 2.8.1, 13.1.1

P

package_name
clause, 7.1, 7.1
param_list
clause, 7.1
parameterized queries
about, 18.2.11
bindings element, 18.2.11.2
lexical conventions, 18.2.11.4
Oracle CQL statements, 18.2.11.1
parameter values, 18.2.11.4
runtime, 18.2.11.5
views, 18.2.11
partial overlapping patterns, 19.7
partition by
rows, 4.1.2
rows and range, 4.1.2
rows, range, and slide, 4.1.2
window specification, 1.1.3.2
PARTITION BY clause, 19.5
PATTERN clause
about, 19.3
alternation operator, 19.3.2
default, 19.3.1
group matches, 19.1.2
grouping operator, 19.3.2
permutation, 19.3.2
quantifiers, 19.3.1
regular expressions, 19.3.1
singleton matches, 19.1.2
pattern quantifier
(), 19.3.2
*, 19.3.1
*?, 19.3.1
+, 19.3.1
+?, 19.3.1
?, 19.3.1
??, 19.3.1
|, 19.3.2
0 or 1 times (maximal), 19.3.1
0 or 1 times (minimal), 19.3.1
0 or more times (maximal), 19.3.1
0 or more times (minimal), 19.3.1
1 or more times (maximal), 19.3.1
1 or more times (minimal), 19.3.1
alternation, 19.3.2
exactly 1 time, 19.3.1
grouping, 19.3.2
None, 19.3.1
pattern recognition. See MATCH_RECOGNIZE clause
pattern_clause syntax, 19.3
pattern_def_dur_clause syntax, 19.1
pattern_definition_clause syntax, 19.4
pattern_inc_timer_evs_clause syntax, 19.10
pattern_measures_clause syntax, 19.2
pattern_partition_clause syntax, 19.5, 19.6
pattern_quantifier syntax, 19.3.1
pattern_recognition_clause syntax, 19.1
pattern_skip_match_clause syntax, 19.7
pattern-matching conditions
LIKE, 6.4
lk function, 8.1
poisson function, 10.1
poissonComplemented function, 10.1
pooledMean function, 11.1.2
pooledVariance function, 11.1.2
pow function, 12.1
precedence
operators, 4.1.2
precision and number of digits of, 2.3.2.2
prev function, 8.1
product function, 11.1.2
projterm syntax, 20.1
pseudo_column syntax, 7.1
pseudocoloumns
about, 3
attr clause, 7.1
ELEMENT_TIME
about, 3.2
application-timestamped value, 3.2.1.2
bigint application-timestamped value, 3.2.1.2.1
int application-timestamped value, 3.2.1.2.1
system-timestamped value, 3.2.1.1
timestamp application-timestamped value, 3.2.1.2.2
with GROUP BY, 3.2.2.2
with PATTERN, 3.2.2.3
with SELECT, 3.2.2.1
pull event sources, 1.1.8.1, 18.2.8, 18.6
push event sources, 1.1.8.1

Q

qualified_type_name
clause, 7.1
quantile function, 11.1.2
quantileInverse function, 11.1.2
queries
about, 18, 18.2
built-in windows, 18.2.3
cache, 18.2.8, 18.5
data cartridges, 18.7
detecting differences, 18.2.10
DIFFERENCE USING, 18.2.10
MATCH_RECOGNIZE clause, 18.2.4
ORDER_BY, 18.2.9
parameterized, 18.2.11
simple, 18.2.2
sorting, 18.2.9
subqueries, 1.1.6, 18.1
TABLE, 18.2.7, 20.1
table
data cartridge, 18.2.7, 20.1
relational database, 18.2.5
relational database datatypes, 2.2.4.3
XML, 18.2.6
views, 18.3
XMLTABLE, 18.2.6
query
attributes
id, 20.1
statement, 20.1
query syntax, 18.2, 20.1
query_ref
clause, 7.1
syntax, 7.1
quotation marks
about, 2.3.1
locale, 2.8.1
text literals, 2.3.1
quoted_string_double_quotes syntax, 7.1
quoted_string_single_quotes syntax, 7.1

R

range
conditions, 6.5
window specification
about, 1.1.3.1
default, 1.1.3.1
rankInterpolated function, 11.1.2
rawtohex function, 8.1
recurring non-event detection, 19.9.2
regexp syntax, 19.3.1
regexp_grp_alt syntax, 19.3.2
relation_variable syntax, 18.2.1.3, 20.1
relational database tables, 1.1.9.1
relations
about, 1.1.1.2
base, 1.1.1.2
distinct, 1.1.2
heartbeat, 1.1.13
operation indicator
deletion (-), 1.1.1.3
insertion (+), 1.1.1.3
update (U), 1.1.1.3
schema, 1.1.1.2
tuple kind indicator, 1.1.1.3
relation-to-stream operators, 1.1.4
Dstream, 4.1.2
Istream, 4.1.2
Rstream, 4.1.2
reserved words, 2.8.1, 2.8.1, 7.1
right outer joins, 18.4.2, 18.4.2.2
rint function, 12.1
rms function, 11.1.2
round function, 12.1
round1 function, 12.1
Rstream relation-to-stream operator, 4.1.2

S

sampleKurtosis function, 11.1.2
sampleKurtosisStandardError function, 11.1.2
sampleSkew function, 11.1.2
sampleSkewStandardError function, 11.1.2
sampleVariance function, 11.1.2
scheduler
time, 1.1.13
schema
relation, 1.1.1.2
stream, 1.1.1.1, 1.1.1.1.2
schema objects
naming
examples, 2.8.3
guidelines, 2.8.2
searched_case syntax, 5.1
searched_case_list syntax, 5.1
second, 7.1
seconds, 7.1
select_clause
distinct, 20.1
syntax, 18.2.1.2, 20.1
SERVER_CLASS_SPACE, 15.1.2.3
set statements
about, 20.1
IN and NOT IN, 20.1
INTERSECT, 20.1
MINUS, 20.1
UNION and UNION ALL, 20.1
sfw_block syntax, 18.2.1.1, 20.1
signum function, 12.1
signum1 function, 12.1
simple comparison conditions, 6.2
simple joins, 18.4.1
simple queries, 18.2.2
simple_case syntax, 5.1
simple_case_list syntax, 5.1
sin function, 12.1
single quotes, 2.3.1
singleton match, 19.1.2
sinh function, 12.1
skew function, 11.1.2
slide
window specification
about, 1.1.3.1
default, 1.1.3.1
SOME operator, 6.2
sorting query results, 18.2.9
SQL99, 1.3
SQLX
about, 5.1
content, 5.1
datatype conversion, 2.2.4.3
document, 5.1
expressions, 5.1
func_expr, 5.1
functions, 8.1
wellformed, 5.1
xml_agg_expr, 5.1
xml_parse_expr, 5.1
xmlagg function, 9.1.1
xmlcolattval_expr, 5.1
xmlcomment function, 8.1
xmlconcat function, 8.1
xmlelement_expr, 5.1
xmlexists function, 8.1
xmlforest_expr, 5.1
xmlquery function, 8.1
SQL/XML. See SQLX
sqrt function, 12.1
standardDeviation function, 11.1.2
standardError function, 11.1.2
standards, 1.3
statement terminator, 1.2.1
stirlingCorrection function, 10.1
streams
about, 1.1.1.1
base, 1.1.1.2
channel, 1.1.1.1.1
derived, 1.1.1.2, 1.1.1.2
heartbeat, 1.1.13
query selector, 1.1.1.1.4
relation, 1.1.1.2, 1.1.1.2
schema, 1.1.1.1, 1.1.1.1.2
tuple, 1.1.1.1
stream-to-relation operators
about, 1.1.3
default, 1.1.3.3
group by, 3.2.2.2, 4.1.2, 4.1.2, 4.1.2
partitioned S[Partition By A1 ... Ak Rows N Range T], 4.1.2
partitioned S[Partition By A1 ... Ak Rows N Range T1 Slide T2], 4.1.2
partitioned S[Partition By A1 ... Ak Rows N], 4.1.2
S[Now] time-based, 4.1.2
S[Range C on E] constant value-based, 4.1.2
S[Range T] time-based, 4.1.2
S[Range T1 Slide T2] time-based, 4.1.2
S[Range Unbounded] time-based, 4.1.2
S[Rows N] tuple-based, 4.1.2
S[Rows N1 slide N2] tuple-based, 4.1.2
stream-to-stream operators, 1.1.5
filter, 1.1.5
MATCH_RECOGNIZE, 1.1.5
project, 1.1.5
XMLTABLE, 1.1.5
studentT function, 10.1
studentTInverse function, 10.1
subqueries, 1.1.6, 1.1.6, 18.1
SUBSET clause, 19.11
subset_clause
about, 19.11
syntax, 19.11
subset_definition syntax, 19.11
subset_name syntax, 19.11
sum function, 9.1.1
sumOfInversions function, 11.1.2
sumOfLogarithms function, 11.1.2
sumOfPowerDeviations function, 11.1.2
sumOfPowers function, 11.1.2
sumOfSquaredDeviations function, 11.1.2
sumOfSquares function, 11.1.2
synonyms. See aliases
Syntax, 10.1
system time, 1.1.13
system timestamped, 1.1.13
systemtimestamp function, 8.1

T

TABLE queries, 18.2.7, 20.1
table_clause syntax, 18.2.7, 20.1
tables, 1.1.9
queries
data cartridge, 18.2.7, 20.1
relational database, 18.2.5
relational database datatypes, 2.2.4.3
XML, 18.2.6
tan function, 12.1
tanh function, 12.1
terminator, 1.2.1
text literals
about, 2.3.1
quotation marks, 2.3.1
time
about, 1.1.13
application, 1.1.13
application timestamped, 1.1.13
heartbeat, 1.1.13
is-total-order, 1.1.13
scheduler, 1.1.13
system, 1.1.13
system timestamped, 1.1.13
time system timestamped, 1.1.13
time_spec
clause, 7.1
syntax, 7.1
time_unit
syntax, 7.1
TIMESTAMP
about, 2.3.3
xsd
dateTime, 2.3.3
TIMESTAMP datatype, 2.1.1
timestamps
application, 1.1.13
system, 1.1.13
to_bigint function, 8.1
to_boolean function, 8.1
to_char function, 8.1
to_double function, 8.1
to_float function, 8.1
to_Geometry Geometry method, 16.2.7
to_JGeometry Geometry method, 16.2.7
to_timestamp function, 8.1
todegrees function, 12.1
tools support
development, 1.4.2
Oracle CEP IDE for Eclipse, 1.4.2
Oracle CEP Server, 1.4.1
Oracle CEP Visualizer, 1.4.1
runtime, 1.4.i.1
toradians function, 12.1
total overlapping patterns, 19.7
trimmedMean function, 11.1.2
tuple
about, 1.1.1.1
kind indicator, 1.1.1.3
streams, 1.1.1.1

U

U
relation update, 1.1.1.3
ulp function, 12.1
ulp1 function, 12.1
unary operators, 4.1.1
UNION ALL clause, 20.1
UNION clause, 20.1
unreserved words, 7.1
unreserved_keyword syntax, 7.1
user-defined functions
about, 1.1.11, 13
aggregate, 13.1.1.2
cache, 13.1.3
classpath, 13.2.1, 13.2.2
datatype mapping, 13.1.2
implementing, 13.1, 13.2
aggregate, 13.2.2
AggrFunctionImpl, 13.2.2
SingleElementFunction, 13.2.1
single-row, 13.2.1
incremental computation
about, 13.1.1.2
implementing, 13.2.2
run-time behavior, 13.2.2
single-row, 13.1.1.1
types of, 13.1.1
using_clause syntax, 18.2.10, 20.1
usingexpr syntax, 20.1
usinglist syntax, 20.1
usingterm syntax, 20.1

V

variable_length_datatype syntax, 2.1
variance function, 11.1.2
view
attributes
id, 20.1
schema, 20.1
statement, 20.1
views
about, 18
joins, 18.3.1
queries, 18.3
schema, 18.3.2
visibility, 18.3

W

weightedMean function, 11.1.2
wellformed, 5.1
WHERE clause
built-in aggregate functions, 9.1.1
Colt aggregate functions, 11.1.2
group by and having clause, 9.1.1, 11.1.2
MATCH_RECOGNIZE clause, 19.1.1
window_type syntax, 1.1.3, 20.1
window_type_partition syntax, 4.1.2
window_type_range syntax, 4.1.2
window_type_tuple syntax, 4.1.2
windows, 1.1.3
about, 1.1.3
Now, 4.1.2
partitioned, 1.1.3.2, 4.1.2, 4.1.2, 4.1.2
range specification
about, 1.1.3.1
default, 1.1.3.1
S[Now] time-based, 4.1.2
S[Partition By A1 ... Ak Rows N Range T], 4.1.2
S[Partition By A1 ... Ak Rows N Range T1 Slide T2], 4.1.2
S[Partition By A1 ... Ak Rows N], 4.1.2
S[Range C on E] constant value-based, 4.1.2
S[Range T] time-based, 4.1.2
S[Range T1 Slide T2] time-based, 4.1.2
S[Range Unbounded] time-based, 4.1.2
S[Rows N] tuple-based, 4.1.2
S[Rows N1 slide N2] tuple-based, 4.1.2
slide specification
about, 1.1.3.1
default, 1.1.3.1
Unbounded, 4.1.2
winsorizedMean function, 11.1.2
WITHIN clause, 19.8
WITHIN INCLUSIVE clause, 19.8
within_clause syntax, 19.8
WITHINDISTANCE geometric relation operator, 16.2.7

X

XML tables, 1.1.9.2
xml_agg_expr syntax, 5.1
xml_attr syntax, 7.1
xml_attr_list
clause, 7.1
syntax, 7.1
xml_attribute_list
clause, 7.1
syntax, 7.1
xml_namespace syntax, 20.1
xmlagg function, 9.1.1
xmlcolattval_expr syntax, 5.1, 5.1
xmlcomment function, 8.1
xmlconcat function, 8.1
xmlexists function, 8.1
xmlforest_expr syntax, 5.1, 5.1
xmlnamespace_clause syntax, 20.1
xmlnamespaces_list syntax, 20.1
xmlquery function, 8.1
XMLTABLE queries, 18.2.6
xmltable_clause syntax, 20.1
XMLTYPE datatype, 2.1.1
XOR condition, 6.3
xqryarg syntax, 7.1
xqryargs_list
clause, 7.1
syntax, 7.1
xsd
dateTime, 2.3.3
xstream_clause syntax, 20.1
xtbl_col syntax, 20.1
xtbl_cols_list syntax, 20.1

Y

y0 function, 10.1
y1 function, 10.1
yn function, 10.1
PK.i.PKO_\EOEBPS/part_using.htm Using Oracle CQL PK%BPKO_\EOEBPS/part_under.htmK Understanding Oracle CQL PK]ydPKPKO_\EOEBPS/funccolt.htm Colt Single-Row Functions

10 Colt Single-Row Functions

This chapter provides a reference to Colt single-row functions included in Oracle Continuous Query Language (Oracle CQL). Colt single-row functions are based on the Colt open source libraries for high performance scientific and technical computing.

For more information, see Section 1.1.11, "Functions".

10.1 Introduction to Oracle CQLBuilt-In Single-Row Colt Functions

Table 10-1 lists the built-in single-row Colt functions that Oracle CQL provides.

Table 10-1 Oracle CQL Built-in Single-Row Colt-Based Functions

Colt PackageFunction

cern.jet.math.Arithmetic

A set of basic polynomials, rounding, and calculus functions.


cern.jet.math.Bessel

A set of Bessel functions.


cern.jet.random.engine.RandomSeedTable

A table with good seeds for pseudo-random number generators. Each sequence in this table has a period of 10**9 numbers.


cern.jet.stat.Gamma

A set of Gamma and Beta functions.


cern.jet.stat.Probability

A set of probability distributions.


cern.colt.bitvector.QuickBitVector

A set of non polymorphic, non bounds checking, low level bit-vector functions.


cern.colt.map.HashFunctions

A set of hash functions.




Note:

Built-in function names are case sensitive and you must use them in the case shown (in lower case).



Note:

In stream input examples, lines beginning with h (such as h 3800) are heartbeat input tuples. These inform Oracle CEP that no further input will have a timestamp lesser than the heartbeat value.


For more information, see:


beta

Syntax

Surrounding text describes beta.png.

Purpose

beta is based on cern.jet.stat.Gamma. It returns the beta function (see Figure 10-1) of the input arguments as a double.

Figure 10-1 cern.jet.stat.Gamma beta

Surrounding text describes Figure 10-1 .

This function takes the following arguments:

  • double1: the x value.

  • double2: the y value.

For more information, see http://dsd.lbl.gov/~hoschek/colt/api/cern/jet/stat/Gamma.html#beta(double,%20double).

Examples

Consider the query qColt28 in Example 10-1. Given the data stream SColtFunc with schema (c1 integer, c2 double, c3 bigint) in Example 10-2, the query returns the relation in Example 10-3.

Example 10-1 beta Function Query

<query id="qColt28"><![CDATA[ 
    select beta(c2,c2) from SColtFunc
]]></query>

Example 10-2 beta Function Stream Input

Timestamp   Tuple
  10        1,0.5,8
1000        4,0.7,6
1200        3,0.89,12
2000        8,0.4,4

Example 10-3 beta Function Relation Output

Timestamp   Tuple Kind  Tuple
  10:       +           3.1415927
1000:       +           1.899038
1200:       +           1.251922
2000:       +           4.226169

beta1

Syntax

Surrounding text describes beta1.png.

Purpose

beta1 is based on cern.jet.stat.Probability. It returns the area P(x) from 0 to x under the beta density function (see Figure 10-2) as a double.

Figure 10-2 cern.jet.stat.Probability beta1

Surrounding text describes Figure 10-2 .

This function takes the following arguments:

  • double1: the alpha parameter of the beta distribution a.

  • double2: the beta parameter of the beta distribution b.

  • double3: the integration end point x.

For more information, see http://dsd.lbl.gov/~hoschek/colt/api/cern/jet/stat/Probability.html#beta(double,%20double,%20double).

Examples

Consider the query qColt35 in Example 10-4. Given the data stream SColtFunc with schema (c1 integer, c2 double, c3 bigint) in Example 10-5, the query returns the relation in Example 10-6.

Example 10-4 beta1 Function Query

<query id="qColt35"><![CDATA[ 
    select beta1(c2,c2,c2) from SColtFunc
]]></query>

Example 10-5 beta1 Function Stream Input

Timestamp   Tuple
  10        1,0.5,8
1000        4,0.7,6
1200        3,0.89,12
2000        8,0.4,4

Example 10-6 beta1 Function Relation Output

Timestamp   Tuple Kind  Tuple
  10:       +           0.5       
1000:       +           0.66235894
1200:       +           0.873397  
2000:       +           0.44519535

betaComplemented

Syntax

Surrounding text describes betacomplemented.png.

Purpose

betaComplemented is based on cern.jet.stat.Probability. It returns the area under the right hand tail (from x to infinity) of the beta density function (see Figure 10-2) as a double.

This function takes the following arguments:

  • double1: the alpha parameter of the beta distribution a.

  • double2: the beta parameter of the beta distribution b.

  • double3: the integration end point x.

For more information, see:

Examples

Consider the query qColt37 in Example 10-7. Given the data stream SColtFunc with schema (c1 integer, c2 double, c3 bigint) in Example 10-8, the query returns the relation in Example 10-9.

Example 10-7 betaComplemented Function Query

<query id="qColt37"><![CDATA[ 
    select betaComplemented(c2,c2,c2) from SColtFunc
]]></query>

Example 10-8 betaComplemented Function Stream Input

Timestamp   Tuple
  10        1,0.5,8
1000        4,0.7,6
1200        3,0.89,12
2000        8,0.4,4

Example 10-9 betaComplemented Function Relation Output

Timestamp   Tuple Kind  Tuple
  10:       +           0.5       
1000:       +           0.66235894
1200:       +           0.873397  
2000:       +           0.44519535

binomial

Syntax

Surrounding text describes binomial.png.

Purpose

binomial is based on cern.jet.math.Arithmetic. It returns the binomial coefficient n over k (see Figure 10-3) as a double.

Figure 10-3 Definition of binomial coefficient

Surrounding text describes Figure 10-3 .

This function takes the following arguments:

  • double1: the n value.

  • long2: the k value.

Table 10-2 lists the binomial function return values for various values of k.

Table 10-2 cern.jet.math.Arithmetic binomial Return Values

ArgumentsReturn Value

k < 0

0

k = 0

1

k = 1

n

Any other value of k

Computed binomial coefficient as given in Figure 10-3.


For more information, see http://dsd.lbl.gov/~hoschek/colt/api/cern/jet/math/Arithmetic.html#binomial(double,%20long).

Examples

Consider the query qColt6 in Example 10-10. Given the data stream SColtFunc with schema (c1 integer, c2 double, c3 long) in Example 10-11, the query returns the relation in Example 10-12.

Example 10-10 binomial Function Query

<query id="qColt6"><![CDATA[ 
    select binomial(c2,c3) from SColtFunc
]]></query>

Example 10-11 binomial Function Stream Input

Timestamp   Tuple
  10        1,0.5,8
1000        4,0.7,6
1200        3,0.89,12
2000        8,0.4,4

Example 10-12 binomial Function Relation Output

Timestamp   Tuple Kind  Tuple
  10:       +           -0.013092041 
1000:       +           -0.012374863 
1200:       +           -0.0010145549
2000:       +           -0.0416      

binomial1

Syntax

Surrounding text describes binomial1.png.

Purpose

binomial1 is based on cern.jet.math.Arithmetic. It returns the binomial coefficient n over k (see Figure 10-3) as a double.

This function takes the following arguments:

  • long1: the n value.

  • long2: the k value.

Table 10-3 lists the BINOMIAL function return values for various values of k.

Table 10-3 cern.jet.math.Arithmetic Binomial1 Return Values

ArgumentsReturn Value

k < 0

0

k = 0 || k = n

1

k = 1 || k = n-1

n

Any other value of k

Computed binomial coefficient as given in Figure 10-3.


For more information, see http://dsd.lbl.gov/~hoschek/colt/api/cern/jet/math/Arithmetic.html#binomial(long,%20long).

Examples

Consider the query qColt7 in Example 10-13. Given the data stream SColtFunc with schema (c1 integer, c2 float, c3 long) in Example 10-14, the query returns the relation in Example 10-15.

Example 10-13 binomial1 Function Query

<query id="qColt7"><![CDATA[ 
    select binomial1(c3,c3) from SColtFunc
]]></query>

Example 10-14 binomial1 Function Stream Input

Timestamp   Tuple
  10        1,0.5,8
1000        4,0.7,6
1200        3,0.89,12
2000        8,0.4,4

Example 10-15 binomial1 Function Relation Output

Timestamp   Tuple Kind  Tuple
  10:       +           1.0
1000:       +           1.0
1200:       +           1.0
2000:       +           1.0

binomial2

Syntax

Surrounding text describes binomial2.png.

Purpose

binomial2 is based on cern.jet.stat.Probability. It returns the sum of the terms 0 through k of the binomial probability density (see Figure 10-4) as a double.

Figure 10-4 cern.jet.stat.Probability binomial2

Surrounding text describes Figure 10-4 .

This function takes the following arguments (all arguments must be positive):

  • integer1: the end term k.

  • integer2: the number of trials n.

  • double3: the probability of success p in (0.0, 1.0)

For more information, see http://dsd.lbl.gov/~hoschek/colt/api/cern/jet/stat/Probability.html#binomial(int,%20int,%20double).

Examples

Consider the query qColt34 in Example 10-16. Given the data stream SColtFunc with schema (c1 integer, c2 double, c3 bigint) in Example 10-17, the query returns the relation in Example 10-18.

Example 10-16 binomial2 Function Query

<query id="qColt34"><![CDATA[ 
    select binomial2(c1,c1,c2) from SColtFunc
]]></query>

Example 10-17 binomial2 Function Stream Input

Timestamp   Tuple
  10        1,0.5,8
1000        4,0.7,6
1200        3,0.89,12
2000        8,0.4,4

Example 10-18 binomial2 Function Relation Output

Timestamp   Tuple Kind  Tuple
  10:       +           1.0
1000:       +           1.0
1200:       +           1.0
2000:       +           1.0

binomialComplemented

Syntax

Surrounding text describes binomialcomplemented.png.

Purpose

binomialComplemented is based on cern.jet.stat.Probability. It returns the sum of the terms k+1 through n of the binomial probability density (see Figure 10-5) as a double.

Figure 10-5 cern.jet.stat.Probability binomialComplemented

Surrounding text describes Figure 10-5 .

This function takes the following arguments (all arguments must be positive):

  • integer1: the end term k.

  • integer2: the number of trials n.

  • double3: the probability of success p in (0.0, 1.0)

For more information, see http://dsd.lbl.gov/~hoschek/colt/api/cern/jet/stat/Probability.html#binomialComplemented(int,%20int,%20double).

Examples

Consider the query qColt38 in Example 10-19. Given the data stream SColtFunc with schema (integer, c2 double, c3 bigint) in Example 10-20, the query returns the relation in Example 10-21.

Example 10-19 binomialComplemented Function Query

<query id="qColt38"><![CDATA[ 
    select binomialComplemented(c1,c1,c2) from SColtFunc
]]></query>

Example 10-20 binomialComplemented Function Stream Input

Timestamp   Tuple
  10        1,0.5,8
1000        4,0.7,6
1200        3,0.89,12
2000        8,0.4,4

Example 10-21 binomialComplemented Function Relation Output

Timestamp   Tuple Kind  Tuple
  10:       +           0.0
1000:       +           0.0
1200:       +           0.0
2000:       +           0.0

bitMaskWithBitsSetFromTo

Syntax

Surrounding text describes bitmaskwithbitssetfromto.png.

Purpose

bitMaskWithBitsSetFromTo is based on cern.colt.bitvector.QuickBitVector. It returns a 64-bit wide bit mask as a long with bits in the specified range set to 1 and all other bits set to 0.

This function takes the following arguments:

  • integer1: the from value; index of the start bit (inclusive).

  • integer2: the to value; index of the end bit (inclusive).

Precondition (not checked): to - from + 1 >= 0 && to - from + 1 <= 64.

If to - from + 1 = 0 then returns a bit mask with all bits set to 0.

For more information, see:

Examples

Consider the query qColt53 in Example 10-22. Given the data stream SColtFunc with schema (c1 integer, c2 float, c3 bigint) in Example 10-23, the query returns the relation in Example 10-24.

Example 10-22 bitMaskWithBitsSetFromTo Function Query

<query id="qColt53"><![CDATA[ 
    select bitMaskWithBitsSetFromTo(c1,c1) from SColtFunc
]]></query>

Example 10-23 bitMaskWithBitsSetFromTo Function Stream Input

Timestamp   Tuple
  10        1,0.5,8
1000        4,0.7,6
1200        3,0.89,12
2000        8,0.4,4

Example 10-24 bitMaskWithBitsSetFromTo Function Relation Output

Timestamp   Tuple Kind  Tuple
  10:       +           2  
1000:       +           16 
1200:       +           8  
2000:       +           256

ceil

Syntax

Surrounding text describes ceil.png.

Purpose

ceil is based on cern.jet.math.Arithmetic. It returns the smallest long greater than or equal to its double argument.

This method is safer than using (float) java.lang.Math.ceil(long) because of possible rounding error.

For more information, see:

Examples

Consider the query qColt1 in Example 10-25. Given the data stream SColtFunc with schema (c1 integer, c2 double, c3 bigint) in Example 10-26, the query returns the relation in Example 10-27.

Example 10-25 ceil Function Query

<query id="qColt1"><![CDATA[ 
    select ceil(c2) from SColtFunc
]]></query>

Example 10-26 ceil Function Stream Input

Timestamp   Tuple
  10        1,0.5,8
1000        4,0.7,6
1200        3,0.89,12
2000        8,0.4,4

Example 10-27 ceil Function Relation Output

Timestamp   Tuple Kind  Tuple
  10:       +           1
1000:       +           1
1200:       +           1
2000:       +           1

chiSquare

Syntax

Surrounding text describes chisquare.png.

Purpose

chiSquare is based on cern.jet.stat.Probability. It returns the area under the left hand tail (from 0 to x) of the Chi square probability density function with v degrees of freedom (see Figure 10-6) as a double.

Figure 10-6 cern.jet.stat.Probability chiSquare

Surrounding text describes Figure 10-6 .

This function takes the following arguments (all arguments must be positive):

  • double1: the degrees of freedom v.

  • double2: the integration end point x.

For more information, see http://dsd.lbl.gov/~hoschek/colt/api/cern/jet/stat/Probability.html#chiSquare(double,%20double).

Examples

Consider the query qColt39 in Example 10-28. Given the data stream SColtFunc with schema (c1 integer, c2 double, c3 bigint) in Example 10-29, the query returns the relation in Example 10-30.

Example 10-28 chiSquare Function Query

<query id="qColt39"><![CDATA[ 
    select chiSquare(c2,c2) from SColtFunc
]]></query>

Example 10-29 chiSquare Function Stream Input

Timestamp   Tuple
  10        1,0.5,8
1000        4,0.7,6
1200        3,0.89,12
2000        8,0.4,4

Example 10-30 chiSquare Function Relation Output

Timestamp   Tuple Kind  Tuple
  10:       +           0.0
1000:       +           0.0
1200:       +           0.0
2000:       +           0.0

chiSquareComplemented

Syntax

Surrounding text describes chisquarecomplemented.png.

Purpose

chiSquareComplemented is based on cern.jet.stat.Probability. It returns the area under the right hand tail (from x to infinity) of the Chi square probability density function with v degrees of freedom (see Figure 10-6) as a double.

This function takes the following arguments (all arguments must be positive):

  • double1: the degrees of freedom v.

  • double2: the integration end point x.

For more information, see http://dsd.lbl.gov/~hoschek/colt/api/cern/jet/stat/Probability.html#chiSquareComplemented(double,%20double).

Examples

Consider the query qColt40 in Example 10-31. Given the data stream SColtFunc with schema (c1 integer, c2 double, c3 bigint) in Example 10-32, the query returns the relation in Example 10-33.

Example 10-31 chiSquareComplemented Function Query

<query id="qColt40"><![CDATA[ 
    select chiSquareComplemented(c2,c2) from SColtFunc
]]></query>

Example 10-32 chiSquareComplemented Function Stream Input

Timestamp   Tuple
  10        1,0.5,8
1000        4,0.7,6
1200        3,0.89,12
2000        8,0.4,4

Example 10-33 chiSquareComplemented Function Relation Output

Timestamp   Tuple Kind  Tuple
  10:       +           0.0
1000:       +           0.0
1200:       +           0.0
2000:       +           0.0

errorFunction

Syntax

Surrounding text describes errorfunction.png.

Purpose

errorFunction is based on cern.jet.stat.Probability. It returns the error function of the normal distribution of the double argument as a double, using the integral that Figure 10-7 shows.

Figure 10-7 cern.jet.stat.Probability errorFunction

Surrounding text describes Figure 10-7 .

For more information, see http://dsd.lbl.gov/~hoschek/colt/api/cern/jet/stat/Probability.html#errorFunction(double).

Examples

Consider the query qColt41 in Example 10-34. Given the data stream SColtFunc with schema (c1 integer, c2 double, c3 bigint) in Example 10-35, the query returns the relation in Example 10-36.

Example 10-34 errorFunction Function Query

<query id="qColt41"><![CDATA[ 
    select errorFunction(c2) from SColtFunc
]]></query>

Example 10-35 errorFunction Function Stream Input

Timestamp   Tuple
  10        1,0.5,8
1000        4,0.7,6
1200        3,0.89,12
2000        8,0.4,4

Example 10-36 errorFunction Function Relation Output

Timestamp   Tuple Kind  Tuple
  10:       +           0.5204999 
1000:       +           0.6778012 
1200:       +           0.79184324
2000:       +           0.42839235

errorFunctionComplemented

Syntax

Surrounding text describes errorfunctioncomplemented.png.

Purpose

errorFunctionComplemented is based on cern.jet.stat.Probability. It returns the complementary error function of the normal distribution of the double argument as a double, using the integral that Figure 10-8 shows.

Figure 10-8 cern.jet.stat.Probability errorfunctioncompelemented

Surrounding text describes Figure 10-8 .

For more information, see http://dsd.lbl.gov/~hoschek/colt/api/cern/jet/stat/Probability.html#errorFunctionComplemented(double).

Examples

Consider the query qColt42 in Example 10-37. Given the data stream SColtFunc with schema (c1 integer, c2 double, c3 bigint) in Example 10-38, the query returns the relation in Example 10-39.

Example 10-37 errorFunctionComplemented Function Query

<query id="qColt42"><![CDATA[ 
    select errorFunctionComplemented(c2) from SColtFunc
]]></query>

Example 10-38 errorFunctionComplemented Function Stream Input

Timestamp   Tuple
  10        1,0.5,8
1000        4,0.7,6
1200        3,0.89,12
2000        8,0.4,4

Example 10-39 errorFunctionComplemented Function Relation Output

Timestamp   Tuple Kind  Tuple
  10:       +           0.47950011
1000:       +           0.3221988 
1200:       +           0.20815676
2000:       +           0.57160765

factorial

Syntax

Surrounding text describes factorial.png.

Purpose

factorial is based on cern.jet.math.Arithmetic. It returns the factorial of the positive integer argument as a double.

For more information, see http://dsd.lbl.gov/~hoschek/colt/api/cern/jet/math/Arithmetic.html#factorial(int).

Examples

Consider the query qColt8 in Example 10-40. Given the data stream SColtFunc with schema (c1 integer, c2 float, c3 bigint) in Example 10-41, the query returns the relation in Example 10-42.

Example 10-40 factorial Function Query

<query id="qColt8"><![CDATA[ 
    select factorial(c1) from SColtFunc
]]></query>

Example 10-41 factorial Function Stream Input

Timestamp   Tuple
  10        1,0.5,8
1000        4,0.7,6
1200        3,0.89,12
2000        8,0.4,4

Example 10-42 factorial Function Relation Output

Timestamp   Tuple Kind  Tuple
  10:       +               1.0
1000:       +              24.0
1200:       +               6.0
2000:       +           40320.0

floor

Syntax

Surrounding text describes floor.png.

Purpose

floor is based on cern.jet.math.Arithmetic. It returns the largest long value less than or equal to the double argument.

This method is safer than using (double) java.lang.Math.floor(double) because of possible rounding error.

For more information, see:

Examples

Consider the query qColt2 in Example 10-43. Given the data stream SColtFunc with schema (c1 integer, c2 double, c3 bigint) in Example 10-44, the query returns the relation in Example 10-45.

Example 10-43 floor Function Query

<query id="qColt2"><![CDATA[ 
    select floor(c2) from SColtFunc
]]></query>

Example 10-44 floor Function Stream Input

Timestamp   Tuple
  10        1,0.5,8
1000        4,0.7,6
1200        3,0.89,12
2000        8,0.4,4

Example 10-45 floor Function Relation Output

Timestamp   Tuple Kind  Tuple
  10:       +           0
1000:       +           0
1200:       +           0
2000:       +           0

gamma

Syntax

Surrounding text describes gamma.png.

Purpose

gamma is based on cern.jet.stat.Gamma. It returns the Gamma function of the double argument as a double.

For more information, see http://dsd.lbl.gov/~hoschek/colt/api/cern/jet/stat/Gamma.html#gamma(double).

Examples

Consider the query qColt29 in Example 10-46. Given the data stream SColtFunc with schema (c1 integer, c2 double, c3 bigint) in Example 10-47, the query returns the relation in Example 10-48.

Example 10-46 gamma Function Query

<query id="qColt29"><![CDATA[ 
    select gamma(c2) from SColtFunc
]]></query>

Example 10-47 gamma Function Stream Input

Timestamp   Tuple
  10        1,0.5,8
1000        4,0.7,6
1200        3,0.89,12
2000        8,0.4,4

Example 10-48 gamma Function Relation Output

Timestamp   Tuple Kind  Tuple
  10:       +           1.7724539
1000:       +           1.2980554
1200:       +           1.0768307
2000:       +           2.2181594

gamma1

Syntax

Surrounding text describes gamma1.png.

Purpose

gamma1 is based on cern.jet.stat.Probability. It returns the integral from zero to x of the gamma probability density function (see Figure 10-9) as a double.

Figure 10-9 cern.jet.stat.Probability gamma1

Surrounding text describes Figure 10-9 .

This function takes the following arguments:

  • double1: the gamma distribution alpha value a

  • double2: the gamma distribution beta or lambda value b

  • double3: the integration end point x

For more information, see http://dsd.lbl.gov/~hoschek/colt/api/cern/jet/stat/Probability.html#gamma(double,%20double,%20double).

Examples

Consider the query qColt36 in Example 10-49. Given the data stream SColtFunc with schema (c1 integer, c2 double, c3 bigint) in Example 10-50, the query returns the relation in Example 10-51.

Example 10-49 gamma1 Function Query

<query id="qColt36"><![CDATA[ 
    select gamma1(c2,c2,c2) from SColtFunc
]]></query>

Example 10-50 gamma1 Function Stream Input

Timestamp   Tuple
  10        1,0.5,8
1000        4,0.7,6
1200        3,0.89,12
2000        8,0.4,4

Example 10-51 gamma1 Function Relation Output

Timestamp   Tuple Kind  Tuple
  10:       +           0.5204999 
1000:       +           0.55171627
1200:       +           0.59975785
2000:       +           0.51785487

gammaComplemented

Syntax

Surrounding text describes gammacomplemented.png.

Purpose

gammaComplemented is based on cern.jet.stat.Probability. It returns the integral from x to infinity of the gamma probability density function (see Figure 10-10) as a double.

Figure 10-10 cern.jet.stat.Probability gammaComplemented

Surrounding text describes Figure 10-10 .

This function takes the following arguments:

  • double1: the gamma distribution alpha value a

  • double2: the gamma distribution beta or lambda value b

  • double3: the integration end point x

For more information, see http://dsd.lbl.gov/~hoschek/colt/api/cern/jet/stat/Probability.html#gammaComplemented(double,%20double,%20double).

Examples

Consider the query qColt43 in Example 10-52. Given the data stream SColtFunc with schema (c1 integer, c2 double, c3 bigint) in Example 10-53, the query returns the relation in Example 10-54.

Example 10-52 gammaComplemented Function Query

<query id="qColt43"><![CDATA[ 
    select gammaComplemented(c2,c2,c2) from SColtFunc
]]></query>

Example 10-53 gammaComplemented Function Stream Input

Timestamp   Tuple
  10        1,0.5,8
1000        4,0.7,6
1200        3,0.89,12
2000        8,0.4,4

Example 10-54 gammaComplemented Function Relation Output

Timestamp   Tuple Kind  Tuple
  10:       +           0.47950011
1000:       +           0.44828376
1200:       +           0.40024218
2000:       +           0.48214513

getSeedAtRowColumn

Syntax

Surrounding text describes getseedatrowcolumn.png.

Purpose

getSeedAtRowColumn is based on cern.jet.random.engine.RandomSeedTable. It returns a deterministic seed as an integer from a (seemingly gigantic) matrix of predefined seeds.

This function takes the following arguments:

  • integer1: the row value; should (but need not) be in [0,Integer.MAX_VALUE].

  • integer2: the column value; should (but need not) be in [0,1].

For more information, see http://dsd.lbl.gov/~hoschek/colt/api/cern/jet/random/engine/RandomSeedTable.html#getSeedAtRowColumn(int,%20int).

Examples

Consider the query qColt27 in Example 10-55. Given the data stream SColtFunc with schema (c1 integer, c2 double, c3 bigint) in Example 10-56, the query returns the relation in Example 10-57.

Example 10-55 getSeedAtRowColumn Function Query

<query id="qColt27"><![CDATA[ 
    select getSeedAtRowColumn(c1,c1) from SColtFunc
]]></query>

Example 10-56 getSeedAtRowColumn Function Stream Input

Timestamp   Tuple
  10        1,0.5,8
1000        4,0.7,6
1200        3,0.89,12
2000        8,0.4,4

Example 10-57 getSeedAtRowColumn Function Relation Output

Timestamp   Tuple Kind  Tuple
  10:       +           253987020 
1000:       +           1289741558
1200:       +           417696270 
2000:       +           350557787 

hash

Syntax

Surrounding text describes hash.png.

Purpose

hash is based on cern.colt.map.HashFunctions. It returns an integer hashcode for the specified double value.

For more information, see http://dsd.lbl.gov/~hoschek/colt/api/cern/colt/map/HashFunctions.html#hash(double).

Examples

Consider the query qColt56 in Example 10-58. Given the data stream SColtFunc with schema (c1 integer, c2 double, c3 bigint) in Example 10-59, the query returns the relation in Example 10-60.

Example 10-58 hash Function Query

<query id="qColt56"><![CDATA[ 
    select hash(c2) from SColtFunc
]]></query>

Example 10-59 hash Function Stream Input

Timestamp   Tuple
  10        1,0.5,8
1000        4,0.7,6
1200        3,0.89,12
2000        8,0.4,4

Example 10-60 hash Function Relation Output

Timestamp   Tuple Kind  Tuple
  10:       +            1071644672
1000:       +            1608935014
1200:       +            2146204385
2000:       +           -1613129319

hash1

Syntax

Surrounding text describes hash1.png.

Purpose

hash1 is based on cern.colt.map.HashFunctions. It returns an integer hashcode for the specified float value.

For more information, see http://dsd.lbl.gov/~hoschek/colt/api/cern/colt/map/HashFunctions.html#hash(float).

Examples

Consider the query qColt57 in Example 10-61. Given the data stream SColtFunc with schema (c1 integer, c2 double, c3 bigint) in Example 10-62, the query returns the relation in Example 10-63.

Example 10-61 hash1 Function Query

<query id="qColt57"><![CDATA[ 
    select hash1(c2) from SColtFunc
]]></query>

Example 10-62 hash1 Function Stream Input

Timestamp   Tuple
  10        1,0.5,8
1000        4,0.7,6
1200        3,0.89,12
2000        8,0.4,4

Example 10-63 hash1 Function Relation Output

Timestamp   Tuple Kind  Tuple
  10:       +           1302214522
1000:       +           1306362078
1200:       +           1309462552
2000:       +           1300047248

hash2

Syntax

Surrounding text describes hash2.png.

Purpose

hash2 is based on cern.colt.map.HashFunctions. It returns an integer hashcode for the specified integer value.

For more information, see http://dsd.lbl.gov/~hoschek/colt/api/cern/colt/map/HashFunctions.html#hash(int).

Examples

Consider the query qColt58 in Example 10-64. Given the data stream SColtFunc with schema (c1 integer, c2 double, c3 bigint) in Example 10-65, the query returns the relation in Example 10-66.

Example 10-64 hash2 Function Query

<query id="qColt58"><![CDATA[ 
    select hash2(c1) from SColtFunc
]]></query>

Example 10-65 hash2 Function Stream Input

Timestamp   Tuple
  10        1,0.5,8
1000        4,0.7,6
1200        3,0.89,12
2000        8,0.4,4

Example 10-66 hash2 Function Relation Output

Timestamp   Tuple Kind  Tuple
  10:       +           1
1000:       +           4
1200:       +           3
2000:       +           8

hash3

Syntax

Surrounding text describes hash3.png.

Purpose

hash3 is based on cern.colt.map.HashFunctions. It returns an integer hashcode for the specified long value.

For more information, see http://dsd.lbl.gov/~hoschek/colt/api/cern/colt/map/HashFunctions.html#hash(long).

Examples

Consider the query qColt59 in Example 10-67. Given the data stream SColtFunc with schema (c1 integer, c2 double, c3 bigint) in Example 10-68, the query returns the relation in Example 10-69.

Example 10-67 hash3 Function Query

<query id="qColt59"><![CDATA[ 
    select hash3(c3) from SColtFunc
]]></query>

Example 10-68 hash3 Function Stream Input

Timestamp   Tuple
  10        1,0.5,8
1000        4,0.7,6
1200        3,0.89,12
2000        8,0.4,4

Example 10-69 hash3 Function Relation Output

Timestamp   Tuple Kind  Tuple
  10:       +           8
1000:       +           6
1200:       +           12
2000:       +           4

i0

Syntax

Surrounding text describes i0.png.

Purpose

i0 is based on cern.jet.math.Bessel. It returns the modified Bessel function of order 0 of the double argument as a double.

The function is defined as i0(x) = j0(ix).

The range is partitioned into the two intervals [0,8] and (8,infinity).

For more information, see:

Examples

Consider the query qColt12 in Example 10-70. Given the data stream SColtFunc with schema (c1 integer, c2 double, c3 bigint) in Example 10-71, the query returns the relation in Example 10-72.

Example 10-70 i0 Function Query

<query id="qColt12"><![CDATA[ 
    select i0(c2) from SColtFunc
]]></query>

Example 10-71 i0 Function Stream Input

Timestamp   Tuple
  10        1,0.5,8
1000        4,0.7,6
1200        3,0.89,12
2000        8,0.4,4

Example 10-72 i0 Function Relation Output

Timestamp   Tuple Kind  Tuple
  10:       +           1.0634834
1000:       +           1.126303 
1200:       +           1.2080469
2000:       +           1.0404018

i0e

Syntax

Surrounding text describes i0e.png.

Purpose

i0e is based on cern.jet.math.Bessel. It returns the exponentially scaled modified Bessel function of order 0 of the double argument as a double.

The function is defined as: i0e(x) = exp(-|x|) j0(ix).

For more information, see:

Examples

Consider the query qColt13 in Example 10-73. Given the data stream SColtFunc with schema (c1 integer, c2 double, c3 bigint) in Example 10-74, the query returns the relation in Example 10-75.

Example 10-73 i0e Function Query

<query id="qColt13"><![CDATA[ 
    select i0e(c2) from SColtFunc
]]></query>

Example 10-74 i0e Function Stream Input

Timestamp   Tuple
  10        1,0.5,8
1000        4,0.7,6
1200        3,0.89,12
2000        8,0.4,4

Example 10-75 i0e Function Relation Output

Timestamp   Tuple Kind  Tuple
  10:       +           0.64503527
1000:       +           0.55930555
1200:       +           0.4960914 
2000:       +           0.6974022 

i1

Syntax

Surrounding text describes i1.png.

Purpose

i1 is based on cern.jet.math.Bessel. It returns the modified Bessel function of order 1 of the double argument as a double.

The function is defined as: i1(x) = -i j1(ix).

The range is partitioned into the two intervals [0,8] and (8,infinity). Chebyshev polynomial expansions are employed in each interval.

For more information, see:

Examples

Consider the query qColt14 in Example 10-76. Given the data stream SColtFunc with schema (c1 integer, c2 double, c3 bigint) in Example 10-77, the query returns the relation in Example 10-78.

Example 10-76 i1 Function Query

<query id="qColt14"><![CDATA[ 
    select i1(c2) from SColtFunc
]]></query>

Example 10-77 i1 Function Stream Input

Timestamp   Tuple
  10        1,0.5,8
1000        4,0.7,6
1200        3,0.89,12
2000        8,0.4,4

Example 10-78 i1 Function Relation Output

Timestamp   Tuple Kind  Tuple
  10:       +           0.2578943 
1000:       +           0.37187967
1200:       +           0.49053898
2000:       +           0.20402676

i1e

Syntax

Surrounding text describes i1e.png.

Purpose

i1e is based on cern.jet.math.Bessel. It returns the exponentially scaled modified Bessel function of order 1 of the double argument as a double.

The function is defined as i1(x) = -i exp(-|x|) j1(ix).

For more information, see

Examples

Consider the query qColt15 in Example 10-79. Given the data stream SColtFunc with schema (c1 integer, c2 double, c3 bigint) in Example 10-80, the query returns the relation in Example 10-81.

Example 10-79 i1e Function Query

<query id="qColt15"><![CDATA[ 
    select i1e(c2) from SColtFunc
]]></query>

Example 10-80 i1e Function Stream Input

Timestamp   Tuple
  10        1,0.5,8
1000        4,0.7,6
1200        3,0.89,12
2000        8,0.4,4

Example 10-81 i1e Function Relation Output

Timestamp   Tuple Kind  Tuple
  10:       +           0.1564208 
1000:       +           0.18466999
1200:       +           0.20144266
2000:       +           0.13676323

incompleteBeta

Syntax

Surrounding text describes incompletebeta.png.

Purpose

incompleteBeta is based on cern.jet.stat.Gamma. It returns the Incomplete Beta Function evaluated from zero to x as a double.

This function takes the following arguments:

  • double1: the beta distribution alpha value a

  • double2: the beta distribution beta value b

  • double3: the integration end point x

For more information, see http://dsd.lbl.gov/~hoschek/colt/api/cern/jet/stat/Gamma.html#incompleteBeta(double,%20double,%20double).

Examples

Consider the query qColt30 in Example 10-82. Given the data stream SColtFunc with schema (c1 integer, c2 double, c3 bigint) in Example 10-83, the query returns the relation in Example 10-84.

Example 10-82 incompleteBeta Function Query

<query id="qColt30"><![CDATA[ 
    select incompleteBeta(c2,c2,c2) from SColtFunc
]]></query>

Example 10-83 incompleteBeta Function Stream Input

Timestamp   Tuple
  10        1,0.5,8
1000        4,0.7,6
1200        3,0.89,12
2000        8,0.4,4

Example 10-84 incompleteBeta Function Relation Output

Timestamp   Tuple Kind  Tuple
  10:       +           0.5       
1000:       +           0.66235894
1200:       +           0.873397  
2000:       +           0.44519535

incompleteGamma

Syntax

Surrounding text describes incompletegamma.png.

Purpose

incompleteGamma is based on cern.jet.stat.Gamma. It returns the Incomplete Gamma function of the arguments as a double.

This function takes the following arguments:

  • double1: the gamma distribution alpha value a.

  • double2: the integration end point x.

For more information, see http://dsd.lbl.gov/~hoschek/colt/api/cern/jet/stat/Gamma.html#incompleteGamma(double,%20double).

Examples

Consider the query qColt31 in Example 10-85. Given the data stream SColtFunc with schema (c1 integer, c2 double, c3 bigint) in Example 10-86, the query returns the relation in Example 10-87.

Example 10-85 incompleteGamma Function Query

<query id="qColt31"><![CDATA[ 
    select incompleteGamma(c2,c2) from SColtFunc
]]></query>

Example 10-86 incompleteGamma Function Stream Input

Timestamp   Tuple
  10        1,0.5,8
1000        4,0.7,6
1200        3,0.89,12
2000        8,0.4,4

Example 10-87 incompleteGamma Function Relation Output

Timestamp   Tuple Kind  Tuple
  10:       +           0.6826895
1000:       +           0.6565891
1200:       +           0.6397422
2000:       +           0.7014413

incompleteGammaComplement

Syntax

Surrounding text describes incompletegammacomplement.png.

Purpose

incompleteGammaComplement is based on cern.jet.stat.Gamma. It returns the Complemented Incomplete Gamma function of the arguments as a double.

This function takes the following arguments:

  • double1: the gamma distribution alpha value a.

  • double2: the integration start point x.

For more information, see http://dsd.lbl.gov/~hoschek/colt/api/cern/jet/stat/Gamma.html#incompleteGammaComplement(double,%20double).

Examples

Consider the query qColt32 in Example 10-88. Given the data stream SColtFunc with schema (c1 integer, c2 double, c3 bigint) in Example 10-89, the query returns the relation in Example 10-90.

Example 10-88 incompleteGammaComplement Function Query

<query id="qColt32"><![CDATA[ 
    select incompleteGammaComplement(c2,c2) from SColtFunc
]]></query>

Example 10-89 incompleteGammaComplement Function Stream Input

Timestamp   Tuple
  10        1,0.5,8
1000        4,0.7,6
1200        3,0.89,12
2000        8,0.4,4

Example 10-90 incompleteGammaComplement Function Relation Output

Timestamp   Tuple Kind  Tuple
  10:       +           0.3173105 
1000:       +           0.34341094
1200:       +           0.3602578 
2000:       +           0.29855874

j0

Syntax

Surrounding text describes j0.png.

Purpose

j0 is based on cern.jet.math.Bessel. It returns the Bessel function of the first kind of order 0 of the double argument as a double.

For more information, see http://dsd.lbl.gov/~hoschek/colt/api/cern/jet/math/Bessel.html#j0(double).

Examples

Consider the query qColt16 in Example 10-91. Given the data stream SColtFunc with schema (c1 integer, c2 double, c3 bigint) in Example 10-92, the query returns the relation in Example 10-93.

Example 10-91 j0 Function Query

<query id="qColt16"><![CDATA[ 
    select j0(c2) from SColtFunc
]]></query>

Example 10-92 j0 Function Stream Input

Timestamp   Tuple
  10        1,0.5,8
1000        4,0.7,6
1200        3,0.89,12
2000        8,0.4,4

Example 10-93 j0 Function Relation Output

Timestamp   Tuple Kind  Tuple
  10:       +           0.9384698
1000:       +           0.8812009
1200:       +           0.8115654
2000:       +           0.9603982

j1

Syntax

Surrounding text describes j1.png.

Purpose

j1 is based on cern.jet.math.Bessel. It returns the Bessel function of the first kind of order 1 of the double argument as a double.

For more information, see http://dsd.lbl.gov/~hoschek/colt/api/cern/jet/math/Bessel.html#j1(double).

Examples

Consider the query qColt17 in Example 10-94. Given the data stream SColtFunc with schema (c1 integer, c2 double, c3 bigint) in Example 10-95, the query returns the relation in Example 10-96.

Example 10-94 j1 Function Query

<query id="qColt17"><![CDATA[ 
    select j1(c2) from SColtFunc
]]></query>

Example 10-95 j1 Function Stream Input

Timestamp   Tuple
  10        1,0.5,8
1000        4,0.7,6
1200        3,0.89,12
2000        8,0.4,4

Example 10-96 j1 Function Relation Output

Timestamp   Tuple Kind  Tuple
  10:       +           0.24226846
1000:       +           0.32899573
1200:       +           0.40236986
2000:       +           0.19602658

jn

Syntax

Surrounding text describes jn.png.

Purpose

jn is based on cern.jet.math.Bessel. It returns the Bessel function of the first kind of order n of the argument as a double.

This function takes the following arguments:

  • integer1: the order of the Bessel function n.

  • double2: the value to compute the bessel function of x.

For more information, see http://dsd.lbl.gov/~hoschek/colt/api/cern/jet/math/Bessel.html#jn(int,%20double).

Examples

Consider the query qColt18 in Example 10-97. Given the data stream SColtFunc with schema (c1 integer, c2 double, c3 bigint) in Example 10-98, the query returns the relation in Example 10-99.

Example 10-97 jn Function Query

<query id="qColt18"><![CDATA[ 
    select jn(c1,c2) from SColtFunc
]]></query>

Example 10-98 jn Function Stream Input

Timestamp   Tuple
  10        1,0.5,8
1000        4,0.7,6
1200        3,0.89,12
2000        8,0.4,4

Example 10-99 jn Function Relation Output

Timestamp   Tuple Kind  Tuple
  10:       +           0.24226846  
1000:       +           6.1009696E-4
1200:       +           0.0139740035
2000:       +           6.321045E-11

k0

Syntax

Surrounding text describes k0.png.

Purpose

k0 is based on cern.jet.math.Bessel. It returns the modified Bessel function of the third kind of order 0 of the double argument as a double.

The range is partitioned into the two intervals [0,8] and (8, infinity). Chebyshev polynomial expansions are employed in each interval.

For more information, see http://dsd.lbl.gov/~hoschek/colt/api/cern/jet/math/Bessel.html#k0(double).

Examples

Consider the query qColt19 in Example 10-100. Given the data stream SColtFunc with schema (c1 integer, c2 double, c3 bigint) in Example 10-101, the query returns the relation in Example 10-102.

Example 10-100 k0 Function Query

<query id="qColt19"><![CDATA[ 
    select k0(c2) from SColtFunc
]]></query>

Example 10-101 k0 Function Stream Input

Timestamp   Tuple
  10        1,0.5,8
1000        4,0.7,6
1200        3,0.89,12
2000        8,0.4,4

Example 10-102 k0 Function Relation Output

Timestamp   Tuple Kind  Tuple
  10:       +           0.92441905
1000:       +           0.6605199 
1200:       +           0.49396032
2000:       +           1.1145291 

k0e

Syntax

Surrounding text describes k0e.png.

Purpose

k0e is based on cern.jet.math.Bessel. It returns the exponentially scaled modified Bessel function of the third kind of order 0 of the double argument as a double.

For more information, see http://dsd.lbl.gov/~hoschek/colt/api/cern/jet/math/Bessel.html#k0e(double).

Examples

Consider the query qColt20 in Example 10-103. Given the data stream SColtFunc with schema (c1 integer, c2 double, c3 bigint) in Example 10-104, the query returns the relation in Example 10-105.

Example 10-103 k0e Function Query

<query id="qColt20"><![CDATA[ 
    select k0e(c2) from SColtFunc
]]></query>

Example 10-104 k0e Function Stream Input

Timestamp   Tuple
  10        1,0.5,8
1000        4,0.7,6
1200        3,0.89,12
2000        8,0.4,4

Example 10-105 k0e Function Relation Output

Timestamp   Tuple Kind  Tuple
  10:       +           1.5241094
1000:       +           1.3301237
1200:       +           1.2028574
2000:       +           1.662682 

k1

Syntax

Surrounding text describes k1.png.

Purpose

k1 is based on cern.jet.math.Bessel. It returns the modified Bessel function of the third kind of order 1 of the double argument as a double.

The range is partitioned into the two intervals [0,2] and (2, infinity). Chebyshev polynomial expansions are employed in each interval.

For more information, see http://dsd.lbl.gov/~hoschek/colt/api/cern/jet/math/Bessel.html#k1(double).

Examples

Consider the query qColt21 in Example 10-106. Given the data stream SColtFunc with schema (c1 integer, c2 double, c3 bigint) in Example 10-107, the query returns the relation in Example 10-108.

Example 10-106 k1 Function Query

<query id="qColt21"><![CDATA[ 
    select k1(c2) from SColtFunc
]]></query>

Example 10-107 k1 Function Stream Input

Timestamp   Tuple
  10        1,0.5,8
1000        4,0.7,6
1200        3,0.89,12
2000        8,0.4,4

Example 10-108 k1 Function Relation Output

Timestamp   Tuple Kind  Tuple
  10:       +           1.6564411
1000:       +           1.0502836
1200:       +           0.7295154
2000:       +           2.1843543

k1e

Syntax

Surrounding text describes k1e.png.

Purpose

k1e is based on cern.jet.math.Bessel. It returns the exponentially scaled modified Bessel function of the third kind of order 1 of the double argument as a double.

The function is defined as: k1e(x) = exp(x) * k1(x).

For more information, see:

Examples

Consider the query qColt22 in Example 10-109. Given the data stream SColtFunc with schema (c1 integer, c2 double, c3 bigint) in Example 10-110, the query returns the relation in Example 10-111.

Example 10-109 k1e Function Query

<query id="qColt22"><![CDATA[ 
    select k1e(c2) from SColtFunc
]]></query>

Example 10-110 k1e Function Stream Input

Timestamp   Tuple
  10        1,0.5,8
1000        4,0.7,6
1200        3,0.89,12
2000        8,0.4,4

Example 10-111 k1e Function Relation Output

Timestamp   Tuple Kind  Tuple
  10:       +           2.7310097
1000:       +           2.1150115
1200:       +           1.7764645
2000:       +           3.258674 

kn

Syntax

Surrounding text describes kn.png.

Purpose

kn is based on cern.jet.math.Bessel. It returns the modified Bessel function of the third kind of order n of the argument as a double.

This function takes the following arguments:

  • integer1: the n value order of the Bessel function.

  • double2: the x value to compute the bessel function of.

The range is partitioned into the two intervals [0,9.55] and (9.55, infinity). An ascending power series is used in the low range, and an asymptotic expansion in the high range.

For more information, see http://dsd.lbl.gov/~hoschek/colt/api/cern/jet/math/Bessel.html#kn(int,%20double).

Examples

Consider the query qColt23 in Example 10-112. Given the data stream SColtFunc with schema (c1 integer, c2 double, c3 bigint) in Example 10-113, the query returns the relation in Example 10-114.

Example 10-112 kn Function Query

<query id="qColt23"><![CDATA[ 
    select kn(c1,c2) from SColtFunc
]]></query>

Example 10-113 kn Function Stream Input

Timestamp   Tuple
  10        1,0.5,8
1000        4,0.7,6
1200        3,0.89,12
2000        8,0.4,4

Example 10-114 kn Function Relation Output

Timestamp   Tuple Kind  Tuple
  10:       +             1.6564411  
1000:       +           191.99422    
1200:       +            10.317473   
2000:       +             9.7876858E8

leastSignificantBit

Syntax

Surrounding text describes leastsignificantbit.png.

Purpose

leastSignificantBit is based on cern.colt.bitvector.QuickBitVector. It returns the index (as an integer) of the least significant bit in state true of the integer argument. Returns 32 if no bit is in state true.

For more information, see:

Examples

Consider the query qColt54 in Example 10-115. Given the data stream SColtFunc with schema (c1 integer, c2 double, c3 bigint) in Example 10-116, the query returns the relation in Example 10-117.

Example 10-115 leastSignificantBit Function Query

<query id="qColt54"><![CDATA[ 
    select leastSignificantBit(c1) from SColtFunc
]]></query>

Example 10-116 leastSignificantBit Function Stream Input

Timestamp   Tuple
  10        1,0.5,8
1000        4,0.7,6
1200        3,0.89,12
2000        8,0.4,4

Example 10-117 leastSignificantBit Function Relation Output

Timestamp   Tuple Kind  Tuple
  10:       +           0
1000:       +           2
1200:       +           0
2000:       +           3

log

Syntax

Surrounding text describes log.png.

Purpose

log is based on cern.jet.math.Arithmetic. It returns the computation that Figure 10-11 shows as a double.

Figure 10-11 cern.jet.math.Arithmetic log

Surrounding text describes Figure 10-11 .

This function takes the following arguments:

  • double1: the base.

  • double2: the value.

For more information, see http://dsd.lbl.gov/~hoschek/colt/api/cern/jet/math/Arithmetic.html#log(double,%20double).

Examples

Consider the query qColt3 in Example 10-118. Given the data stream SColtFunc with schema (c1 integer, c2 double, c3 bigint) in Example 10-119, the query returns the relation in Example 10-120.

Example 10-118 log Function Query

<query id="qColt3"><![CDATA[ 
    select log(c2,c2) from SColtFunc
]]></query>

Example 10-119 log Function Stream Input

Timestamp   Tuple
  10        1,0.5,8
1000        4,0.7,6
1200        3,0.89,12
2000        8,0.4,4

Example 10-120 log Function Relation Output

Timestamp   Tuple Kind  Tuple
  10:       +           1.0
1000:       +           1.0
1200:       +           1.0
2000:       +           1.0

log10

Syntax

Surrounding text describes log10.png.

Purpose

log10 is based on cern.jet.math.Arithmetic. It returns the base 10 logarithm of a double value as a double.

For more information, see http://dsd.lbl.gov/~hoschek/colt/api/cern/jet/math/Arithmetic.html#log10(double).

Examples

Consider the query qColt4 in Example 10-121. Given the data stream SColtFunc with schema (c1 integer, c2 double, c3 bigint) in Example 10-122, the query returns the relation in Example 10-123.

Example 10-121 log10 Function Query

<query id="qColt4"><![CDATA[ 
    select log10(c2) from SColtFunc
]]></query>

Example 10-122 log10 Function Stream Input

Timestamp   Tuple
  10        1,0.5,8
1000        4,0.7,6
1200        3,0.89,12
2000        8,0.4,4

Example 10-123 log10 Function Relation Output

Timestamp   Tuple Kind  Tuple
  10:       +           -0.30103    
1000:       +           -0.15490197 
1200:       +           -0.050610002
2000:       +           -0.39794    

log2

Syntax

Surrounding text describes log2.png.

Purpose

log2 is based on cern.jet.math.Arithmetic. It returns the base 2 logarithm of a double value as a double.

For more information, see http://dsd.lbl.gov/~hoschek/colt/api/cern/jet/math/Arithmetic.html#log2(double).

Examples

Consider the query qColt9 in Example 10-124. Given the data stream SColtFunc with schema (c1 integer, c2 double, c3 bigint) in Example 10-125, the query returns the relation in Example 10-126.

Example 10-124 log2 Function Query

<query id="qColt9"><![CDATA[ 
    select log2(c2) from SColtFunc
]]></query>

Example 10-125 log2 Function Stream Input

Timestamp   Tuple
  10        1,0.5,8
1000        4,0.7,6
1200        3,0.89,12
2000        8,0.4,4

Example 10-126 log2 Function Relation Output

Timestamp   Tuple Kind  Tuple
  10:       +           -1.0       
1000:       +           -0.5145732 
1200:       +           -0.16812278
2000:       +           -1.321928  

logFactorial

Syntax

Surrounding text describes logfactorial.png.

Purpose

logFactorial is based on cern.jet.math.Arithmetic. It returns the natural logarithm (base e) of the factorial of its integer argument as a double

For argument values k<30, the function looks up the result in a table in O(1). For argument values k>=30, the function uses Stirlings approximation.

For more information, see http://dsd.lbl.gov/~hoschek/colt/api/cern/jet/math/Arithmetic.html#logFactorial(int).

Examples

Consider the query qColt10 in Example 10-127. Given the data stream SColtFunc with schema (c1 integer, c2 double, c3 bigint) in Example 10-128, the query returns the relation in Example 10-129.

Example 10-127 logFactorial Function Query

<query id="qColt10"><![CDATA[ 
    select logFactorial(c1) from SColtFunc
]]></query>

Example 10-128 logFactorial Function Stream Input

Timestamp   Tuple
  10        1,0.5,8
1000        4,0.7,6
1200        3,0.89,12
2000        8,0.4,4

Example 10-129 logFactorial Function Relation Output

Timestamp   Tuple Kind  Tuple
  10:       +            0.0      
1000:       +            3.1780539
1200:       +            1.7917595
2000:       +           10.604603 

logGamma

Syntax

Surrounding text describes loggamma.png.

Purpose

logGamma is based on cern.jet.stat.Gamma. It returns the natural logarithm (base e) of the gamma function of the double argument as a double.

For more information, see http://dsd.lbl.gov/~hoschek/colt/api/cern/jet/stat/Gamma.html#logGamma(double).

Examples

Consider the query qColt33 in Example 10-130. Given the data stream SColtFunc with schema (c1 integer, c2 double, c3 bigint) in Example 10-131, the query returns the relation in Example 10-132.

Example 10-130 logGamma Function Query

<query id="qColt33"><![CDATA[ 
    select logGamma(c2) from SColtFunc
]]></query>

Example 10-131 logGamma Function Stream Input

Timestamp   Tuple
  10        1,0.5,8
1000        4,0.7,6
1200        3,0.89,12
2000        8,0.4,4

Example 10-132 logGamma Function Relation Output

Timestamp   Tuple Kind  Tuple
  10:       +           0.5723649 
1000:       +           0.26086727
1200:       +           0.07402218
2000:       +           0.7966778 

longFactorial

Syntax

Surrounding text describes longfactorial.png.

Purpose

longFactorial is based on cern.jet.math.Arithmetic. It returns the factorial of its integer argument (in the range k >= 0 && k < 21) as a long.

For more information, see http://dsd.lbl.gov/~hoschek/colt/api/cern/jet/math/Arithmetic.html#longFactorial(int).

Examples

Consider the query qColt11 in Example 10-133. Given the data stream SColtFunc with schema (c1 integer, c2 double, c3 bigint) in Example 10-134, the query returns the relation in Example 10-135.

Example 10-133 longFactorial Function Query

<query id="qColt11"><![CDATA[ 
    select longFactorial(c1) from SColtFunc
]]></query>

Example 10-134 longFactorial Function Stream Input

Timestamp   Tuple
  10        1,0.5,8
1000        4,0.7,6
1200        3,0.89,12
2000        8,0.4,4

Example 10-135 longFactorial Function Relation Output

Timestamp   Tuple Kind  Tuple
  10:       +           1
1000:       +           24
1200:       +           6
2000:       +           40320

mostSignificantBit

Syntax

Surrounding text describes mostsignificantbit.png.

Purpose

mostSignificantBit is based on cern.colt.bitvector.QuickBitVector. It returns the index (as an integer) of the most significant bit in state true of the integer argument. Returns -1 if no bit is in state true

For more information, see:

Examples

Consider the query qColt55 in Example 10-136. Given the data stream SColtFunc with schema (c1 integer, c2 double, c3 bigint) in Example 10-137, the query returns the relation in Example 10-138.

Example 10-136 mostSignificantBit Function Query

<query id="qColt55"><![CDATA[ 
    select mostSignificantBit(c1) from SColtFunc
]]></view>

Example 10-137 mostSignificantBit Function Stream Input

Timestamp   Tuple
  10        1,0.5,8
1000        4,0.7,6
1200        3,0.89,12
2000        8,0.4,4

Example 10-138 mostSignificantBit Function Relation Output

Timestamp   Tuple Kind  Tuple
  10:       +           0
1000:       +           2
1200:       +           1
2000:       +           3

negativeBinomial

Syntax

Surrounding text describes negativebinomial.png.

Purpose

negativeBinomial is based on cern.jet.stat.Probability. It returns the sum of the terms 0 through k of the Negative Binomial Distribution (see Figure 10-12) as a double.

Figure 10-12 cern.jet.stat.Probability negativeBinomial

Surrounding text describes Figure 10-12 .

This function takes the following arguments:

  • integer1: the end term k.

  • integer2: the number of trials n.

  • double3: the probability of success p in (0.0,1.0).

For more information, see http://dsd.lbl.gov/~hoschek/colt/api/cern/jet/stat/Probability.html#negativeBinomial(int,%20int,%20double).

Examples

Consider the query qColt44 in Example 10-139. Given the data stream SColtFunc with schema (c1 integer, c2 double, c3 bigint) in Example 10-140, the query returns the relation in Example 10-141.

Example 10-139 negativeBinomial Function Query

<query id="qColt44"><![CDATA[ 
    select negativeBinomial(c1,c1,c2) from SColtFunc
]]></query>

Example 10-140 negativeBinomial Function Stream Input

Timestamp   Tuple
  10        1,0.5,8
1000        4,0.7,6
1200        3,0.89,12
2000        8,0.4,4

Example 10-141 negativeBinomial Function Relation Output

Timestamp   Tuple Kind  Tuple
  10:       +           0.75      
1000:       +           0.94203234
1200:       +           0.99817264
2000:       +           0.28393665

negativeBinomialComplemented

Syntax

Surrounding text describes negatievbinomialcompl.png.

Purpose

negativeBinomialComplemented is based on cern.jet.stat.Probability. It returns the sum of the terms k+1 to infinity of the Negative Binomial distribution (see Figure 10-13) as a double.

Figure 10-13 cern.jet.stat.Probability negativeBinomialComplemented

Surrounding text describes Figure 10-13 .

This function takes the following arguments:

  • integer1: the end term k.

  • integer2: the number of trials n.

  • double3: the probability of success p in (0.0,1.0).

For more information, see http://dsd.lbl.gov/~hoschek/colt/api/cern/jet/stat/Probability.html#negativeBinomialComplemented(int,%20int,%20double).

Examples

Consider the query qColt45 in Example 10-142. Given the data stream SColtFunc with schema (c1 integer, c2 double, c3 bigint) in Example 10-143, the query returns the relation in Example 10-144.

Example 10-142 negativeBinomialComplemented Function Query

<query id="qColt45"><![CDATA[ 
    select negativeBinomialComplemented(c1,c1,c2) from SColtFunc
]]></query>

Example 10-143 negativeBinomialComplemented Function Stream Input

Timestamp   Tuple
  10        1,0.5,8
1000        4,0.7,6
1200        3,0.89,12
2000        8,0.4,4

Example 10-144 negativeBinomialComplemented Function Relation Output

Timestamp   Tuple Kind  Tuple
  10:       +           0.25        
1000:       +           0.05796766  
1200:       +           0.0018273441
2000:       +           0.7160633   

normal

Syntax

Surrounding text describes normal.png.

Purpose

normal is based on cern.jet.stat.Probability. It returns the area under the Normal (Gaussian) probability density function, integrated from minus infinity to the double argument x (see Figure 10-14) as a double.

Figure 10-14 cern.jet.stat.Probability normal

Surrounding text describes Figure 10-14 .

For more information, see http://dsd.lbl.gov/~hoschek/colt/api/cern/jet/stat/Probability.html#normal(double).

Examples

Consider the query qColt46 in Example 10-145. Given the data stream SColtFunc with schema (c1 integer, c2 double, c3 bigint) in Example 10-146, the query returns the relation in Example 10-147.

Example 10-145 normal Function Query

<query id="qColt46"><![CDATA[ 
    select normal(c2) from SColtFunc
]]></query>

Example 10-146 normal Function Stream Input

Timestamp   Tuple
  10        1,0.5,8
1000        4,0.7,6
1200        3,0.89,12
2000        8,0.4,4

Example 10-147 normal Function Relation Output

Timestamp   Tuple Kind  Tuple
  10:       +           0.69146246
1000:       +           0.7580363 
1200:       +           0.81326705
2000:       +           0.65542173

normal1

Syntax

Surrounding text describes normal1.png.

Purpose

normal1 is based on cern.jet.stat.Probability. It returns the area under the Normal (Gaussian) probability density function, integrated from minus infinity to x (see Figure 10-15) as a double.

Figure 10-15 cern.jet.stat.Probability normal1

Surrounding text describes Figure 10-15 .

This function takes the following arguments:

  • double1: the normal distribution mean.

  • double2: the variance of the normal distribution v.

  • double3: the integration limit x.

For more information, see http://dsd.lbl.gov/~hoschek/colt/api/cern/jet/stat/Probability.html#normal(double,%20double,%20double).

Examples

Consider the query qColt47 in Example 10-148. Given the data stream SColtFunc with schema (c1 integer, c2 double, c3 bigint) in Example 10-149, the query returns the relation in Example 10-150.

Example 10-148 normal1 Function Query

<query id="qColt47"><![CDATA[ 
    select normal1(c2,c2,c2) from SColtFunc
]]></query>

Example 10-149 normal1 Function Stream Input

Timestamp   Tuple
  10        1,0.5,8
1000        4,0.7,6
1200        3,0.89,12
2000        8,0.4,4

Example 10-150 normal1 Function Relation Output

Timestamp   Tuple Kind  Tuple
  10:       +           0.5
1000:       +           0.5
1200:       +           0.5
2000:       +           0.5

normalInverse

Syntax

Surrounding text describes normalinverse.png.

Purpose

normalInverse is based on cern.jet.stat.Probability. It returns the double value, x, for which the area under the Normal (Gaussian) probability density function (integrated from minus infinity to x) equals the double argument y (assumes mean is zero and variance is one).

For more information, see http://dsd.lbl.gov/~hoschek/colt/api/cern/jet/stat/Probability.html#normalInverse(double).

Examples

Consider the query qColt48 in Example 10-151. Given the data stream SColtFunc with schema (c1 integer, c2 double, c3 bigint) in Example 10-152, the query returns the relation in Example 10-153.

Example 10-151 normalInverse Function Query

<query id="qColt48"><![CDATA[ 
    select normalInverse(c2) from SColtFunc
]]></view>

Example 10-152 normalInverse Function Stream Input

Timestamp   Tuple
  10        1,0.5,8
1000        4,0.7,6
1200        3,0.89,12
2000        8,0.4,4

Example 10-153 normalInverse Function Relation Output

Timestamp   Tuple Kind  Tuple
  10:       +           0.0      
1000:       +           0.5244005
1200:       +           1.226528 
2000:       +           0.2533471

poisson

Syntax

Surrounding text describes poisson.png.

Purpose

poisson is based on cern.jet.stat.Probability. It returns the sum of the first k terms of the Poisson distribution (see Figure 10-16) as a double.

Figure 10-16 cern.jet.stat.Probability poisson

Surrounding text describes Figure 10-16 .

This function takes the following arguments:

  • integer1: the number of terms k.

  • double2: the mean of the Poisson distribution m.

For more information, see http://dsd.lbl.gov/~hoschek/colt/api/cern/jet/stat/Probability.html#poisson(int,%20double).

Examples

Consider the query qColt49 in Example 10-154. Given the data stream SColtFunc with schema (c1 integer, c2 double, c3 bigint) in Example 10-155, the query returns the relation in Example 10-156.

Example 10-154 poisson Function Query

<query id="qColt49"><![CDATA[ 
    select poisson(c1,c2) from SColtFunc
]]></query>

Example 10-155 poisson Function Stream Input

Timestamp   Tuple
  10        1,0.5,8
1000        4,0.7,6
1200        3,0.89,12
2000        8,0.4,4

Example 10-156 poisson Function Relation Output

Timestamp   Tuple Kind  Tuple
  10:       +           0.909796 
1000:       +           0.9992145
1200:       +           0.9870295
2000:       +           1.0      

poissonComplemented

Syntax

Surrounding text describes poissoncomplemented.png.

Purpose

poissonComplemented is based on cern.jet.stat.Probability. It returns the sum of the terms k+1 to Infinity of the Poisson distribution (see Figure 10-17) as a double.

Figure 10-17 cern.jet.stat.Probability poissonComplemented

Surrounding text describes Figure 10-17 .

This function takes the following arguments:

  • integer1: the start term k.

  • double2: the mean of the Poisson distribution m.

For more information, see http://dsd.lbl.gov/~hoschek/colt/api/cern/jet/stat/Probability.html#poissonComplemented(int,%20double).

Examples

Consider the query qColt50 in Example 10-157. Given the data stream SColtFunc with schema (c1 integer, c2 double, c3 bigint) in Example 10-158, the query returns the relation in Example 10-159.

Example 10-157 poissonComplemented Function Query

<query id="qColt50"><![CDATA[ 
    select poissonComplemented(c1,c2) from SColtFunc
]]></query>

Example 10-158 poissonComplemented Function Stream Input

Timestamp   Tuple
  10        1,0.5,8
1000        4,0.7,6
1200        3,0.89,12
2000        8,0.4,4

Example 10-159 poissonComplemented Function Relation Output

Timestamp   Tuple Kind  Tuple
  10:       +           0.09020401  
1000:       +           7.855354E-4 
1200:       +           0.012970487 
2000:       +           5.043364E-10

stirlingCorrection

Syntax

Surrounding text describes stirlingcorrection.png.

Purpose

stirlingCorrection is based on cern.jet.math.Arithmetic. It returns the correction term of the Stirling approximation of the natural logarithm (base e) of the factorial of the integer argument (see Figure 10-18) as a double.

Figure 10-18 cern.jet.math.Arithmetic stirlingCorrection

Surrounding text describes Figure 10-18 .

For more information, see http://dsd.lbl.gov/~hoschek/colt/api/cern/jet/math/Arithmetic.html#stirlingCorrection(int).

Examples

Consider the query qColt5 in Example 10-160. Given the data stream SColtFunc with schema (c1 integer, c2 double, c3 bigint) in Example 10-161, the query returns the relation in Example 10-162.

Example 10-160 stirlingCorrection Function Query

<query id="qColt5"><![CDATA[ 
    select stirlingCorrection(c1) from SColtFunc
]]></query>

Example 10-161 stirlingCorrection Function Stream Input

Timestamp   Tuple
  10        1,0.5,8
1000        4,0.7,6
1200        3,0.89,12
2000        8,0.4,4

Example 10-162 stirlingCorrection Function Relation Output

Timestamp   Tuple Kind  Tuple
  10:       +           0.08106147 
1000:       +           0.020790672
1200:       +           0.027677925
2000:       +           0.010411265

studentT

Syntax

Surrounding text describes studentt.png.

Purpose

studentT is based on cern.jet.stat.Probability. It returns the integral from minus infinity to t of the Student-t distribution with k > 0 degrees of freedom (see Figure 10-19) as a double.

Figure 10-19 cern.jet.stat.Probability studentT

Surrounding text describes Figure 10-19 .

This function takes the following arguments:

  • double1: the degrees of freedom k.

  • double2: the integration end point t.

For more information, see http://dsd.lbl.gov/~hoschek/colt/api/cern/jet/stat/Probability.html#studentT(double,%20double).

Examples

Consider the query qColt51 in Example 10-163. Given the data stream SColtFunc with schema (c1 integer, c2 double, c3 bigint) in Example 10-164, the query returns the relation in Example 10-165.

Example 10-163 studentT Function Query

<query id="qColt51"><![CDATA[ 
    select studentT(c2,c2) from SColtFunc
]]></query>

Example 10-164 studentT Function Stream Input

Timestamp   Tuple
  10        1,0.5,8
1000        4,0.7,6
1200        3,0.89,12
2000        8,0.4,4

Example 10-165 studentT Function Relation Output

Timestamp   Tuple Kind  Tuple
  10:       +           0.621341  
1000:       +           0.67624015
1200:       +           0.7243568 
2000:       +           0.5930112 

studentTInverse

Syntax

Surrounding text describes studenttinverse.png.

Purpose

studentTInverse is based on cern.jet.stat.Probability. It returns the double value, t, for which the area under the Student-t probability density function (integrated from minus infinity to t) equals 1-alpha/2. The value returned corresponds to the usual Student t-distribution lookup table for talpha[size]. This function uses the studentt function to determine the return value iteratively.

This function takes the following arguments:

  • double1: the probability alpha.

  • integer2: the data set size.

For more information, see:

Examples

Consider the query qColt52 in Example 10-166. Given the data stream SColtFunc with schema (c1 integer, c2 double, c3 bigint) in Example 10-167, the query returns the relation in Example 10-168.

Example 10-166 studentTInverse Function Query

<query id="qColt52"><![CDATA[ 
    select studentTInverse(c2,c1) from SColtFunc
]]></query>

Example 10-167 studentTInverse Function Stream Input

Timestamp   Tuple
  10        1,0.5,8
1000        4,0.7,6
1200        3,0.89,12
2000        8,0.4,4

Example 10-168 studentTInverse Function Relation Output

Timestamp   Tuple Kind  Tuple
  10:       +           1.0       
1000:       +           0.4141633 
1200:       +           0.15038916
2000:       +           0.8888911 

y0

Syntax

Surrounding text describes y0.png.

Purpose

y0 is based on cern.jet.math.Bessel. It returns the Bessel function of the second kind of order 0 of the double argument as a double.

For more information, see http://dsd.lbl.gov/~hoschek/colt/api/cern/jet/math/Bessel.html#y0(double).

Examples

Consider the query qColt24 in Example 10-169. Given the data stream SColtFunc with schema (c1 integer, c2 double, c3 bigint) in Example 10-170, the query returns the relation in Example 10-171.

Example 10-169 y0 Function Query

<query id="qColt24"><![CDATA[ 
    select y0(c2) from SColtFunc
]]></query>

Example 10-170 y0 Function Stream Input

Timestamp   Tuple
  10        1,0.5,8
1000        4,0.7,6
1200        3,0.89,12
2000        8,0.4,4

Example 10-171 y0 Function Relation Output

Timestamp   Tuple Kind  Tuple
  10:       +           -0.44451874  
1000:       +           -0.19066493  
1200:       +           -0.0031519707
2000:       +           -0.60602456  

y1

Syntax

Surrounding text describes y1.png.

Purpose

y1 is based on cern.jet.math.Bessel. It returns the Bessel function of the second kind of order 1 of the float argument as a double.

For more information, see http://dsd.lbl.gov/~hoschek/colt/api/cern/jet/math/Bessel.html#y1(double).

Examples

Consider the query qColt25 in Example 10-172. Given the data stream SColtFunc with schema (c1 integer, c2 double, c3 bigint) in Example 10-173, the query returns the relation in Example 10-174.

Example 10-172 y1 Function Query

<query id="qColt25"><![CDATA[ 
    select y1(c2) from SColtFunc
]]></query>

Example 10-173 y1 Function Stream Input

Timestamp   Tuple
  10        1,0.5,8
1000        4,0.7,6
1200        3,0.89,12
2000        8,0.4,4

Example 10-174 y1 Function Relation Output

Timestamp   Tuple Kind  Tuple
  10:       +           -1.4714724 
1000:       +           -1.1032499 
1200:       +           -0.88294965
2000:       +           -1.780872  

yn

Syntax

Surrounding text describes yn.png.

Purpose

yn is based on cern.jet.math.Bessel. It returns the Bessel function of the second kind of order n of the double argument as a double.

This function takes the following arguments:

  • integer1: the n value order of the Bessel function.

  • double2: the x value to compute the Bessel function of.

For more information, see http://dsd.lbl.gov/~hoschek/colt/api/cern/jet/math/Bessel.html#yn(int,%20double).

Examples

Consider the query qColt26 in Example 10-175. Given the data stream SColtFunc with schema (c1 integer, c2 double, c3 bigint) in Example 10-176, the query returns the relation in Example 10-177.

Example 10-175 yn Function Query

<query id="qColt26"><![CDATA[ 
    select yn(c1,c2) from SColtFunc
]]></query>

Example 10-176 yn Function Stream Input

Timestamp   Tuple
  10        1,0.5,8
1000        4,0.7,6
1200        3,0.89,12
2000        8,0.4,4

Example 10-177 yn Function Relation Output

Timestamp   Tuple Kind  Tuple
  10:       +             -1.4714724  
1000:       +           -132.63406    
1200:       +             -8.020442   
2000:       +             -6.3026547E8
PK IPKO_\EOEBPS/cql_elements.htm Basic Elements of Oracle CQL

2 Basic Elements of Oracle CQL

This chapter provides a reference for fundamental parts of Oracle Continuous Query Language (Oracle CQL), including datatypes, literals, nulls, and more. Oracle CQL is the query language used in Oracle Complex Event Processing (Oracle CEP) applications.

The basic elements of Oracle CQL include:

Before using the statements described in Part IV, "Using Oracle CQL", you should familiarize yourself with the concepts covered in this chapter.

2.1 Datatypes

Each value manipulated by Oracle CEP has a datatype. The datatype of a value associates a fixed set of properties with the value. These properties cause Oracle CEP to treat values of one datatype differently from values of another. For example, you can add values of INTEGER datatype, but not values of CHAR datatype.When you create a stream, you must specify a datatype for each of its elements. When you create a user-defined function, you must specify a datatype for each of its arguments. These datatypes define the domain of values that each element can contain or each argument can have. For example, attributes with TIMESTAMP as datatype cannot accept the value February 29 (except for a leap year) or the values 2 or 'SHOE'.Oracle CQL provides a number of built-in datatypes that you can use. The syntax of Oracle CQL datatypes appears in the diagrams that follow.

If Oracle CQL does not support a datatype that your events use, you can use an Oracle CQL data cartridge or a user-defined function to evaluate that datatype in an Oracle CQL query.

For more information, see:

datatype::=

Surrounding text describes datatype.png.

variable_length_datatype::=

Surrounding text describes variable_length_datatype.png.

fixed_length_datatype::=

Surrounding text describes fixed_length_datatype.png.

2.1.1 Oracle CQL Built-in Datatypes

Table 2-1 summarizes Oracle CQL built-in datatypes. Refer to the syntax in the preceding sections for the syntactic elements.

Consider these datatype and datatype literal restrictions when defining event types. For more information, see "Creating Oracle CEP Event Types" in the Oracle Fusion Middleware Developer's Guide for Oracle Complex Event Processing for Eclipse.

Table 2-1 Oracle CQL Built-in Datatype Summary

Oracle CQL DatatypeDescription

BIGINT

Fixed-length number equivalent to a Java Long type.

For more information, see Section 2.3.2, "Numeric Literals".

BOOLEAN

Fixed-length boolean equivalent to a Java Boolean type. Valid values are true or false.

BYTE[(size)]Foot 1 

Variable-length character data of length size bytes. Maximum size is 4096 bytes. Default and minimum size is 1 byte.

For more information, see Section 2.3.2, "Numeric Literals".

CHAR[(size)]Footref 1

Variable-length character data of length size characters. Maximum size is 4096 characters. Default and minimum size is 1 character.

For more information, see Section 2.3.1, "Text Literals".

DOUBLE

Fixed-length number equivalent to a Java double type.

For more information, see Section 2.3.2, "Numeric Literals".

FLOAT

Fixed-length number equivalent to a Java float type.

For more information, see Section 2.3.2, "Numeric Literals".

INTEGER

Fixed-length number equivalent to a Java int type.

For more information, see Section 2.3.2, "Numeric Literals".

INTERVAL

Fixed-length INTERVAL datatype specifies a period of time. Oracle CEP supports DAY TO SECOND. Maximum length is 64 bytes.

For more information, see Section 2.3.4, "Interval Literals".

TIMESTAMP

Fixed-length TIMESTAMP datatype stores a datetime literal that conforms to one of the java.text.SimpleDateFormat format models that Oracle CQL supports. Maximum length is 64 bytes.

For more information, see Section 2.3.3, "Datetime Literals".

XMLTYPE

Use this datatype for stream elements that contain XML data. Maximum length is 4096 characters.

XMLTYPE is a system-defined type, so you can use it as an argument of a function or as the datatype of a stream attribute.

For more information, see "SQL/XML (SQLX)".

OBJECT

This stands for any Java object (that is, any subclass of java.lang.Object).

We refer to this as opaque type support in Oracle CEP since the Oracle CEP engine does not understand the contents of an OBJECT field.

You typically use this type to pass values, from an adapter to its destination, as-is; these values need not be interpreted by the Oracle CEP engine (such as Collection types or any other user-specific Java type) but that are associated with the event whose other fields are referenced in a query.


Footnote 1 Oracle CQL supports single-dimension arrays only.

2.1.2 Handling Other Datatypes Using Oracle CQL Data Cartridges

If your event uses a datatype that Oracle CQL does not support, you can use an Oracle CQL data cartridge to evaluate that datatype in an Oracle CQL query.

Oracle CQL includes the following data cartridges:

For more information, see Chapter 14, "Introduction to Data Cartridges".

2.1.3 Handling Other Datatypes Using a User-Defined Function

If your event uses a datatype that Oracle CQL does not support, you can create a user-defined function to evaluate that datatype in an Oracle CQL query.

Consider the enum datatype that Example 2-1 shows. The event that Example 2-2 shows uses this enum datatype. Oracle CQL does not support enum datatypes.

Example 2-1 Enum Datatype ProcessStatus

package com.oracle.app;

public enum ProcessStatus {
    OPEN(1), 
    CLOSED(0)}
}

Example 2-2 Event Using Enum Datatype ProcessStatus

package com.oracle.app;

import com.oracle.capp.ProcessStatus;

public class ServiceOrder {
    private String serviceOrderId;
    private String electronicSerialNumber;
    private ProcessStatus status;
... 
}

By creating the user-defined function that Example 2-3 shows and registering the function in your application assembly file as Example 2-4 shows, you can evaluate this enum datatype in an Oracle CQL query as Example 2-5 shows.

Example 2-3 User-Defined Function to Evaluate Enum Datatype

package com.oracle.app;

import com.oracle.capp.ProcessStatus;
public class CheckIfStatusClosed {
    public boolean execute(Object[] args) {
        ProcessStatus arg0 = (ProcessStatus)args[0];
        if (arg0 == ProcessStatus.OPEN)
            return Boolean.FALSE;
        else
            return Boolean.TRUE;
    }
}

Example 2-4 Registering the User-Defined Function in Application Assembly File

<wlevs:processor id="testProcessor">
    <wlevs:listener ref="providerCache"/>
    <wlevs:listener ref="outputCache"/>
    <wlevs:cache-source ref="testCache"/>
    <wlevs:function function-name="statusClosed" exec-method=”execute” />
        <bean class="com.oracle.app.CheckIfStatusClosed"/>
    </wlevs:function>
</wlevs:processor>

Example 2-5 Using the User-Defined Function to Evaluate Enum Datatype in an Oracle CQL Query

<query id="rule-04"><![CDATA[
    SELECT
        meter.electronicSerialNumber, 
        meter.exceptionKind
    FROM 
        MeterLogEvent AS meter, 
        ServiceOrder AS svco
    WHERE 
        meter.electronicSerialNumber = svco.electronicSerialNumber and
        svco.serviceOrderId IS NULL OR statusClosed(svco.status)
]]></query>

For more information, see Chapter 13, "User-Defined Functions".

2.2 Datatype Comparison Rules

This section describes how Oracle CEP compares values of each datatype.

2.2.1 Numeric Values

A larger value is considered greater than a smaller one. All negative numbers are less than zero and all positive numbers. Thus, -1 is less than 100; -100 is less than -1.

2.2.2 Date Values

A later date is considered greater than an earlier one. For example, the date equivalent of '29-MAR-2005' is less than that of '05-JAN-2006' and '05-JAN-2006 1:35pm' is greater than '05-JAN-2005 10:09am'.

2.2.3 Character Values

Oracle CQL supports Lexicographic sort based on dictionary order.

Internally, Oracle CQL compares the numeric value of the char. Depending on the encoding used, the numeric values will differ, but in general, the comparison will remain the same. For example:

'a' < 'b'
'aa' < 'ab'
'aaaa' < 'aaaab'

2.2.4 Datatype Conversion

Generally an expression cannot contain values of different datatypes. For example, an arithmetic expression cannot multiply 5 by 10 and then add 'JAMES'. However, Oracle CEP supports both implicit and explicit conversion of values from one datatype to another.

Oracle recommends that you specify explicit conversions, rather than rely on implicit or automatic conversions, for these reasons:

  • Oracle CQL statements are easier to understand when you use explicit datatype conversion functions.

  • Implicit datatype conversion can have a negative impact on performance.

  • Implicit conversion depends on the context in which it occurs and may not work the same way in every case.

  • Algorithms for implicit conversion are subject to change across software releases and among Oracle products. Behavior of explicit conversions is more predictable.

This section describes:

2.2.4.1 Implicit Datatype Conversion

Oracle CEP automatically converts a value from one datatype to another when such a conversion makes sense.

Table 2-2 is a matrix of Oracle implicit conversions. The table shows all possible conversions (marked with an X). Unsupported conversions are marked with a --.

Table 2-2 Implicit Type Conversion Matrix


to CHARto BYTEto BOOLEANto INTEGERto DOUBLEto BIGINTto FLOATto TIMESTAMPto INTERVAL

from CHAR

--

--

--

--

--

--

--

X

--

from BYTE

X

--

--

--

--

--

--

--

--

from BOOLEAN

--

--

X

--

--

--

--

--

--

from INTEGER

X

--

--

--

X

X

X

--

--

from DOUBLE

X

--

--

--

X

--

--

--

--

from BIGINT

X

--

--

--

X

--

X

--

--

from FLOAT

X

--

--

--

X

--

--

--

--

from TIMESTAMP

X

--

--

--

--

--

--

--

--

from INTERVAL

X

--

--

--

--

--

--

--

--


The following rules govern the direction in which Oracle CEP makes implicit datatype conversions:

  • During SELECT FROM operations, Oracle CEP converts the data from the stream to the type of the target variable if the select clause contains arithmetic expressions or condition evaluations.

    For example, implicit conversions occurs in the context of expression evaluation, such as c1+2.0, or condition evaluation, such as c1 < 2.0, where c1 is of type INTEGER.

  • Conversions from FLOAT to BIGINT are exact.

  • Conversions from BIGINT to FLOAT are inexact if the BIGINT value uses more bits of precision that supported by the FLOAT.

  • When comparing a character value with a TIMESTAMP value, Oracle CEP converts the character data to TIMESTAMP.

  • When you use a Oracle CQL function or operator with an argument of a datatype other than the one it accepts, Oracle CEP converts the argument to the accepted datatype wherever supported.

  • When making assignments, Oracle CEP converts the value on the right side of the equal sign (=) to the datatype of the target of the assignment on the left side.

  • During concatenation operations, Oracle CEP converts from noncharacter datatypes to CHAR.

  • During arithmetic operations on and comparisons between character and noncharacter datatypes, Oracle CEP converts from numeric types to CHAR as Table 2-2 shows.

2.2.4.2 Explicit Datatype Conversion

You can explicitly specify datatype conversions using Oracle CQL conversion functions. Table 2-3 shows Oracle CQL functions that explicitly convert a value from one datatype to another. Unsupported conversions are marked with a --.

Table 2-3 Explicit Type Conversion Matrix


to CHARto BYTEto BOOLEANto INTEGERto DOUBLEto BIGINTto FLOATto TIMESTAMPto INTERVAL

from CHAR

--

hextoraw


--

--

--

--

--

to_timestamp


--

from BYTE

--

rawtohex


--

--

--

--

--

--

--

from BOOLEAN










from INTEGER

to_char


--

to_boolean


--

to_double


to_bigint


to_float


--

--

from DOUBLE

to_char


--

--

--

--

--

--

--

--

from LONG

--

--

--

--

--

--

--

to_timestamp


--

from BIGINT

to_char


--

to_boolean


--

to_double


--

to_float


--

--

from FLOAT

to_char


--

--

--

to_double


--

--

--

--

from TIMESTAMP

to_char


--

--

--

--

--

--

--

--

from INTERVAL

to_char


--

--

--

--

--

--

--

--


2.2.4.3 SQL Datatype Conversion

Using an Oracle CQL processor, you can specify a relational database table as an event source. You can query this event source, join it with other event sources, and so on. When doing so, you must observe the SQL and Oracle CEP data type equivalents that Oracle CEP supports.

For more information, see:

2.2.4.4 Oracle Data Cartridge Datatype Conversion

At run time, Oracle CEP maps between Oracle CQL and data cartridge datatypes according to the data cartridge's implementation.

For more information, see:

2.2.4.5 User-Defined Function Datatype Conversion

At run time, Oracle CEP maps between the Oracle CQL datatype you specify for a user-defined function's return type and its Java datatype equivalent.

For more information, see Section 13.1.2, "User-Defined Function Datatypes".

2.3 Literals

The terms literal and constant value are synonymous and refer to a fixed data value. For example, 'JACK', 'BLUE ISLAND', and '101' are all text literals; 5001 is a numeric literal.

Oracle CEP supports the following types of literals in Oracle CQL statements:

2.3.1 Text Literals

Use the text literal notation to specify values whenever const_string, quoted_string_double_quotes, or quoted_string_single_quotes appears in the syntax of expressions, conditions, Oracle CQL functions, and Oracle CQL statements in other parts of this reference. This reference uses the terms text literal, character literal, and string interchangeably.

Text literals are enclosed in single or double quotation marks so that Oracle CEP can distinguish them from schema object names.

You may use single quotation marks (') or double quotation marks ("). Typically, you use double quotation marks. However, for certain expressions, conditions, functions, and statements, you must use the quotation marks as specified in the syntax given in other parts of this reference: either quoted_string_double_quotes or quoted_string_single_quotes.

If the syntax uses simply const_string, then you can use either single or double quotation marks.

If the syntax uses the term char, then you can specify either a text literal or another expression that resolves to character data. When char appears in the syntax, the single quotation marks are not used.

Oracle CEP supports Java localization. You can specify text literals in the character set specified by your Java locale.

For more information, see:

2.3.2 Numeric Literals

Use numeric literal notation to specify fixed and floating-point numbers.

2.3.2.1 Integer Literals

You must use the integer notation to specify an integer whenever integer appears in expressions, conditions, Oracle CQL functions, and Oracle CQL statements described in other parts of this reference.

The syntax of integer follows:

integer::=

Surrounding text describes integer.png.

where digit is one of 0, 1, 2, 3, 4, 5, 6, 7, 8, 9.

An integer can store a maximum of 32 digits of precision.

Here are some valid integers:

7
+255

2.3.2.2 Floating-Point Literals

You must use the number or floating-point notation to specify values whenever number or n appears in expressions, conditions, Oracle CQL functions, and Oracle CQL statements in other parts of this reference.

The syntax of number follows:

number::=

Surrounding text describes number.png.

where

  • + or - indicates a positive or negative value. If you omit the sign, then a positive value is the default.

  • digit is one of 0, 1, 2, 3, 4, 5, 6, 7, 8 or 9.

  • f or F indicates that the number is a 64-bit binary floating point number of type FLOAT.

  • d or D indicates that the number is a 64-bit binary floating point number of type DOUBLE.

    If you omit f or F and d or D, then the number is of type INTEGER.

    The suffixes f or F and d or D are supported only in floating-point number literals, not in character strings that are to be converted to INTEGER. For example, if Oracle CEP is expecting an INTEGER and it encounters the string '9', then it converts the string to the Java Integer 9. However, if Oracle CEP encounters the string '9f', then conversion fails and an error is returned.

A number of type INTEGER can store a maximum of 32 digits of precision. If the literal requires more precision than provided by BIGINT or FLOAT, then Oracle CEP truncates the value. If the range of the literal exceeds the range supported by BIGINT or FLOAT, then Oracle CEP raises an error.

If your Java locale uses a decimal character other than a period (.), then you must specify numeric literals with 'text' notation. In these cases, Oracle CEP automatically converts the text literal to a numeric value.


Note:

You cannot use this notation for floating-point number literals.


For example, if your Java locale specifies a decimal character of comma (,), specify the number 5.123 as follows:

'5,123'

Here are some valid NUMBER literals:

25
+6.34
0.5
-1

Here are some valid floating-point number literals:

25f
+6.34F
0.5d
-1D

2.3.3 Datetime Literals

Oracle CEP supports datetime datatype TIMESTAMP.

Datetime literals must not exceed 64 bytes.

All datetime literals must conform to one of the java.text.SimpleDateFormat format models that Oracle CQL supports. For more information, see Section 2.4.2, "Datetime Format Models".

Currently, the SimpleDateFormat class does not support xsd:dateTime. As a result, Oracle CQL does not support XML elements or attributes that use this type.

For example, if your XML event uses an XSD like Example 2-6, Oracle CQL cannot parse the MyTimestamp element.

Example 2-6 Invalid Event XSD: xsd:dateTime is Not Supported

<xsd:element name="ComplexTypeBody">
    <xsd:complexType>
        <xsd:sequence>
            <xsd:element name="MyTimestamp" type="xsd:dateTime"/>
            <xsd:element name="ElementKind" type="xsd:string"/>
            <xsd:element name="name" type="xsd:string"/>
            <xsd:element name="node" type="SimpleType"/>
        </xsd:sequence>
    </xsd:complexType>
</xsd:element> 

Oracle recommends that you define your XSD to replace xsd:dateTime with xsd:string as Example 2-7 shows.

Example 2-7 Valid Event XSD: Using xsd:string Instead of xsd:dateTime

<xsd:element name="ComplexTypeBody">
    <xsd:complexType>
        <xsd:sequence>
            <xsd:element name="MyTimestamp" type="xsd:string"/>
            <xsd:element name="ElementKind" type="xsd:string"/>
            <xsd:element name="name" type="xsd:string"/>
            <xsd:element name="node" type="SimpleType"/>
        </xsd:sequence>
    </xsd:complexType>
</xsd:element> 

Using the XSD from Example 2-7, Oracle CQL can process events such as that shown in Example 2-8 as long as the Timestamp element's String value conforms to the java.text.SimpleDateFormat format models that Oracle CQL supports. For more information, see Section 2.4.2, "Datetime Format Models".

Example 2-8 XML Event Payload

<ComplexTypeBody xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ...>
  <MyTimestamp>2000-01-15T00:00:00</MyTimestamp>
  <ElementKind>plus</ElementKind>
  <name>complexEvent</name>
  <node>
    <type>complexNode</type>
    <number>1</number>
  </node>
</ComplexTypeBody>

For more information on using XML with Oracle CQL, see "SQL/XML (SQLX)".

2.3.4 Interval Literals

An interval literal specifies a period of time. Oracle CEP supports interval literal DAY TO SECOND. This literal contains a leading field and may contain a trailing field. The leading field defines the basic unit of date or time being measured. The trailing field defines the smallest increment of the basic unit being considered. Part ranges (such as only SECOND or MINUTE to SECOND) are not supported.

Interval literals must not exceed 64 bytes.

2.3.4.1 INTERVAL DAY TO SECOND

Specify DAY TO SECOND interval literals using the following syntax:

interval_value::=

Surrounding text describes interval_value.png.

where const_string is a TIMESTAMP value that conforms to the appropriate datetime format model (see Section 2.4.2, "Datetime Format Models").

Examples of the various forms of INTERVAL DAY TO SECOND literals follow:

Form of Interval LiteralInterpretation

INTERVAL '4 5:12:10.222' DAY TO SECOND(3)

4 days, 5 hours, 12 minutes, 10 seconds, and 222 thousandths of a second.


You can add or subtract one DAY TO SECOND interval literal from another DAY TO SECOND literal and compare one interval literal to another as Example 2-9 shows. In this example, stream tkdata2_SIn1 has schema (c1 integer, c2 interval).

Example 2-9 Comparing Intervals

<query id="tkdata2_q295"><![CDATA
select * from tkdata2_SIn1 where (c2 + INTERVAL "2 1:03:45.10" DAY TO SECOND) > INTERVAL "6 12:23:45.10" DAY TO SECOND
]]></query>

2.4 Format Models

A format model is a character literal that describes the format of datetime or numeric data stored in a character string. When you convert a character string into a date or number, a format model determines how Oracle CEP interprets the string. The following format models are relevant to Oracle CQL queries:

2.4.1 Number Format Models

You can use number format models in the following functions:

  • In the to_bigint function to translate a value of int datatype to bigint datatype.

  • In the to_float function to translate a value of int or bigint datatype to float datatype

2.4.2 Datetime Format Models

Oracle CQL supports the format models that the java.text.SimpleDateFormat specifies.

Table 2-4 lists the java.text.SimpleDateFormat models that Oracle CQL uses to interpret TIMESTAMP literals. For more information, see Section 2.3.3, "Datetime Literals".

Table 2-4 Datetime Format Models

Format ModelExample

MM/dd/yyyy HH:mm:ss Z

11/21/2005 11:14:23 -0800

MM/dd/yyyy HH:mm:ss z

11/21/2005 11:14:23 PST

MM/dd/yyyy HH:mm:ss

11/21/2005 11:14:23

MM-dd-yyyy HH:mm:ss

11-21-2005 11:14:23

dd-MMM-yy

15-DEC-01

yyyy-MM-dd'T'HH:mm:ss

2005-01-01T08:12:12


You can use a datetime format model in the following functions:

  • to_timestamp: to translate the value of a char datatype to a TIMESTAMP datatype.

2.5 Nulls

If a column in a row has no value, then the column is said to be null, or to contain null. Nulls can appear in tuples of any datatype that are not restricted by primary key integrity constraints. Use a null when the actual value is not known or when a value would not be meaningful.

Oracle CEP treats a character value with a length of zero as null. However, do not use null to represent a numeric value of zero, because they are not equivalent.


Note:

Oracle CEP currently treats a character value with a length of zero as null. However, this may not continue to be true in future releases, and Oracle recommends that you do not treat empty strings the same as nulls.


Any arithmetic expression containing a null always evaluates to null. For example, null added to 10 is null. In fact, all operators (except concatenation) return null when given a null operand.

For more information, see:

2.5.1 Nulls in Oracle CQL Functions

All scalar functions (except nvl and concat) return null when given a null argument. You can use the nvl function to return a value when a null occurs. For example, the expression NVL(commission_pct,0) returns 0 if commission_pct is null or the value of commission_pct if it is not null.

Most aggregate functions ignore nulls. For example, consider a query that averages the five values 1000, null, null, null, and 2000. Such a query ignores the nulls and calculates the average to be (1000+2000)/2 = 1500.

2.5.2 Nulls with Comparison Conditions

To test for nulls, use only the null comparison conditions (see null_conditions::=). If you use any other condition with nulls and the result depends on the value of the null, then the result is UNKNOWN. Because null represents a lack of data, a null cannot be equal or unequal to any value or to another null. However, Oracle CEP considers two nulls to be equal when evaluating a decode expression. See decode::= for syntax and additional information.

2.5.3 Nulls in Conditions

A condition that evaluates to UNKNOWN acts almost like FALSE. For example, a SELECT statement with a condition in the WHERE clause that evaluates to UNKNOWN returns no tuples. However, a condition evaluating to UNKNOWN differs from FALSE in that further operations on an UNKNOWN condition evaluation will evaluate to UNKNOWN. Thus, NOT FALSE evaluates to TRUE, but NOT UNKNOWN evaluates to UNKNOWN.

Table 2-5 shows examples of various evaluations involving nulls in conditions. If the conditions evaluating to UNKNOWN were used in a WHERE clause of a SELECT statement, then no rows would be returned for that query.

Table 2-5 Conditions Containing Nulls

ConditionValue of AEvaluation

a IS NULL

10

FALSE

a IS NOT NULL

10

TRUE

a IS NULL

NULL

TRUE

a IS NOT NULL

NULL

FALSE

a = NULL

10

FALSE

a != NULL

10

FALSE

a = NULL

NULL

FALSE

a != NULL

NULL

FALSE

a = 10

NULL

FALSE

a != 10

NULL

FALSE


For more information, see Section 6.6, "Null Conditions".

2.6 Comments

Oracle CQL does not support comments.

2.7 Aliases

Oracle CQL allows you to define aliases (or synonyms) to simplify and improve the clarity of your queries.

This section describes:

2.7.1 Defining Aliases Using the AS Operator

Using the AS operator, you can specify an alias in Oracle CQL for queries, relations, streams, and any items in the SELECT list of a query.

This section describes:

For more information, see Chapter 18, "Oracle CQL Queries, Views, and Joins".

2.7.1.1 Aliases in the relation_variable Clause

You can use the relation_variable clause AS operator to define an alias to label the immediately preceding expression in the select list so that you can reference the result by that name. The alias effectively renames the select list item for the duration of the query. You can use an alias in the ORDER BY clause (see Section 18.2.9, "Sorting Query Results"), but not other clauses in the query.

Example 2-10 shows how to define alias badItem for a stream element its.itemId in a SELECT list and alias its for a MATCH_RECOGNIZE clause.

Example 2-10 Using the AS Operator in the SELECT Statement

<query id="detectPerish"><![CDATA[ 
  select its.itemId as badItem
  from tkrfid_ItemTempStream MATCH_RECOGNIZE (
      PARTITION BY itemId
      MEASURES A.itemId as itemId
      PATTERN (A B* C)
      DEFINE
          A  AS  (A.temp >= 25),
          B  AS  ((B.temp >= 25) and (to_timestamp(B.element_time) - to_timestamp(A.element_time) < INTERVAL "0 00:00:05.00" DAY TO SECOND)),
          C  AS  (to_timestamp(C.element_time) - to_timestamp(A.element_time) >= INTERVAL "0 00:00:05.00" DAY TO SECOND)
  ) as its
]]></query>

For more information, see Section 18.2.1.3, "From Clause".

2.7.1.2 Aliases in Window Operators

You can use the AS operator to define an alias to label the immediately preceding window operator so that you can reference the result by that name.

You may not use the AS operator within a window operator but you may use the AS operator outside of the window operator.

Example 2-11 shows how to define aliases bid and ask after partitioned range window operators.

Example 2-11 Using the AS Operator After a Window Operator

<query id="Rule1"><![CDATA[
SELECT
    bid.id as correlationId
    bid.cusip as cusip
    max(bid.b0) as bid0
    bid.srcid as bidSrcId,
    bid.bq0 as bid0Qty,
    min(ask.a0) as ask0,
    ask.srcid as askSrcId,
    ask.aq0 as ask0Qty
FROM
    stream1[PARTITION by bid.cusip rows 100 range 4 hours] as bid,
    stream2[PARTITION by ask.cusip rows 100 range 4 hours] as ask
GROUP BY
    bid.id, bid.cusip, bid.srcid,bid.bq0, ask.srcid, ask.aq0
]]></query> 

For more information, see Section 1.1.3, "Stream-to-Relation Operators (Windows)".

2.7.2 Defining Aliases Using the Aliases Element

Aliases are required to provide location transparency. Using the aliases element, you can define an alias and then use it in an Oracle CQL query or view. You configure the aliases element in the component configuration file of a processor as Figure 2-0 shows.

Example 2-12 aliases Element in a Processor Component Configuration File

<?xml version="1.0" encoding="UTF-8"?>
<n1:config xmlns:n1="http://www.bea.com/ns/wlevs/config/application">
  <processor>
    <name>processor1</name>
    <rules>
      <query id="q1">
       <![CDATA[
         select str(msg) from cqlInStream [rows 2];
       ]]>
     </query>
    </rules>
    <aliases>
        <type-alias>
            <source>str</source>
            <target>java.lang.String </target>
       </type-alias>
    </aliases>
  </processor>
</n1:config>

The scope of the aliases element is the queries and views defined in the rules element of the processor to which the aliases element belongs.

Note the following:

  • If the alias already exists then, Oracle CEP will throw an exception.

  • If a query or view definition references an alias, then the alias must already exist.

This section describes:

2.7.2.1 How to Define a Data Type Alias Using the Aliases Element

Using the aliases element child element type-alias, you can define an alias for a data type. You can create an alias for any built-in or data cartridge data type.

For more information, see Section 2.1, "Datatypes".

To define a type alias using the aliases element:

  1. Edit the component configuration file of a processor.

  2. Add an aliases element as Example 2-13 shows.

    Example 2-13 Adding an aliases Element to a Processor

    <?xml version="1.0" encoding="UTF-8"?>
    <n1:config xmlns:n1="http://www.bea.com/ns/wlevs/config/application">
      <processor>
        <name>processor1</name>
        <rules>
          <query id="q1">
           <![CDATA[
             select str(msg) from cqlInStream [rows 2];
           ]]>
         </query>
        </rules>
        <aliases>
        </aliases>
      </processor>
    </n1:config>
    
  3. Add a type-alias child element to the aliases element as Example 2-14 shows.

    Example 2-14 Adding a type-alias Element to a Processor

    <?xml version="1.0" encoding="UTF-8"?>
    <n1:config xmlns:n1="http://www.bea.com/ns/wlevs/config/application">
      <processor>
        <name>processor1</name>
        <rules>
          <query id="q1">
           <![CDATA[
             select str(msg) from cqlInStream [rows 2];
           ]]>
         </query>
        </rules>
        <aliases>
            <type-alias>
           </type-alias>
        </aliases>
      </processor>
    </n1:config>
    
  4. Add a source and target child element to the type-alias element as Example 2-15 shows, where:

    Example 2-15 Adding the source and target Elements

    <?xml version="1.0" encoding="UTF-8"?>
    <n1:config xmlns:n1="http://www.bea.com/ns/wlevs/config/application">
      <processor>
        <name>processor1</name>
        <rules>
          <query id="q1">
           <![CDATA[
             select str(msg) from cqlInStream [rows 2];
           ]]>
         </query>
        </rules>
        <aliases>
            <type-alias>
                <source>str</source>
                <target>java.lang.String</target>
           </type-alias>
        </aliases>
      </processor>
    </n1:config>
    
  5. Use the alias in the queries and views you define for this processor.

    You can use the alias in exactly the same way you would use the data type it refers to. As Example 2-16 shows, you can access methods and fields of the aliased type.

    Example 2-16 Accessing the Methods and Fields of an Aliased Type

    <?xml version="1.0" encoding="UTF-8"?>
    <n1:config xmlns:n1="http://www.bea.com/ns/wlevs/config/application">
      <processor>
        <name>processor1</name>
        <rules>
          <query id="q1">
           <![CDATA[
             select str(msg).length() from cqlInStream [rows 2];
           ]]>
         </query>
        </rules>
        <aliases>
            <type-alias>
                <source>str</source>
                <target>java.lang.String</target>
           </type-alias>
        </aliases>
      </processor>
    </n1:config>
    

2.8 Schema Object Names and Qualifiers

Some schema objects are made up of parts that you can or must name, such as the stream elements in a stream or view, integrity constraints, streams, views, and user-defined functions. This section provides:

For more information, see Section 1.2.1, "Lexical Conventions".

2.8.1 Schema Object Naming Rules

Every Oracle CEP object has a name. In a Oracle CQL statement, you represent the name of an object with an nonquoted identifier, meaning an identifier that is not surrounded by any punctuation.

You must use nonquoted identifiers to name an Oracle CEP object.

The following list of rules applies to identifiers:

  • Identifiers cannot be Oracle CEP reserved words.

    Depending on the Oracle product you plan to use to access an Oracle CEP object, names might be further restricted by other product-specific reserved words.

    The Oracle CQL language contains other words that have special meanings. These words are not reserved. However, Oracle uses them internally in specific ways. Therefore, if you use these words as names for objects and object parts, then your Oracle CQL statements may be more difficult to read and may lead to unpredictable results.

    For more information, see

  • Oracle recommends that you use ASCII characters in schema object names because ASCII characters provide optimal compatibility across different platforms and operating systems.

  • Identifiers must begin with an alphabetic character (a letter) from your database character set.

  • Identifiers can contain only alphanumeric characters from your Java locale's character set and the underscore (_). In particular, space, dot and slash are not permitted.

    For more information, see:

  • In general, you should choose names that are unique across an application for the following objects:

    • Streams

    • Queries

    • Views

    • User-defined functions

    Specifically, a query and view cannot have the same name.

  • Identifier names are case sensitive.

  • Stream elements in the same stream or view cannot have the same name. However, stream elements in different streams or views can have the same name.

  • Functions can have the same name, if their arguments are not of the same number and datatypes (that is, if they have distinct signatures). Creating multiple functions with the same name with different arguments is called overloading the function.

    If you register or create a user-defined function with the same name and signature as a built-in function, your function replaces that signature of the built-in function. Creating a function with the same name and signature as that of a built-in function is called overriding the function.

    Built-in functions are public where as user-defined functions belong to a particular schema.

    For more information, see: