com.atlassian.confluence.content.render.xhtml.migration.exceptions.UnknownMacroMigrationException: The macro 'next_previous_links' is unknown.

Siddhi Extensions

Following are the Siddhi extensions you can use in processing events using WSO2 DAS.

math

Math extension provides basic mathematical functions such as calculating absolute value, sin, cos, tan, base conversion, parsing, etc. Following are the functions of the Math extension. 

abs

Syntax<double> abs(<float|double> p1)
Extension TypeFunction
DescriptionReturns the absolute value of  p1 . This function wraps the java.lang.Math.abs() function.
Examples

Both the following queries return 3 since the absolute value of both 3 and -3 is 3.

  • abs(3)
  • abs(-3)

acos  

Syntax<double> acos(<float|double> p1)
Extension TypeFunction
DescriptionIf -1 <= p1 <= 1, this function returns the arc-cosine (inverse cosine) of p1. If not, it returns NULL. The return value is in radian scale. This function wraps the java.lang.Math.acos() function.
Exampleacos(0.5) returns 1.0471975511965979.

asin

Syntax<double> asin (<float|double>  p1)
Extension TypeFunction
DescriptionIf -1 <= p1 <= 1, this function returns the arc-sin (inverse sine) of  p1 . If not, it returns NULL. The return value is in radian scale. This function wraps the java.lang.Math.asin() function.
Exampleasin(0.5) returns 0.5235987755982989.

atan 

Syntax<double> atan(<int|long|float|double> p1)
Extension TypeFunction
DescriptionReturns the arc-tangent (inverse tangent) of p1. The return value is in radian scale. This function wraps the java.lang.Math.atan() function.
Examplesatan(6d) returns 1.4056476493802699.
Syntax<double> atan (<int|long|float|double> p1, <int|long|float|double> p2)
Extension TypeFunction
DescriptionReturns the arc-tangent (inverse tangent) of   p1  and  p2  coordinates. The return value is in radian scale. This function wraps the java.lang.Math.atan2() function.
Examplesatan(12d, 5d) returns 1.1760052070951352.

bin

Syntax<string>  bin(<int|long> p1)
Extension TypeFunction
DescriptionReturns a string representation of the integer/long  p1 argument as an unsigned integer in base 2. This function wraps the java.lang.Integer.toBinaryString and java.lang.Long.toBinaryString methods.
Examples bin(9) returns "1001".

ceil

Syntax<double>  ceil(<float|double> p1)
Extension TypeFunction
DescriptionReturns the smallest (closest to negative infinity) double value that is greater than or equal to the  p1 argument, and is equal to a mathematical integer. This function wraps the java.lang.Math.ceil() method.
Exampleceil(423.187d) returns 424.0.

conv

Syntax<string>  conv(<string> a, <int> fromBase, <int> toBase)
Extension TypeFunction
DescriptionConverts a from the fromBase base to the toBase base.
Exampleconv("7f", 16, 10) returns "127".

copySign

Syntax<double>  copySign(<int|long|float|double> magnitude, <int|long|float|double> sign)
Extension TypeFunction
DescriptionReturns the magnitude of  magnitude  with the sign of  sign  . This function wraps the java.lang.Math.copySign() function.
ExamplecopySign(5.6d, -3.0d) returns -5.6.

cos

Syntax<double>  cos(<int|long|float|double> p1)
Extension TypeFunction
DescriptionReturns the cosine of  p1  ( p1  is in radians). This function wraps the java.lang.Math.cos() function.
Examplecos(6d) returns 0.9601702866503661.

cosh

Syntax<double>  cosh(<int|long|float|double> p1)
Extension TypeFunction
DescriptionReturns the hyperbolic cosine of  p1  ( p1  is in radians). This function wraps the java.lang.Math.cosh() function.
Examplecosh (6d) returns 201.7156361224559.

cbrt

Syntax<double>  cbrt(<int|long|float|double> p1)
Extension TypeFunction
DescriptionReturns the cube-root of  p1  ( p1  is in radians). This function wraps the java.lang.Math.cbrt() function.
Examplecbrt(17d) returns 2.5712815906582356.

e 

Syntax<double>  e()
Extension TypeFunction
DescriptionReturns the java.lang.Math.E constant, which is the closest double value to e (which is the base of the natural logarithms).
Examplee() returns 2.7182818284590452354.

exp

Syntax<double>  exp(<int|long|float|double> p1)
Extension TypeFunction
DescriptionReturns Euler's number e raised to the power of  p1 . This function wraps the java.lang.Math.exp() function.
Exampleexp(10.23) returns 27722.51006805505.

floor

Syntax<double>  floor(<int|long|float|double> p1)
Extension TypeFunction
DescriptionThis function wraps the java.lang.Math.floor() function that returns the largest (closest to positive infinity) value that is less that or equal to p1 , and is equal to a mathematical integer.
Examplefloor(10.23) returns 10.0.

getExponent

Syntax<double>  getExponent(<int|long|float|double>  p1)
Extension TypeFunction
DescriptionReturns the unbiased exponent used in the representation of  p1 . This function wraps the java.lang.Math.getExponent() function.
ExamplegetExponent(60984.1) returns 15.

hex

Syntax<string>  hex(<int|long|float|double> p1)
Extension TypeFunction
DescriptionThis function wraps the java.lang.Double.toHexString() function that returns a hexadecimal string representation of  p1 .
Examplehex(200) returns "c8".

isInfinite

Syntax<boolean>  isInfinite(<float|double>  p1)
Extension TypeFunction
DescriptionThis function wraps the java.lang.Float.isInfinite() and java.lang.Double.isInfinite() functions that return true if  p1  is infinitely large in magnitude, or return false otherwise.
ExampleisInfinite(java.lang.Double.POSITIVE_INFINITY) returns true.

isNan  

Syntax< boolean>  isNan(<float|double>  p1)
Extension TypeFunction
DescriptionThis function wraps the java.lang.Float.isNaN() and java.lang.Double.isNaN() functions that return true if  p1  is a NaN (Not-a-Number) value, or return false otherwise.
ExampleisNan(java.lang.Math.log(-12d)) returns true.

ln

Syntax<double> ln (< int|long|float|double >  p1)
Extension TypeFunction
DescriptionReturns the natural logarithm (base e) of  p1 .
Exampleln(11.453) returns 2.438251704415579.

