Versions Compared

Key

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

Siddhi Inbuilt functions in wiki format

...

coalesce
Anchor
coalesce
coalesce

Syntax<int|long|float|double|string|bool|object> coalesce(<int|long|float|double|string|bool|object> arg1<int|long|float|double|string|bool|object> arg2,.., <int|long|float|double|string|bool|object> argN)
Extension TypeFunction
DescriptionReturns the value of the first input parameter that is not null.
ParametersThis function accepts one or more parameters. They can belong to any one of the available types. All the specified parameters should be of the same type.
Return TypeThis will be the same as the type of the first input parameter.
Examples
  • coalesce('123', null, '789') returns 123
  • coalesce(null, 76, 567) returns 76
  • coalesce(null, null, null) returns null

...

convert
Anchor
convert
convert

Syntax<int|long|float|double|string|bool> convert(<int|long|float|double|string|bool> toBeConverted<string> convertedTo)
Extension TypeFunction
DescriptionConverts the first input parameter according to the convertedTo parameter. 
Parameters
  • toBeConverted: This specifies the value to be converted. The type of this value can be any of the available types other than object.
  • convertedTo: A string constant parameter expressing the conveverted to type using one of the following strings values: int, long, float, double, string, bool.
Return TypeThe return type is the same as the type specified by the convertedTo parameter.
Examples
  • convert('123', 'double') returns 123.0
  • convert(45.9, 'int') returns 46
  • convert(true, 'string') returns true

...

instanceOfBoolean
Anchor
boolean
boolean

Syntax<bool> instanceOfBoolean(<int|long|float|double|string|bool|object> arg)
Extension TypeFunction
DescriptionChecks whether the parameter is an instance of Boolean or not.
Parameters
  • arg: The parameter to be checked.
Return TypeReturns bool: true if the parameter is an instance of Boolean, or false if the parameter is not an instance of Boolean.
Examples
  • instanceOfBoolean(123) returns false
  • instanceOfBoolean(true) returns true
  • instanceOfBoolean(false) returns true

instanceOfDouble
Anchor
double
double

Syntax<bool> instanceOfDouble(<int|long|float|double|string|bool|object> arg)
Extension TypeFunction
DescriptionChecks whether the parameter is an instance of Double or not.
Parameters
  • arg: The parameter to be checked.
Return TypeReturns bool: true if the parameter is an instance of Double, or false if the parameter is not an instance of Double.
Examples
  • instanceOfDouble(123) returns false
  • instanceOfDouble(56.45) returns true
  • instanceOfDouble(false) returns false

instanceOfFloat
Anchor
float
float

Syntax<bool> instanceOfFloat(<int|long|float|double|string|bool|object> arg)
Extension TypeFunction
DescriptionChecks whether the parameter is an instance of Float or not.
ParameterThe parameter to be checked.
Return TypeReturns bool: true if the parameter is an instance of Float, or false if the parameter is not an instance of Float.
Examples
  • instanceOfFloat(123) returns false
  • instanceOfFloat(56.45) returns false
  • instanceOfFloat(56.45f) returns true

instanceOfInteger
Anchor
integer
integer

Syntax<bool> instanceOfInteger(<int|long|float|double|string|bool|object> arg)
Extension TypeFunction
DescriptionChecks whether the parameter is an instance of Integer or not.
ParameterThe parameter to be checked.
Return TypeReturns bool: true if the parameter is an instance of Integer, or false if the parameter is not an instance of Integer.
Examples
  • instanceOfInteger(123) returns true
  • instanceOfInteger(56.45) returns false
  • instanceOfInteger(56.45f) returns false

instanceOfLong
Anchor
long
long

Syntax<bool> instanceOfLong(<int|long|float|double|string|bool|object> arg)
Extension TypeFunction
DescriptionChecks whether the parameter is an instance of Long or not.
ParameterThe parameter to be checked.
Return TypeReturns bool: true if the parameter is an instance of Long, or false if the parameter is not an instance of Long.
Examples
  • instanceOfLong(123) returns false
  • instanceOfLong(5667l) returns true
  • instanceOfLong(56.67) returns false

instanceOfString
Anchor
string
string

Syntax<bool> instanceOfString(<int|long|float|double|string|bool|object> arg)
Extension TypeFunction
DescriptionChecks whether the parameter is an instance of String or not.
ParameterThe parameter to be checked.
Return TypeReturns bool: true if the parameter is an instance of String, or false if the parameter is not an instance of String.
Examples
  • instanceOfString('test') returns true
  • instanceOfString('5667') returns true
  • instanceOfString(56.67) returns false

UUID

Syntax<string> UUID()
Extension TypeFunction
DescriptionGenerates a UUID (Universally Unique Identifier).
Return TypeReturns a UUID string.
Examples
  • UUID() returns a34eec40-32c2-44fe-8075-7f4fde2e2dd8
  • The following converts a room number to string, introducing a message ID to each event.

    Code Block
    languagesql
    linenumberstrue
    from TempStream 
    select convert(roomNo, 'string') as roomNo, temp, UUID() as messageID
    insert into RoomTempStream;

...

cast
Anchor
cast
cast

Syntax<int|long|float|double|string|bool|object> cast(<object> toBeCasted<string> castTo)
Extension TypeFunction
Description

Converts the first parameter according to the castTo parameter. Incompatible arguments will cause Class Cast Exceptions if further processed. This is to be used with map extension which

will return attribute of type object. We can use this cast function to cast the object to accurate concrete type.

Parameters
  • toBeCasted: This specifies the attribute to be casted.
  • castTo: A string constant parameter expressing the cast to type using one of the following strings values: int, long, float, double, string, bool.
Return TypeThis will be the same as the type of the second input parameter.
Examples
  • cast(100.3, 'double') returns 100.3d
  • cast(true, 'double') returns true
  • cast(null, 'double') returns null

ifThenElse
Anchor

...

ifThenElse

...

ifThenElse

Syntax<bool> ifThenElse(<bool> condition<int|long|float|double|string|bool|object> arg1, <int|long|float|double|string|bool|object> arg2)
Extension TypeFunction
Description

Return the arg1 parameter if the condition parameter is true, or return the arg2 parameter if the condition parameter is false.

Parameters
  • condition: This specifies the if then else condition value. The type of this value : bool
  • arg1: The parameter to be return if the condition value true. The type of this value one of the following : int, long, float, double, string, bool,object.
  • arg2: The parameter to be return if the condition value false. The type of this value one of the following : int, long, float, double, string, bool,object.
Return Type

Returns <int|long|float|double|string|bool|object>arg1 if the condition parameter is true,

or  <int|long|float|double|string|bool|object> arg2  if the condition parameter is false.

Examples
  • ifThenElse(sensorValue > 35,'High','Low') returns 'High'
  • ifThenElse(voltage < 5, 0, 1) returns 'High'
  • ifThenElse(password == 'admin', true, false) returns 'High'

...