WSO2 Complex Event Processor is succeeded by WSO2 Stream Processor. To view the latest documentation for WSO2 SP, see WSO2 Stream Processor Documentation.

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Excerpt
hiddentrue
1.FORMAT FOR FUNCTIONS

functionName

<returnType r1> functionName   ( < paramType> p1) (FOR ONE RETURN TYPE & ONE PARAMETER TYPE)
< returnType | returnType functionName(<paramType|paramType> p1, <paramType|paramType> p2) (FOR ONE RETURN TYPE & MANY PARAMETER TYPES)
[< returnType | returnType r1, < returnType | returnType >  r2 functionName(<paramType|paramType> p1) (FOR MANY RETURN TYPES & ONE PARAMETER TYPE)
  • Extension TypeFunction | Aggregate  Function | Stream Function | Stream Processor | Window
  • Description
  • Parameter p1
  • Return  Parameter :  r1
  • Example:

functionName

<returnType> functionName   ( < paramType> p1)(FOR ONE RETURN TYPE & ONE PARAMETER TYPE)

<returnType|returnType>  functionName(<paramType|paramType> p1, <paramType|paramType> p2)(FOR ONE RETURN TYPE & MANY PARAMETER TYPES)

[< returnType | returnType r1, < returnType | returnType >  r2 functionName(<paramType|paramType> p1)(FOR MANY RETURN TYPES & ONE PARAMETER TYPE)

  • Extension Type: Function | Aggregate  Function | Stream Function | Aggregate Stream Function | Window
  • Description
  • Parameter p1
  • Return  Parameter :  r1
  • Example

 

kf (Kalman Filter)

This extension provides Kalman filtering capabilities to Siddhi. This allows you to detect outliers of input data. Following are the functions of the Kalman Filter extension.

kalmanFilter

This function uses measurements observed over time containing noise and other inaccuracies, and produces estimated values for the current measurement.

Syntax<double, double> kalmanFilter(<double> measuredValue)Extension TypeFuctionExample1st round: kf:kalmanFilter(-74.178444) returns an estimated value of -74.178444.
  • 2nd round: kf:kalmanFilter(-74.177872) returns an estimated value of -74.178158000143.
  • 3rd round: kf:kalmanFilter(-74.175703) returns an estimated value of  
    -74.1773396670348.
    Syntax<double, double> kalmanFilter(<double> measuredValue, <double> measurementNoiseSD)
    Extension TypeFunction
    Example
    • 1st round: kf:kalmanFilter(-74.178444) returns an estimated value of -74.178444.
    • 2nd round: kf:kalmanFilter(-74.177872) returns an estimated value of  -74.17815800142999.
    • 3rd round: kf:kalmanFilter(-74.175703) returns an estimated value of -74.17733967034776.
    Syntax<double, double> kalmanFilter(<double> measuredValue,  <double> measuredChangingRate, <double> measurementNoiseSD, <long> timestamp)
    Extension TypeFunction
    Example
    • 1st round: kf:kalmanFilter(-74.178444) returns an estimated value of -74.1784439700006.
    • 2nd round: kf:kalmanFilter(-74.177872) returns an estimated value of -74.17657538193608.
    • 3rd round: kf:kalmanFilter(-74.175703) returns an estimated value of -74.17487924016262.

    map

    This extension provides the capability to send a map object inside Siddhi stream definitions and use it inside queries. The following are the functions of the map extension.

    create

    Syntax

    <Object> create()

    or

    <Object> create(<Object> key1, <Object> value1,<Object> key2, <Object> value2,...<Object> keyN, <Object> valueN)

    Extension TypeFunction
    DescriptionReturns the created map object.
    Examples
    • create() returns an empty map.
    • create(1 , ”one” ,  2 , ”two” , 3 , ”three”) returns a map with keys 1, 2, 3 and corresponding values "one", "two", "three".

    get

    Syntax<Object> get(<Map> map, <Object> key)
    Extension TypeFunction
    DescriptionReturns the value object from the map that is related to the given key.
    Exampleget(company,1) returns the value that is related to the key 1 from the map named company.

    isMap

    Syntax<bool> isMap(<Object> object)
    Extension TypeFunction
    DescriptionReturns true if the object is a map or false otherwise.
    ExampleisMap(students) returns true if the students object is a map. It returns false if the students object is not a map.

    put

    SyntaxObject> put(<Object> map, <Object> key,<Object> value)
    Extension TypeFunction
    DescriptionReturns the updated map after adding the given key-value pair.
    Exampleput(students , 1234 , ”sam”) returns the updated map named students after adding the object "sam" with key 1234.

    remove

    Syntax<Object> remove(<Object> map, <Object> key)
    Extension TypeFunction
    DescriptionReturns the updated map after removing the element with key.
    Exampleremove(students , 1234) returns the updated map students after removing the element with the key 1234.

    createFromJSON

    Syntax<Object> createFromJSON(<string> JSONstring)
    Extension TypeFunction
    DescriptionReturns the map created with the key values pairs given in the JSONstring.
    ExamplecreateFromJSON(“{‘symbol' : 'IBM' , 'price' : 200, 'volume' : 100}”) returns a map with the keys "symbol""price", "volume", and with the values "IBM"200 and 100 respectively.

    createFromXML

    Syntax<Object> createFromXML(<string> XMLstring)
    Extension TypeFunction
    DescriptionReturns the map created with the key values pairs given in the XMLstring.
    ExamplecreateFromXML(“<company> <symbol> wso2 </symbol> <price> <100> </price> <volume> 200 </volume> </company>”) returns a map with the keys "symbol""price""volume", and with the values WSO2100 and 200 respectively.

    toJSON

    Syntax<String> toJSON(<Object> map)
    Extension TypeFunction
    DescriptionConverts a map into a JSON object and returns the definition of that JSON object as a string.
    ExampleIf "company" is a map with key value pairs ("symbol" : wso2)("volume" : 100), and ("price",200), toJSON(company) returns the string “{“symbol” : “wso2” , “volume” : 100 , “price” : 200}”.

    toXML

    Syntax

    <String> toXML(<Object> map)

    or

    <String> toXML(<Object> map, <String> rootElementName)

    Extension TypeFunction
    DescriptionReturns the map as an XML string.
    Example

    If "company" is a map with key value pairs (“symbol” : wso2)(“volume” : 100), and (“price” : 200),

    toXML(company) returns the string “<symbol>wso2</symbol><volume><100></volume><price>200</price>".

    toXML(company, "abcCompany") returns the string “<abcCompany><symbol>wso2</symbol><volume><100></volume><price>200</price></abcCompany>".

    reorder

    Reorder extension is implemented using the K-Slack algorithm. The K-Slack Siddhi extension is used for reordering events from an unordered event stream. The following is an example of a query with the reorder extension.

    Code Block
    languagesql
    linenumberstrue
    @info(name = 'query1') 
    from inputStream#reorder:kslack(eventTimestamp) 
    select eventTimestamp, price, volume 
    insert into outputStream;

    There are several important variations of the K-slack API of which the details are described below.

    kslack

    Syntax

    <bool> kslack(<long> timestamp)

    Extension TypeStreamProcessor
    DescriptionThis is the most basic version. The events are sorted by the timestamp parameter.
    Syntax

    <bool> kslack(<long> timestamp, <long> timeOut )

    Extension TypeStreamProcessor
    DescriptionThe second argument shown in the above syntax corresponds to a fixed time-out value set at the beginning of the process. Once the time-out value expires, the extension drains all the events that are buffered within the reorder extension to outside. The time out has been implemented internally using a timer. The events buffered within the extension are released each time the timer ticks.
    Syntax
    <bool> kslack(<long> timestamp, <long> timeOut, <long> maxValue )
    Extension TypeStreamProcessor
    DescriptionThe third argument in the above syntax is the maximum value for K. This is the amount to which the K value of the K-Slack algorithm will be increased.
    Example
    • kslack(timestamp, -1l, 1000000)
      In the above example, the algorithm execution starts when K=0 and it gets increased up to 1000000. The value of the K-slack does not increase from that point onwards. Hence, this leads to lower latency compared to the version shown in the first (i.e., single parameter) example of this list. Note that the second argument is set to -1l which effectively disables the timer based draining of the internal buffer.
    • kslack(timestamp, 1000l, 1000000)
      The above is another variation of the third category. Here, a time-out value is specified for the second argument (i.e. 1000 ms). In this case, the K-slack algorithm buffers events until the 1000ms time period expires. The maximum K value is 1000000. The K-value cannot exceed the specified amount.

    Syntax

    <bool> kslack(<long> timestamp, <long> timeOut, <bool> expireFlag )

    Extension TypeStreamProcessor
    DescriptionThe fourth argument in the above syntax is a flag that indicates whether the out-of order events that appear after the expiration of the K-slack window should be discarded or not.
    Examplekslack(timestamp, -1l, -1l, true)

     

    ...