log2

Syntax<double> log2 (< int|long|float|double >  p1)
Extension TypeFunction
DescriptionReturns the base 2 logarithm of  p1 .
Examplelog2(91d) returns 6.507794640198696.

log10

Syntax<double> log10 ( < int|long|float|double >  p1 )
Extension TypeFunction
DescriptionReturns the base 10 logarithm of p1.
Examplelog10(19.234) returns 1.2840696117100832.

log

Syntax<double> log (< int|long|float|double >  number, < int|long|float|double >  base )
Extension TypeFunction
DescriptionReturns the logarithm (base=base) of  number .
Examplelog(34, 2f) returns 5.08746284125034.

max

Syntax<double> max (< int|long|float|double >  p1,  <int|long|float|double>   p2 )
Extension TypeFunction
DescriptionReturns the greater value out of p1 and p2 .
Examplemax(123.67d, 91) returns 123.67.

min

Syntax<double> min (< int|long|float|double >  p1,  <int|long|float|double>   p2 )
Extension TypeFunction
DescriptionReturns the smaller value out of p1 and p2 .
Examplemin(123.67d, 91) returns 91.

oct

Syntax<string> oct (<int|long>  p1)
Extension TypeFunction
DescriptionConverts p1 to octal.
Exampleoct(99l) returns "143".

parseDouble

Syntax<double> parseDouble (<string>  str)
Extension TypeFunction
DescriptionReturns str as a double.
ExampleparseDouble("123") returns 123.0.

parseFloat

Syntax<float> parseFloat (<string>  str)
Extension TypeFunction
DescriptionReturns str as a float.
ExampleparseFloat("123") returns 123.0.

parseInt

Syntax<int> parseInt (<string>  str)
Extension TypeFunction
DescriptionReturns str as an int.
ExampleparseInt("123") returns 123.

parseLong

Syntax<long> parseLong (<string>  str)
Extension TypeFunction
DescriptionReturns str as a long.
ExampleparseLong("123") returns 123.

pi

Syntax<double> pi ( )
Extension TypeFunction
DescriptionReturns the java.lang.Math.PI constant, which is the closest value to pi (i.e. the ratio of the circumference of a circle to its diameter). 
Examplepi() always returns 3.141592653589793.

power 

Syntax<double> power ( < int|long|float|double>  value,  <int|long|float|double>   toPower )
Extension TypeFunction
DescriptionReturns value raised to the power of toPower.
Examplepower(5.6d, 3.0d) returns 175.61599999999996.

rand

Syntax<double> rand ( )
Extension TypeFunction
Description A sequence of calls to rand() generates a stream of pseudo-random numbers. This function uses the java.util.Random class internally.
ExampleTwo sequential calls to rand() may return 0.8263929447650588 and 0.24425883860361197 respectively.
Syntax<double> rand (< int|long >  seed)
Extension TypeFunction
DescriptionA sequence of calls to rand(seed) generates a stream of pseudo-random numbers. This function uses the java.util.Random class internally. 
ExampleTwo sequential calls to rand(12) may return 0.7298928061101974 and 0.2750691655200749, respectively.

round

Syntax

<int> round (<float> value )

Extension TypeFuncion
DescriptionReturns the closest integer value to the argument.
Exampleround(3.35) returns 3.
Syntax<long> round (<double> value )
Extension TypeFunction
DescriptionReturns the closest long value to the argument.
Exampleround(3252.353) returns 3252.

signum

Syntax<int> signum (< int|long|float|double >  p1)
Extension TypeFunction
Description
  • If a is a positive, this returns the sign of p1 as 1.0.
  • If a is a negative, this returns the sign of p1 as -1.0.
  • If a is neither a positive or a negative, this returns the sign of p1 as 0.0.

This function wraps the java.lang.Math.signum() function.

Examplesignum(-6.32d) returns -1.

sin

Syntax<double> sin (< int|long|float|double >  p1)
Extension TypeFunction
DescriptionReturns the sine of  p1  ( p1  is in radians). This function wraps the java.lang.Math.sin() function.
Examplesin(6d) returns -0.27941549819892586.

sinh 

Syntax<double> sinh (< int|long|float|double >  p1)
Extension TypeFunction
DescriptionReturns the hyperbolic sine of  p1  ( p1  is in radians). This function wraps the java.lang.Math.sinh() function. 
Examplesinh(6d) returns 201.71315737027922.

sqrt 

Syntax<double> sqrt (< int|long|float|double >  p1)
Extension TypeFunction
DescriptionReturns the square-root of  p1 . This function wraps the java.lang.Math.sqrt() function. 
Examplesqrt(4d) returns 2.

tan   

Syntax<double> tan (< int|long|float|double >  p1)
Extension TypeFunction
DescriptionReturns the tan of  p1  ( p1  is in radians). This function wraps the java.lang.Math.tan() function. 
Exampletan(6d) returns -0.29100619138474915.

tanh

Syntax<double> tanh (<int|long|float|double>  p1)
Extension TypeFunction
DescriptionReturns the hyperbolic tangent of  p1 ( p1  is in radians). This function wraps the java.lang.Math.tanh() function. 
Exampletanh(6d) returns 0.9999877116507956.

toDegrees

Syntax<double> toDegrees (< int|long|float|double >  p1)
Extension TypeFunction
DescriptionConverts  p1  from radians to degrees. This function wraps the java.lang.Math.toDegrees() function.
ExampletoDegrees(6d) returns 343.77467707849394.

toRadians

Syntax<double> toRadians (< int|long|float|double >  p1)
Extension TypeFunction
DescriptionConverts  p1  from degrees to radians. This function wraps the java.lang.Math.toRadians() function.
ExampletoRadians(6d) returns 0.10471975511965977.

str

This extension provides basic string handling capabilities such as con-cat, length, convert to lowercase, replace all, etc. Following are the functions of the String extension.

charAt

Syntax<string> charAt(<string> str, <int>  index)
Extension TypeFunction
DescriptionReturns the char value as a string value at the specified index.
ExamplecharAt("WSO2", 1) returns 'S'.

coalesce 

Syntax< int|long|float|double|string|boolean > coalesce (< int|long|float|double|string|boolean >  arg1, < int|long|float|double|string|boolean >   arg2 ,.., < int|long|float|double|string|boolean >   argN )
Extension TypeFunction
DescriptionReturns the value of the first of its input parameters that is not null.
ParametersThis functions accepts any number of parameters. The parameters can be of different types.
Return TypeThis is the same as the type of the first input parameter that is not null.
Examples
  • coalesce("123", null, "789") returns "123".
  • coalesce(null, "BBB", "CCC") returns "BBB".
  • coalesce(null, null, null) returns null 

concat

Syntax<string> concat   ( <int|long|float|double|string|boolean > arg1, < int|long|float|double|string|boolean >   arg2 ,.., < int|long|float|double|string|boolean >   argN )
Extension TypeFunction
DescriptionReturns a string that is the result of concatenating the given arguments:  arg1 arg2 , ..,  argN .
Examples
  • concat("D533", "8JU^", "XYZ") returns "D5338JU^XYZ".
  • concat("AAA", null, "CCC") returns "AAACCC".

hex

Syntax<string> hex   ( < string> str)
Extension TypeFunction
DescriptionReturns a hexadecimal string representation of  str .
Examplehex("MySQL") returns "4d7953514c".

length

Syntax<int> length   ( < string> str)
Extension TypeFunction
DescriptionReturns the length of the string:  str .
Exampleslength("Hello World") returns 11.

lower

Syntax<string> lower   ( < string> str)
Extension TypeFunction
DescriptionConverts the capital letters in the str input string to the equivalent simple letters.
Examplelower("WSO2 cep ") returns "wso2 cep ".

regexp 

Syntax<boolean> regexp   ( < string> str, <string> regex )
Extension TypeFunction
DescriptionReturns true if the given string (i.e. str ) matches the given regular expression (i.e. regex  ). Returns false if the string does not match the regular expression.
Exampleregexp("WSO2 abcdh", "WSO(.*h)") returns true.

repeat 

Syntax<string> repeat   ( < string> str, <int>  times)
Extension TypeFunction
DescriptionRepeats the specified string (i.e. string ) for the specified number of times (i.e. times ).
Examplerepeat("StRing 1", 3) returns "StRing 1StRing 1StRing 1".

replaceAll

Syntax<string> replaceAll   ( < string> str, <string>  regex ,  <string>  replacement)
Extension TypeFunction
DescriptionReplaces each substring of the given string (i.e. str ) that matches the given regular expression (i.e. regex ) with the string specified as the replacement (i.e. replacement ).
ExamplereplaceAll("hello hi hello",  'hello', 'test') returns "test hi test".

replaceFirst

Syntax<string> replaceFirst (< string>  str ,  <string>  regex ,  <string>  replacement )
Extension TypeFunction
DescriptionReplaces the first substring that matches the given regular expression (i.e. regex ) with the string specified as the replacement (i.e. replacement )
ExamplereplaceFirst("hello WSO2 A hello",  'WSO2(.*)A', 'XXXX') returns "hello XXXX hello".

reverse

Syntax<string> reverse   ( < string> str)
Extension TypeFunction
DescriptionReturns the reverse ordered string of  str .
Examplereverse("Hello World") returns "dlroW olleH".

strcmp   

Syntax<int> strcmp ( < string> str, <string>  compareTo)
Extension TypeFunction
DescriptionCompares  str  with  compareTo  strings lexicographically.
Examples
  • strcmp("Hello", 'Hello') returns 0.
  • strcmp("AbCDefghiJ KLMN", 'Hello') returns -7.

substr

Syntax<string> substr   ( < string> sourceText, <int> beginIndex )
Extension TypeFunction
DescriptionReturns a ne string that is a substring of sourceText.
Examplesubstr("AbCDefghiJ KLMN", 4) returns "efghiJ KLMN".
Syntax<string> substr   ( < string> sourceText, <int> beginIndex,  <int> length )
Extension TypeFunction
Description Returns a new string that is a substring of  sourceText.
Examplesubstr("AbCDefghiJ KLMN",  2, 4) returns "CDef".
Syntax<string> substr   ( < string> sourceText, <string> regex)
Extension TypeFunction
Description Returns a new string that is a substring of  sourceText.
Examplessubstr("WSO2D efghiJ KLMN", '^WSO2(.*)') returns "WSO2D efghiJ KLMN" 
Syntax<string> substr   ( < string> sourceText, <string> regex,  <int> groupNumber )
Extension TypeFunction
DescriptionReturns a new string that is a substring of  sourceText.
Examplesubstr("WSO2 cep WSO2 XX E hi hA WSO2 heAllo",  'WSO2(.*)A(.*)',  2) returns " ello".

trim

Syntax<string> trim   ( < string> str)
Extension TypeFunction
DescriptionReturns a copy of  str , with the leading and/or trailing white-spaces omitted.
Exampletrim("  AbCDefghiJ KLMN  ") returns "AbCDefghiJ KLMN".

unhex

Syntax<string> unhex   ( < string> str)
Extension TypeFunction
DescriptionThis is the equivalent of the unhex function in mysql 5.0. unhex(str) interprets each pair of characters in str as a hexadecimal number. Also see hex () string extension.
Exampleunhex("4d7953514c") returns "MySQL".

upper

Syntax<string> upper ( <string> str)
Extension TypeFunction
DescriptionConverts the simple letters in the given input string (i.e. str ) to the equivalent capital letters.
Exampleupper("Hello World") returns "HELLO WORLD".

contains

Syntax<bool> contains ( < string> inputSequence, <string>  searchingSequence )
Extension TypeFunction
DescriptionThis method returns true if inputSequence contains the specified sequence of char values in the searchingSequence .
Examplecontains("21 products are produced by WSO2 currently", "WSO2") returns true.

geo

This extension provides geo data related functionality such as checking whether a given geo coordinate is within a predefined geo-fence, etc. Following are the functions of the Geo extension.

intersects

Syntax<bool> intersects (<string> geoJSONGeometry , <string> geoJSONGeometryFence )
Extension TypeFunction
DescriptionReturns true if the geoJSONGeometry incoming event intersects the given string (i.e. geoJSONGeometryFence). Returns false otherwise.
Exampleintersects( {'type':'Polygon','coordinates':[[[0.5, 0.5],[0.5, 1.5],[1.5, 1.5],[1.5, 0.5],[0.5, 0.5]]]} , {'type':'Polygon','coordinates':[[[0, 0],[0, 1],[1, 1],[1, 0],[0, 0]]]} ), returns true because geoJSONGeometry intersects geoJSONGeometryFence.
Syntax<bool> intersects (<double> longitude , <double> latitude , <string> geoJSONGeometryFence )
Extension TypeFunction
DescriptionReturns true if the location specified in terms of longitude and latitude intersects the given geoJSONGeometryFence . Returns false otherwise.
Exampleintersects(0.5. 0.5 , {'type':'Polygon','coordinates':[[[0, 0],[0, 1],[1, 1],[1, 0],[0, 0]]]}), returns true because the location specified in terms of longitude and latitude intersects geoJSONGeometryFence.

within

Syntax<bool> within (<double> longitude , <double> latitude, <string> geoJSONGeometryFence )
Extension TypeFunction
DescriptionReturns true if the location specified in terms of longitude and latitude is within the geoJSONGeometryFence.
Examples
  • within(0.5, 0.5, {'type':'Polygon','coordinates':[[[0,0],[0,2],[1,2],[1,0],[0,0]]]} ) returns true.
  • within(2, 2, {'type':'Polygon','coordinates':[[[0,0],[0,2],[1,2],[1,0],[0,0]]]} ) returns false.
Syntax<bool> within (<string> geoJSONGeometry , <string> geoJSONGeometryFence  )
Extension TypeFunction
DescriptionReturns true if the geoJSONGeometry is within the geoJSONGeometryFence. Returns false otherwise.
Example
  • within( {'type': 'Circle', 'radius': 110575, 'coordinates':[1.5, 1.5]} , {'type':'Polygon','coordinates':[[[0,0],[0,4],[3,4],[3,0],[0,0]]]} ) returns true.
  • within( {'type': 'Circle', 'radius': 110575, 'coordinates':[0.5, 1.5]} , {'type':'Polygon','coordinates':[[[0,0],[0,4],[3,4],[3,0],[0,0]]]} ) returns false.

withindistance

Syntax<bool> withindistance (<double> longitude , <double> latitude, <string> geoJSONGeometryFence )
Extension TypeFunction
DescriptionReturns true if the location specified in terms of longitude and latitude is within distance of the geoJSONGeometryFence. Returns false otherwise.
Examplewithindistance( 0.5 , 0.5, {'type':'Polygon','coordinates':[[[0, 0],[0, 1],[1, 1],[1, 0],[0, 0]]]}, 110574.61087757687) returns true because the location specified in terms of longitude and latitude is within the distance of the geoJSONGeometryFence.
Syntax<bool> withindistance (<string> geoJSONGeometry , <string> geoJSONGeometryFence , <double> distance )
Extension TypeFunction
DescriptionReturns true if the area given by geoJSONGeometry is within distance of the geoJSONGeometryFence.
Examplewithindistance( {'type':'Polygon','coordinates':[[[0.5, 0.5],[0.5, 1.5],[1.5, 1.5],[1.5, 0.5],[0.5, 0.5]]]} , {'type':'Polygon','coordinates':[[[0, 0],[0, 1],[1, 1],[1, 0],[0, 0]]]}, 110574.61087757687) returns true because geoJSONGeometry is within the distance of geoJSONGeometryFence.

crosses

Syntax<bool> crosses (<string> id , <double> longitude, <double> latitude , <string> geoJSONGeometryFence )
Extension TypeFunction
DescriptionReturns true when the  the specified object of which the location is specified  in terms of  longitude   and  latitude crosses the geographic location specified in geoJSONGeometryFence . Returns false when the object crosses out of the location specified in geoJSONGeometryFence .
Example
  • crosses(km-4354, -0.5, 0.5, {'type':'Polygon','coordinates':[[[0, 0],[2, 0],[2, 1],[0, 1],[0, 0]]]} ) returns true.
  • km-4354, 1.5, 0.5, {'type':'Polygon','coordinates':[[[0, 0],[2, 0],[2, 1],[0, 1],[0, 0]]]} ) returns true.
Syntax<bool> crosses (<string> id , <string> geoJSONGeometry , <string> geoJSONGeometryFence )
Extension TypeStreamProcessor
DescriptionReturns true when the object (i.e. geoJSONGeometry ) crosses the specified geographic location (i.e. geoJSONGeometryFence ). Returns false when the object crosses out of geoJSONGeometryFence . 

stationary

Syntax<bool> stationary (<string> id , <double> longitude, <double> latitude , <string> geoJSONGeometryFence , <double> radius )
Extension TypeStreamProcessor
DescriptionReturns true when the object (defined in terms of   longitude   and  latitude ) becomes stationary within the specified radius . Returns false when the object moves out of the specified radius.
Example
  • stationary(km-4354,0,0, 110574.61087757687) returns true.
  • stationary(km-4354,1,1, 110574.61087757687) returns true .
  • stationary(km-4354,1,1.5, 110574.61087757687) returns true.
Syntax<bool> stationary (<string> id , <string> geoJSONGeometry , <string> geoJSONGeometryFence , <double>  radius )
Extension TypeStreamProcessor
DescriptionReturns true when the object (i.e. geoJSONGeometry ) becomes stationary within the specified radius . Returns false when the objects moves out of the specified radius.

proximity

Syntax<bool,string> proximity (<string> id , <double> longitude, <double> latitude , <string> geoJSONGeometryFence , <double> radius )
Extension TypeStreamProcessor
DescriptionReturns true when two objects (specified in terms of longitude and latitude) are within the specified radius to another object. Returns false when the specified object moves out of the specified radius . The proximityWith optional attribute indicates the ID of the object that the object specified is in close proximity with. proximityID is a unique ID for the two objects in close proximity.
Example

The following return true with ID3.

  • proximity(1, 0, 0, 110574.61087757687)
  • proximity(2, 1, 1, 110574.61087757687)
  • proximity(3, 2, 2, 110574.61087757687)
  • proximity(1, 1.5, 1.5, 110574.61087757687)


Syntax<bool> proximity (<string> id , <string> geoJSONGeometry , <string> geoJSONGeometryFence , <double>  radius )
Extension TypeStreamProcessor
DescriptionReturns true when an object (i.e. geoJSONGeometry ) is within the specified radius from another object. Returns false when one or both objects move away from each other and are no longer within the specified radiu s of each other. The proximityWith optional attribute indicates the ID of the object that the object specified is in close proximity with. proximityID is a unique ID for the two objects in close proximity.

geocode

Syntax<double, double, string> geocode (<string> location  )
Extension TypeStreamProcessor
DescriptionTransforms a location to its geo-coordinates ( longitude and latitude ) and formatted address.
Examplegeocode(duplication rd) returns the following data with adherring latitude, longitude, and formattedAddress attribute names respectively.
6.8995244d, 79.8556202d, "R A De Mel Mawatha, Colombo, Sri Lanka"

r

This extension allows you to execute R scripts within Siddhi query. Following are the functions of the R extension.

eval

Syntax[<int|long|float|double|string|boolean>  output1 ,  <int|long|float|double|string|boolean>   output2, ... ] eval   ( <string > script,  <string >  outputAttributes, <int|long|float|double|string|boolean >  input1 , <int|long|float|double|string|boolean> input2 , ... )
Extension TypeStreamProcessor
DescriptionThis runs the R script for each event and produces  aggregated outputs based on the provided input variable parameters and expected output attributes.
Parameters

script : R script as a string produces aggregated outputs based on the provided input variable parameters and expected output attributes.
outputAttributes  : A set of output attributes separated by commas as string. Each attribute is denoted as <name><space><type>. e.g., 'output1 string, output2 long'

Return ParametersOutput parameters are generated based on the outputAttributes provided.
Example

eval('totalItems <- sum(items); totalTemp <- sum(temp);', 'totalItems int, totalTemp double', items, temp), where the data type of items is int and that of temp is double returns [ totalItems, totalTemp ], where the data type of totalItems is int and that of totalTemp is double.

evalSource

Syntax[<int|long|float|double|string|boolean>  output1 ,  <int|long|float|double|string|boolean>   output2, ... ] eval   ( <string > filePath,  <string >  outputAttributes,<int|long|float|double|string|boolean>  input1 , <int|long|float|double|string|boolean> input2 , ... )
Extension TypeStream Processor
DescriptionThis runs the R script loaded from a file to each event and produces aggregated outputs based on the provided input variable parameters and expected output attributes.
Parameters

filePath : The file path of the R script where this script uses the input variable parameters and produces the expected output attributes.

outputAttributes  : A set of output attributes separated by commas as string. Each attribute is denoted as <name><space><type> . e.g., 'output1 string, output2 long'

ReturnOutput parameters are generated based on the outputAttributes provided.
Exampleeval('/home/user/test/script1.R', 'totalItems int, totalTemp double', items, temp), where the data type of items is int and that of temp is double returns [ totalItems, totalTemp ] where the data type of totalTemp is int and that of totalTemp is double.

 

regex

This extension provides basic RegEx execution capabilities to Siddhi. Following are the functions of the RegEx extension.

find

Syntax<bool> find (<string> regex , <string> inputSequence )
Extension TypeFunction
DescriptionThis method attempts to find the next sub-sequence of the inputSequence that matches the regex pattern. It returns true if such a sub sequence exists, or returns false otherwise.
Examples
  • find("\d\d(.*)WSO2", "21 products are produced by WSO2 currently") returns true.
  • find("\d\d(.*)WSO2", "21 products are produced currently") returns false.


Syntax<bool> find (<string> regex , <string> inputSequence, <int> startingIndex )
Extension TypeFunction
DescriptionThis method attempts to find the next sub-sequence of the inputSequence that matches the regex pattern starting from given index (i.e. startingIndex ). It returns true if such a sub sequence exists, or returns false otherwise.
Examples
  • find("\d\d(.*)WSO2", "21 products are produced within 10 years by WSO2 currently by WSO2 employees",  30) returns true.
  • find("\d\d(.*)WSO2", "21 products are produced within 10 years by WSO2 currently by WSO2 employees", 35) returns false.

group

Syntax<string> group (<string> regex , <string> inputSequence , <int>  groupId )
Extension TypeFunction
DescriptionReturns the input sub-sequence captured by the given group during the previous match operation. Returns null if no sub-sequence was found during the previous match operation. For more information about the match operation, see matches.
Example group("(\d\d)(.*)(WSO2.*)", "21 products are produced within 10 years by WSO2 currently by WSO2 employees", 3) returns "WSO2 employees".

lookingAt

Syntax<string> lookingAt (<string> regex , <string> inputSequence )
Extension TypeFunction
DescriptionThis method attempts to match the inputSequence against the regex pattern starting at the beginning.
Examples
  • lookingAt("\d\d(.*)WSO2", "21 products are produced by WSO2 currently in Sri Lanka") returns true.
  • lookingAt("WSO2(.*)middleware(.*)", "sample test string and WSO2 is situated in trace and its a middleware company") returns false.

matches

Syntax<string> matches (<string> regex , <string> inputSequence )
Extension TypeFunction
DescriptionThis method attempts to match the entire inputSequence against the regex pattern.
Examples
  • matches("WSO2(.*)middleware(.*)", "WSO2 is situated in trace and its a middleware company") returns true.
  • matches("WSO2(.*)middleware", "WSO2 is situated in trace and its a middleware company") returns false.

time

This extension provides time related functionality to Siddhi such as getting current time, current date, manipulating/formatting dates, etc. Following are the functions of the time extension.

currentDate

Syntax<string> currentDate ( )
Extension TypeFunction
DescriptionReturns the current system date in the yyyy-MM-dd format.
ExamplecurrentDate() returns 2015-08-20.

currentTime

Syntax<string> currentTime ( )
Extension TypeFunction
DescriptionReturns the current system time in the HH:mm:ss format.
ExamplecurrentTime() returns 13:15:10.

currentTimestamp

Syntax<string> currentTimestamp ( )
Extension TypeFunction
DescriptionReturns the current system timestamp in the yyyy-MM-dd HH:mm:ss format.
ExamplecurrentTime() returns 2015-08-20 13:15:10.

dateAdd

The common parameters of this function are described below.

  • dateValue : A value of date. e.g., "2014-11-11 13:23:44.657", "2014-11-11", "13:23:44.657"
  • expr : The amount by which the selected part of the date format should be incremented. e.g., 2 ,5 ,10 etc.
  • unit : The part of the date format that needs to be manipulated. e.g., "MINUTE" , "HOUR" , "MONTH" , "YEAR" , "QUARTER" , * "WEEK" , "DAY" , "SECOND"
  • dateFormat : The date format of the date value provided. e.g., yyyy-MM-dd HH:mm:ss.SSS
  • timestampInMilliseconds : The date value in milliseconds (from the epoch). e.g., 1415712224000L
Syntax<string> dateAdd (<string> dateValue , <long> expr, <string> unit, <string> dateFormat )
Extension TypeFunction
DescriptionReturns the specified date and time with the selected unit of the specified dateValue incremented by the given amount (i.e. expr ).
ExampledateAdd("2014-11-11 13:23:44", 2, 'year',"yyyy-MM-dd HH:mm:ss") returns "2016-11-11 13:23:44".
Syntax<string> dateAdd (<string>  dateValue  , < long >  expr,  <string>  unit )
Extension TypeFunction
DescriptionReturns the specified date and time with the selected unit of the specified dateValue incremented by the given amount (i.e. expr ).
ExampledateAdd("2014-11-11 13:23:44", 2, 'year') returns "2016-11-11 13:23:44".
Syntax<string> dateAdd (<long>  timestampInMilliseconds, < long >   expr,  <string>  unit )
Extension TypeFunction
DescriptionReturns the specified time stamp with the selected unit of the specified timestampInMilliseconds incremented by the given amount (i.e. expr ).
ExampledateAdd(1415692424000L, 2, 'year') returns "2016-11-11 13:23:44".

dateSub

The common parameters of this function are described below.

  • dateValue : A value of date. e.g., "2014-11-11 13:23:44.657""2014-11-11""13:23:44.657"
  • expr : The amount by which the selected part of the date format should be reduced. e.g., 2 ,5 ,10 etc.
  • unit : The part of the date format that needs to be manipulated. e.g., "MINUTE" , "HOUR" , "MONTH" , "YEAR" , "QUARTER" , * "WEEK" , "DAY" , "SECOND"
  • dateFormat : The date format of the date value provided. e.g., yyyy-MM-dd HH:mm:ss.SSS
  • timestampInMilliseconds : The date value in milliseconds (from the epoch). e.g., 1415712224000L
Syntax<string> dateSub (<string> dateValue , <long> expr, <string> unit, <string> dateFormat )
Extension TypeFunction
DescriptionReturns the specified date and time with the selected unit of the specified dateValue reduced by the given amount (i.e. expr ).
ExampledateSub("2014-11-11 13:23:44", 2, 'year',"yyyy-MM-dd HH:mm:ss") returns "2012-11-11 13:23:44".
Syntax<string> dateSub (<string>  dateValue  , < long >  expr,  <string>  unit )
Extension TypeFunction
DescriptionReturns the specified date and time stamp with he selected unit of the specified dateValue reduced by the given amount (i.e. expr ).
ExampledateSub("2014-11-11 13:23:44", 2, 'year') returns "2012-11-11 13:23:44".
Syntax<string> dateSub (<long>  timestampInMilliseconds,  < long >   expr,  <string>  unit )
Extension TypeFunction
DescriptionReturns the specified time stamp with the selected unit of the specified timestampInMilliseconds   reduced by the given amount (i.e. expr ).
Example dateSub(1415692424000L, 2, 'year') returns 1352620424000.

dateDiff

The common parameters of this function are described below.

  • dateValue1 : A value of date. e.g., "2014-11-11 13:23:44.657", "2014-11-11" , "13:23:44.657"
  • dateValue2 : A value of date. e.g., "2014-11-11 13:23:44.657""2014-11-11" , "13:23:44.657"
  • dateFormat1 : The date format of dateValue1 . e.g., yyyy-MM-dd HH:mm:ss.SSS
  • dateFormat2 : The date format of  dateValue2 . e.g., yyyy-MM-dd HH:mm:ss.SSS
  • timestampInMilliseconds1 : A date value in milliseconds (from the epoch) e.g., 1415712224000L
  • timestampInMilliseconds2 :A date value in milliseconds (from the epoch) e.g., 1415712224000L
Syntax<int> dateDiff (<string> dateValue1 ,  < string >  dateValue2 ,  <string> dateFormat1, <string> dateFormat2 )
Extension TypeFunction
DescriptionReturns the number of days between the two dates specified (i.e. dateValue1 and dateValue2 ).
ExampledateDiff('2014-11-11 13:23:44', '2014-11-9 13:23:44', 'yyyy-MM-dd HH:mm:ss', 'yyyy-MM-dd HH:mm:ss') returns 2.
Syntax<int> dateDiff (<string> dateValue1 ,  < string >  dateValue2 )
Extension TypeFunction
DescriptionReturns the number of days between the two dates specified (i.e. dateValue1 and dateValue2 ).
ExampledateDiff('2014-11-11 13:23:44.000', '2014-11-9 13:23:44.000') returns 2.
Syntax<int> dateDiff (<string> timestampInMilliseconds1 ,  < string >  timestampInMilliseconds2 )
Extension TypeFunction
DescriptionReturns the number of days between the two date and time stamps specified (i.e. timestampInMilliseconds1 and timestampInMilliseconds2 ).
ExampledateDiff(1415692424000, 1415519624000) returns 2.

dateFormat

The common parameters of this function are described below.

  • dateValue : -A value of date. e.g., "2014-11-11 13:23:44.657", "2014-11-11" , "13:23:44.657" 
  • dateTargetFormat : The date format to which the specified date value needs to be converted. e.g., yyyy/MM/dd HH:mm:ss
  • dateSourceFormat : The date format of the date value provided. e.g., yyyy-MM-dd HH:mm:ss.SSS
  • timestampInMilliseconds : A date value in milliseconds (from the epoch) e.g., 1415712224000L
Syntax<string> dateFormat(<string>  dateValue,<string>  dateTargetFormat,<string>  dateSourceFormat)
Extension TypeFunction
DescriptionReturns a formatted date string.
ExampledateFormat('2014-11-11 13:23:55', 'ss', 'yyyy-MM-dd HH:mm:ss') returns 55.
Syntax<string> dateFormat(<string>  dateValue,<string>  dateTargetFormat)
Extension TypeFunction
DescriptionReturns a formatted date string.
ExampledateFormat('2014-11-11 13:23:55.657', 'ss') returns 55.
Syntax<string>  dateFormat (<long> timestampInMilliseconds ,<string>  dateTargetFormat)
Extension TypeFunction
DescriptionReturns a formatted date string.
ExampledateFormat(1415692424000, 'yyyy-MM-dd') returns 2014-11-11.  

extract

  • dateValue : A value of date. e.g., "2014-11-11 13:23:44.657", "2014-11-11" , "13:23:44.657" 
  • unit : The part of the date format that needs to be manipulated. e.g., "MINUTE" , "HOUR" , "MONTH" , "YEAR" , "QUARTER" , * "WEEK" , "DAY" , "SECOND"
  • dateFormat : The date format of the date value provided. e.g., yyyy-MM-dd HH:mm:ss.SSS
  • timestampInMilliseconds : A date value in milliseconds (from the epoch) e.g., 1415712224000L
Syntax<int>  extract (<string> unit ,<string>  dateValue, <string> dataFormat)
Extension TypeFunction
DescriptionReturns the specified unit extracted from the specified dateValue .
Exampleextract('year', '2014-3-11 02:23:44', 'yyyy-MM-dd hh:mm:ss') returns 2014.
Syntax<int>  extract (<string> unit ,<string>  dateValue)
Extension TypeFunction
DescriptionReturns the specified unit extracted from the specified dateValue .
Exampleextract('year', '2014-3-11 02:23:44.234') returns 2014.
Syntax<int>  extract (<long> timestampInMilliseconds ,<string>  unit)
Extension TypeFunction
DescriptionReturns the specified unit extracted from the specified timestampInMilliseconds .
Exampleextract(1394484824000, 'year') returns 2014.

date

Syntax<string>  date (<string> dateValue ,<string>  dateFormat)
Extension TypeFunction
DescriptionReturns the date component of the dateValue.
Exampleextact('2014-11-11 13:23:44', 'yyyy-MM-dd HH:mm:ss') returns 2014-11-11.

timestampInMilliseconds

Syntax<long>  timestampInMilliseconds ()
Extension TypeFunction
DescriptionReturns the current time stamp in milliseconds.
ExampletimestampInMilliseconds() returns 1440160328693.
Syntax<long>  timestampInMilliseconds (<string> dateValue)
Extension TypeFunction
DescriptionReturns the time stamp of the specified dateValue in milliseconds. In order to use this function, the date format of the specified dateValue should be yyyy-MM-dd HH:mm:ss.SSS.
ExampletimestampInMilliseconds('2007-11-30 10:30:19.000') returns 1196398819000.
Syntax<long>  timestampInMilliseconds (<string> dateValue, <string> dateFormat)
Extension TypeFunction
DescriptionReturns the time stamp of the specified dateValue in milliseconds. The date format can be specified in the dateForma t parameter.
ExampletimestampInMilliseconds('2007-11-30 10:30:19', 'yyyy-MM-dd HH:mm:ss') returns 1196398819000.

utcTimestamp

Syntax<string> utcTimestamp()
Extension TypeFunction
DescriptionReturns the system time in the yyyy-MM-dd HH:mm:ss date format.
ExampleutcTimestamp() returns 2015-08-21 12:16:13.

nlp 

This extension provides Natural Language Processing capabilities to Siddhi. Functions of the NLP extension are as follows.

findNameEntityType

Syntax<string> findNameEntityType(<string> entityType, <bool>  groupSuccessiveMatch, <string> string-variable )
Extension TypeFunction
Description

This function uses the following input parameters.

  • entityType : This is a user-specified string constant. e.g., PERSON, LOCATION, ORGANIZATION, MONEY, PERCENT, DATE or TIME
  • groupSuccessiveMatch : This is a user-specified boolean constant used to group successive matches of the specified entityType and a text stream.
  • streamAttribute : A string or the stream attribute in which text stream is included.

This function returns the entities in the text. If you specify group successive matches as true, the result aggregates successive words of the same entity type.

Example

findNameEntityType("PERSON",true,text)

In the above example, if the text attribute contains "Bill Gates donates £31million to fight Ebola", the result is Bill Gates. If the group successive match is set to false, two events are generated as Bill and Gates.

findNameEntityTypeViaDictionary

Syntax<string> findNameEntityTypeViaDictionary(<string> entityType, <string> dictionaryFilePath,  <string> string-variable )
Extension TypeFunction
Description

This function uses the following input parameters.

  • entityType : This is a user-specified string constant. e.g., PERSON, LOCATION, ORGANIZATION, MONEY, PERCENT, DATE or TIME
  • dictionaryFilePath : The path to the dictionary in which the function searches for the specified entries. The relevant entries for the entity types should be available in the dictionary as shown in the example below.
  • streamAttribute : A string or the stream attribute in which text stream is included.

This function returns the entities in the text. If you specify group successive matches as true , the result aggregates successive words of the same entity type.

Example

findNameEntityTypeViaDictionary("PERSON","dictionary.xml",text)

In the above example, if the text attribute contains "Bill Gates donates £31million to fight Ebola", and the dictionary consists of the above entries (i.e. entries of the example in the Description), the result is "Bill".

findRelationshipByVerb

Syntax<string > text, <string> subject,  < string > object < string >  verb   findRelationshipByVerb (<string> verb, <string> string-variable )
Extension TypeFunction
Description

findRelationshipByVerb takes in a user specified string constant as a verb and a text stream, and returns the whole text, subject, object and the verb based on the specified verb. This information can be extracted only if the verb specified exists in the text stream. However, the tense of the verb does not have to match.

The input parameters used are as follows.

  • verb : This is a user specified string constant.
  • string-variable : A string or the stream attribute which includes the text stream.
Examples

findRelationshipByVerb("say", "Information just reaching us says another Liberian With Ebola Arrested At Lagos Airport") returns the following.

  • The whole text
  • Information as the subject
  • Liberian as the object.
  • says as the verb.

findRelationshipByRegex

Syntax<string > text, <string> subject,  < string > object < string >  verb   findRelationshipByRegex (<string> regex, <string> string-variable )
Extension TypeFunction
DescriptionThis function returns the whole text, subject, object and verb from the text stream that matches the named nodes of the Semgrex pattern.
Example

findRelationshpByRegex('{}=verb >/nsubj|agent/ {}=subject >/dobj/ {}=object', "gates foundation donates $50M in support of #Ebola relief") returns the following.

  • The whole text
  • "foundation" as the subject
  • "$" as the object
  • "donates" as the verb

findSemgrexPattern

Syntax<string > text, <string> match,  < string > object < string >  verb   findSemgrexPattern (<string> regex, <string> string-variable )
Extension TypeFunction
Description

The  findSemgrexPattern function returns the whole text, subject, object and verb from the text stream that matches the named nodes of the Semgrex pattern.

This function uses the following input parameters.

  • regex : A user specified regular expression that matches the Semgrex pattern syntax.
  • string-variable : A string or the stream attribute which includes the text stream.
Example

findSemgrexPattern('{lemma:die} >/.*subj|num.*/=reln {}=diedsubject', "Sierra Leone doctor dies of Ebola after failed evacuation.")

In this example, the function searches for words with the lemmatization die that are governors on any subject or numeric relation. The dependent is marked as the diedsubject, and the relationship is marked as reln. Thus, the query returns an output stream that has the full match of this expression, i.e. the governing word with lemmatization for die. It also returns the name of the corresponding node for each match it finds.

The following is the list of elements in the output stream.

  • The whole text
  • dies as the match
  • "nsubj" as reln
  • doctor asdiedsubject

findTokensRegexPattern

Syntax< string > text, <string> match, <string>  group_1, etc.   findTokensRegexPattern (<string> regex, <string> string-variable )
Extension TypeFunction
Description

findTokensRegexPattern returns the whole text, subject, object and verb from the text stream that matches the named nodes of the Semgrex pattern. The return also includes the corresponding node in the Semgrex pattern and the corresponding named relation defined in the regular expression for each word/phrase.

This function uses the following input parameters.

  • regex : A user specified regular expression that matches the Semgrex pattern syntax.
  • string-variable : A string or the stream attribute which includes the text stream.
Example

findTokensRegexPattern('([ner:/PERSON|ORGANIZATION|LOCATION/]+) (?:[]* [lemma:donate]) ([ner:MONEY]+)', text) defines three groups:

  • The first group looks for words that are entities of  either PERSON, ORGANIZATON or LOCATION with one or more successive words matching same.
  • The middle group is defined as the non capturing group.
  • Third looks for one or more successive entities of type MONEY.

This function returns the following.

  • The whole text
  • " Paul Allen donates $ 9million " as the match.
  • " Paul Allen", as group_1.
  • "$ 9million" as group_2.

pmml 

This extension adds PMML based predictive analytic model compliance to Siddhi. It allows you to make predictions based on a predictive analytic model. Supported functions of PMML extension are as follows.

predict

Syntax< double | float|long|int|string|boolean > predict(<string> pathToPmmlFile)
Extension TypeStream Processor
Description

Processes the input stream attributes according to the defined PMML standard model and outputs the processed results together with the input stream attributes.

This function uses the following input parameter.

  • pathToPmmlFile : The path to the PMML model file.

The function returns the outputs defined in the output fields. The number of outputs can vary.

Example

predict('<DAS HOME>/samples/artifacts/0301/decision-tree.pmml')

This model is implemented to detect network intruders. The input event stream is processed by the execution plan that uses the pmml predictive model to detect whether a particular user is an intruder to the network or not. The output stream contains the processed query results that include the predicted responses together with the feature values extracted from the input event stream.

Syntax< double | float|long|int|string|boolean > predict(<string> pathToPmmlFile,  <double|float|long|int|string|boolean> input )
Extension TypeStream Processor
Description

Processes the input stream attributes according to the defined PMML standards model and outputs the processed results.

This function uses the following input parameters.

  • pathToPmmlFile : The path to the PMML model file.
  • input : An attribute of the input stream that is sent to the PMML standard model as a value to based on which the prediction is made. The predict function does not accept any constant values as input parameters. You can have multiple input parameters according to the input stream definition.

This function returns the processed outputs defined in the query. The number of outputs can vary depending on the query definition.

Examples

predict('<DAS_HOME>/samples/artifacts/0301/decision-tree.pmml', root_shell, su_attempted, num_root, num_file_creations, num_shells, num_access_files, num_outbound_cmds, is_host_login, is_guest_login, count, srv_count, serror_rate, srv_serror_rate)

This model is implemented to detect network intruders. The input event stream is processed by the execution plan that uses the pmml predictive model to detect whether a particular user is an intruder to the network or not. The output stream contains the processed query results that include the predicted responses.

 

ml

This extension provides Siddhi the capability to make predictions based on Machine Learning models. Supported functions of the ML extension are as follows.

predict

Syntax<double|float|long|int|string|boolean> predict(<string> pathToMLModel, <string> dataType)
Extension TypeStream Processor
Description

Returns an output event with the additional attribute that has the response variable name of the model, set with the predicted value, using the feature values extracted from the input event.

This function uses the following input parameters.

  • pathToMLModel : The file path or the registry path to the location of the ML model. If the model storage location is registry, the value of this parameter should have registry as the prefix.
  • dataType : The data type of the predicted value (double, float, long, integer/int, string, boolean/bool).
Example predict(‘registry:/_system/governance/mlmodels/indian-diabetes-model’)
Syntax<double|float|long|int|string|boolean> predict(<string> pathToMLModel, <string> dataType, <double> input)
Extension TypeStream Processor
Description

Returns an output event with the additional attribute that has the response variable name of the model, set with the predicted value, using the feature values extracted from the input event.

This function uses the following input parameters.

  • pathToMLModel : The file path or the registry path to the location of the ML model. If the model storage location is registry, the value of this parameter should have registry as the prefix.
  • dataType : The data type of the predicted value (double, float, long, integer/int, string, boolean/bool).
  • input : An attribute of the input stream that is sent to the ML model as a value to based on which the prediction is made. The predict function does not accept any constant values as input parameters. You can have multiple input parameters.
Examplepredict(‘registry:/_system/governance/mlmodels/indian-diabetes-model’, NumPregnancies, TSFT, DPF, BMI, DBP, PG2, Age, SI2)

 

timeseries 

See Time Series Extension.

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, <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)
Extension TypeFunction
DescriptionReturns the map as an XML string.
ExampleIf "company" is a map with key value pairs (“symbol” : wso2)(“volume” : 100), and (“price” : 200)toXML(map) returns the string “<symbol>wso2</symbol><volume><100></volume><price>200</price>.

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.

@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)
com.atlassian.confluence.content.render.xhtml.migration.exceptions.UnknownMacroMigrationException: The macro 'next_previous_links2' is unknown.