API Docs - v5.0.10
Tested Siddhi Core version: 5.1.8
It could also support other Siddhi Core minor versions.
Str
groupConcat (Aggregate Function)
This function aggregates the received events by concatenating the keys in those events using a separator, e.g.,a comma (,) or a hyphen (-), and returns the concatenated key string.
Syntax<STRING> str:groupConcat(<STRING> key)
<STRING> str:groupConcat(<STRING> key, <STRING> ...)
<STRING> str:groupConcat(<STRING> key, <STRING> separator, <BOOL> distinct)
<STRING> str:groupConcat(<STRING> key, <STRING> separator, <BOOL> distinct, <STRING> order)
QUERY PARAMETERS
Name | Description | Default Value | Possible Data Types | Optional | Dynamic |
---|---|---|---|---|---|
key | The string that needs to be aggregated. |
STRING | No | Yes | |
separator | The separator that separates each string key after concatenating the keys. |
, | STRING | Yes | Yes |
distinct | This is used to only have distinct values in the concatenated string that is returned. |
false | BOOL | Yes | Yes |
order | This parameter accepts 'ASC' or 'DESC' strings to sort the string keys in either ascending or descending order respectively. |
No order | STRING | Yes | Yes |
Examples EXAMPLE 1
from InputStream#window.time(5 min)
select str:groupConcat("key") as groupedKeys
input OutputStream;
When we input events having values for the key
as 'A'
, 'B'
, 'S'
, 'C'
, 'A'
, it returns "A,B,S,C,A"
to the 'OutputStream'.
EXAMPLE 2
from InputStream#window.time(5 min)
select groupConcat("key","-",true,"ASC") as groupedKeys
input OutputStream;
When we input events having values for the key
as 'A'
, 'B'
, 'S'
, 'C'
, 'A'
, specify the seperator as hyphen and choose the order to be ascending, the function returns "A-B-C-S"
to the 'OutputStream'.
charAt (Function)
This function returns the 'char' value that is present at the given index position. of the input string.
Syntax<STRING> str:charAt(<STRING> input.value, <INT> index)
QUERY PARAMETERS
Name | Description | Default Value | Possible Data Types | Optional | Dynamic |
---|---|---|---|---|---|
input.value | The input string of which the char value at the given position needs to be returned. |
STRING | No | Yes | |
index | The variable that specifies the index of the char value that needs to be returned. |
INT | No | Yes |
Examples EXAMPLE 1
charAt("WSO2", 1)
In this case, the functiion returns the character that exists at index 1. Hence, it returns 'S'.
charFrequency (Function)
Gives the frequency of a char in input string
.
<LONG> str:charFrequency(<STRING> input.string, <STRING> char)
QUERY PARAMETERS
Name | Description | Default Value | Possible Data Types | Optional | Dynamic |
---|---|---|---|---|---|
input.string | The input string to be processed. |
STRING | No | Yes | |
char | The char's number of occurrences to be calculated |
STRING | No | Yes |
Examples EXAMPLE 1
str:charFrequency("WSO2,ABM,NSFT", ",")
This counts the number of occurrences of ,
in the given input.string
. In this scenario, the output will is 2
.
coalesce (Function)
This returns the first input parameter value of the given argument, that is not null.
Syntax<INT|LONG|DOUBLE|FLOAT|STRING|BOOL|OBJECT> str:coalesce(<INT|LONG|DOUBLE|FLOAT|STRING|BOOL|OBJECT> arg, <INT|LONG|DOUBLE|FLOAT|STRING|BOOL|OBJECT> ...)
QUERY PARAMETERS
Name | Description | Default Value | Possible Data Types | Optional | Dynamic |
---|---|---|---|---|---|
arg | It can have one or more input parameters in any data type. However, all the specified parameters are required to be of the same type. |
INT LONG DOUBLE FLOAT STRING BOOL OBJECT |
No | Yes |
Examples EXAMPLE 1
coalesce(null, "BBB", "CCC")
This returns the first input parameter that is not null. In this example, it returns "BBB".
concat (Function)
This function returns a string value that is obtained as a result of concatenating two or more input string values.
Syntax<STRING> str:concat(<STRING> arg, <STRING> ...)
QUERY PARAMETERS
Name | Description | Default Value | Possible Data Types | Optional | Dynamic |
---|---|---|---|---|---|
arg | This can have two or more |
STRING | No | Yes |
Examples EXAMPLE 1
concat("D533", "8JU^", "XYZ")
This returns a string value by concatenating two or more given arguments. In the example shown above, it returns "D5338JU^XYZ".
contains (Function)
This function returns true
if theinput.string
contains the specified sequence of char values in the search.string
.
<BOOL> str:contains(<STRING> input.string, <STRING> search.string)
QUERY PARAMETERS
Name | Description | Default Value | Possible Data Types | Optional | Dynamic |
---|---|---|---|---|---|
input.string | Input string value. |
STRING | No | Yes | |
search.string | The string value to be searched for in the |
STRING | No | Yes |
Examples EXAMPLE 1
contains("21 products are produced by WSO2 currently", "WSO2")
This returns a boolean value as the output. In this case, it returnstrue
.
equalsIgnoreCase (Function)
This returns a boolean value by comparing two strings lexicographically without considering the letter case.
Syntax<BOOL> str:equalsIgnoreCase(<STRING> arg1, <STRING> arg2)
QUERY PARAMETERS
Name | Description | Default Value | Possible Data Types | Optional | Dynamic |
---|---|---|---|---|---|
arg1 | The first input string argument. |
STRING | No | Yes | |
arg2 | The second input string argument. This is compared with the first argument. |
STRING | No | Yes |
Examples EXAMPLE 1
equalsIgnoreCase("WSO2", "wso2")
This returns a boolean value as the output. In this scenario, it returns "true".
fillTemplate (Function)
fillTemplate(string, map) will replace all the keys in the string using values in the map. fillTemplate(string, r1, r2 ..) replace all the entries {{1}}, {{2}}, {{3}} with r1 , r2, r3.
Syntax<STRING> str:fillTemplate(<STRING> template, <STRING|INT|LONG|DOUBLE|FLOAT|BOOL> replacement.type, <STRING|INT|LONG|DOUBLE|FLOAT|BOOL> ...)
<STRING> str:fillTemplate(<STRING> template, <OBJECT> map)
QUERY PARAMETERS
Name | Description | Default Value | Possible Data Types | Optional | Dynamic |
---|---|---|---|---|---|
template | The string with templated fields that needs to be filled with the given strings. The format of the templated fields should be as follows: |
STRING | No | Yes | |
replacement.type | A set of arguments with any type string|int|long|double|float|bool. |
- | STRING INT LONG DOUBLE FLOAT BOOL |
Yes | Yes |
map | A map with key-value pairs to be replaced. |
- | OBJECT | Yes | Yes |
Examples EXAMPLE 1
str:fillTemplate("{{prize}} > 100 && {{salary}} < 10000", map:create('prize', 300, 'salary', 10000))
In this example, the template is '{{prize}} > 100 && {{salary}} < 10000'.Here, the templated string {{prize}} is replaced with the value corresponding to the 'prize' key in the given map.
Likewise salary replace with the salary value of the map
EXAMPLE 2
str:fillTemplate("{{1}} > 100 && {{2}} < 10000", 200, 300)
In this example, the template is '{{1}} > 100 && {{2}} < 10000'.Here, the templated string {{1}} is replaced with the corresponding 1st value 200.
Likewise {{2}} replace with the 300
hex (Function)
This function returns a hexadecimal string by converting each byte of each character in the input string to two hexadecimal digits.
Syntax<STRING> str:hex(<STRING> input.string)
QUERY PARAMETERS
Name | Description | Default Value | Possible Data Types | Optional | Dynamic |
---|---|---|---|---|---|
input.string | The input string to derive the hexadecimal value. |
STRING | No | Yes |
Examples EXAMPLE 1
hex("MySQL")
This returns the hexadecimal value of the input.string. In this scenario, the output is "4d7953514c".
length (Function)
Returns the length of the input string.
Syntax<INT> str:length(<STRING> input.string)
QUERY PARAMETERS
Name | Description | Default Value | Possible Data Types | Optional | Dynamic |
---|---|---|---|---|---|
input.string | The input string to derive the length. |
STRING | No | Yes |
Examples EXAMPLE 1
length("Hello World")
This outputs the length of the provided string. In this scenario, the, output is 11
.
locate (Function)
This function returns the position of one string within another. Optionally, the user can give the starting index to be search from.
Syntax<INT> str:locate(<STRING> string.to.search.for, <STRING> string.to.search.in)
<INT> str:locate(<STRING> string.to.search.for, <STRING> string.to.search.in, <INT> searching.start.position)
QUERY PARAMETERS
Name | Description | Default Value | Possible Data Types | Optional | Dynamic |
---|---|---|---|---|---|
string.to.search.for | The string to be searched for. eg: @wso2.com |
STRING | No | Yes | |
string.to.search.in | The string to be searched in. eg: john@wso2.com |
STRING | No | Yes | |
searching.start.position | The character position in the string to begin the search. |
0 | INT | Yes | Yes |
Examples EXAMPLE 1
define stream inputStream (str string);
@info(name = 'query1')
from inputStream#str:locate(str , '@wso2.com')
select indexNo
insert into outputStream;
This query searches the starting index of '@wso2.com' in str. If the str is "streamin@wso2.com", then the function will return 8.
lower (Function)
Converts the capital letters in the input string to the equivalent simple letters.
Syntax<STRING> str:lower(<STRING> input.string)
QUERY PARAMETERS
Name | Description | Default Value | Possible Data Types | Optional | Dynamic |
---|---|---|---|---|---|
input.string | The input string to convert to the lower case (i.e., equivalent simple letters). |
STRING | No | Yes |
Examples EXAMPLE 1
lower("WSO2 cep ")
This converts the capital letters in the input.string to the equivalent simple letters. In this scenario, the output is "wso2 cep ".
regexp (Function)
Returns a boolean value based on the matchability of the input string and the given regular expression.
Syntax<BOOL> str:regexp(<STRING> input.string, <STRING> regex)
QUERY PARAMETERS
Name | Description | Default Value | Possible Data Types | Optional | Dynamic |
---|---|---|---|---|---|
input.string | The input string to match with the given regular expression. |
STRING | No | Yes | |
regex | The regular expression to be matched with the input string. |
STRING | No | Yes |
Examples EXAMPLE 1
regexp("WSO2 abcdh", "WSO(.*h)")
This returns a boolean value after matching regular expression with the given string. In this scenario, it returns "true" as the output.
repeat (Function)
Repeats the input string for a specified number of times.
Syntax<STRING> str:repeat(<STRING> input.string, <INT> times)
QUERY PARAMETERS
Name | Description | Default Value | Possible Data Types | Optional | Dynamic |
---|---|---|---|---|---|
input.string | The input string that is repeated the number of times as defined by the user. |
STRING | No | Yes | |
times | The number of times the input.string needs to be repeated . |
INT | No | Yes |
Examples EXAMPLE 1
repeat("StRing 1", 3)
This returns a string value by repeating the string for a specified number of times. In this scenario, the output is "StRing 1StRing 1StRing 1".
replaceAll (Function)
Finds all the substrings of the input string that matches with the given expression, and replaces them with the given replacement string.
Syntax<STRING> str:replaceAll(<STRING> input.string, <STRING> regex, <STRING> replacement.string)
QUERY PARAMETERS
Name | Description | Default Value | Possible Data Types | Optional | Dynamic |
---|---|---|---|---|---|
input.string | The input string to be replaced. |
STRING | No | Yes | |
regex | The regular expression to be matched with the input string. |
STRING | No | Yes | |
replacement.string | The string with which each substring that matches the given expression should be replaced. |
STRING | No | Yes |
Examples EXAMPLE 1
replaceAll("hello hi hello", 'hello', 'test')
This returns a string after replacing the substrings of the input string with the replacement string. In this scenario, the output is "test hi test" .
replaceFirst (Function)
Finds the first substring of the input string that matches with the given regular expression, and replaces itwith the given replacement string.
Syntax<STRING> str:replaceFirst(<STRING> input.string, <STRING> regex, <STRING> replacement.string)
QUERY PARAMETERS
Name | Description | Default Value | Possible Data Types | Optional | Dynamic |
---|---|---|---|---|---|
input.string | The input string that should be replaced. |
STRING | No | Yes | |
regex | The regular expression with which the input string should be matched. |
STRING | No | Yes | |
replacement.string | The string with which the first substring of input string that matches the regular expression should be replaced. |
STRING | No | Yes |
Examples EXAMPLE 1
replaceFirst("hello WSO2 A hello", 'WSO2(.*)A', 'XXXX')
This returns a string after replacing the first substring with the given replacement string. In this scenario, the output is "hello XXXX hello".
reverse (Function)
Returns the input string in the reverse order character-wise and string-wise.
Syntax<STRING> str:reverse(<STRING> input.string)
QUERY PARAMETERS
Name | Description | Default Value | Possible Data Types | Optional | Dynamic |
---|---|---|---|---|---|
input.string | The input string to be reversed. |
STRING | No | Yes |
Examples EXAMPLE 1
reverse("Hello World")
This outputs a string value by reversing the incoming input.string
. In this scenario, the output is "dlroW olleH".
split (Function)
Splits the input.string
into substrings using the value parsed in the split.string
and returns the substring at the position specified in the group.number
.
<STRING> str:split(<STRING> input.string, <STRING> split.string, <INT> group.number)
QUERY PARAMETERS
Name | Description | Default Value | Possible Data Types | Optional | Dynamic |
---|---|---|---|---|---|
input.string | The input string to be replaced. |
STRING | No | Yes | |
split.string | The string value to be used to split the |
STRING | No | Yes | |
group.number | The index of the split group |
INT | No | Yes |
Examples EXAMPLE 1
split("WSO2,ABM,NSFT", ",", 0)
This splits the given input.string
by given split.string
and returns the string in the index given by group.number. In this scenario, the output will is "WSO2".
strcmp (Function)
Compares two strings lexicographically and returns an integer value. If both strings are equal, 0 is returned. If the first string is lexicographically greater than the second string, a positive value is returned. If the first string is lexicographically greater than the second string, a negative value is returned.
Syntax<INT> str:strcmp(<STRING> arg1, <STRING> arg2)
QUERY PARAMETERS
Name | Description | Default Value | Possible Data Types | Optional | Dynamic |
---|---|---|---|---|---|
arg1 | The first input string argument. |
STRING | No | Yes | |
arg2 | The second input string argument that should be compared with the first argument lexicographically. |
STRING | No | Yes |
Examples EXAMPLE 1
strcmp("AbCDefghiJ KLMN", 'Hello')
This compares two strings lexicographically and outputs an integer value.
substr (Function)
Returns a substring of the input string by considering a subset or all of the following factors: starting index, length, regular expression, and regex group number.
Syntax<STRING> str:substr(<STRING> input.string, <INT> begin.index)
<STRING> str:substr(<STRING> input.string, <INT> begin.index, <INT> length)
<STRING> str:substr(<STRING> input.string, <STRING> regex)
<STRING> str:substr(<STRING> input.string, <STRING> regex, <INT> group.number)
QUERY PARAMETERS
Name | Description | Default Value | Possible Data Types | Optional | Dynamic |
---|---|---|---|---|---|
input.string | The input string to be processed. |
STRING | No | Yes | |
begin.index | Starting index to consider for the substring. |
- | INT | Yes | Yes |
length | The length of the substring. |
input.string .length - begin.index |
INT | Yes | Yes |
regex | The regular expression that should be matched with the input string. |
- | STRING | Yes | Yes |
group.number | The regex group number |
0 | INT | Yes | Yes |
Examples EXAMPLE 1
substr("AbCDefghiJ KLMN", 4)
This outputs the substring based on the given begin.index
. In this scenario, the output is "efghiJ KLMN".
EXAMPLE 2
substr("AbCDefghiJ KLMN", 2, 4)
This outputs the substring based on the given begin.index
and length. In this scenario, the output is "CDef".
EXAMPLE 3
substr("WSO2D efghiJ KLMN", '^WSO2(.*)')
This outputs the substring by applying the regex. In this scenario, the output is "WSO2D efghiJ KLMN".
EXAMPLE 4
substr("WSO2 cep WSO2 XX E hi hA WSO2 heAllo", 'WSO2(.*)A(.*)', 2)
This outputs the substring by applying the regex and considering the group.number
. In this scenario, the output is " ello".
trim (Function)
Returns a copy of the input string without the leading and trailing whitespace (if any).
Syntax<STRING> str:trim(<STRING> input.string)
QUERY PARAMETERS
Name | Description | Default Value | Possible Data Types | Optional | Dynamic |
---|---|---|---|---|---|
input.string | The input string that needs to be trimmed. |
STRING | No | Yes |
Examples EXAMPLE 1
trim(" AbCDefghiJ KLMN ")
This returns a copy of the input.string
with the leading and/or trailing white-spaces omitted. In this scenario, the output is "AbCDefghiJ KLMN".
unhex (Function)
Returns a string by converting the hexadecimal characters in the input string.
Syntax<STRING> str:unhex(<STRING> input.string)
QUERY PARAMETERS
Name | Description | Default Value | Possible Data Types | Optional | Dynamic |
---|---|---|---|---|---|
input.string | The hexadecimal input string that needs to be converted to string. |
STRING | No | Yes |
Examples EXAMPLE 1
unhex("4d7953514c")
This converts the hexadecimal value to string.
upper (Function)
Converts the simple letters in the input string to the equivalent capital/block letters.
Syntax<STRING> str:upper(<STRING> input.string)
QUERY PARAMETERS
Name | Description | Default Value | Possible Data Types | Optional | Dynamic |
---|---|---|---|---|---|
input.string | The input string that should be converted to the upper case (equivalent capital/block letters). |
STRING | No | Yes |
Examples EXAMPLE 1
upper("Hello World")
This converts the simple letters in the input.string
to theequivalent capital letters. In this scenario, the output is "HELLO WORLD".
tokenize (Stream Processor)
This function splits the input string into tokens using a given regular expression and returns the split tokens.
Syntaxstr:tokenize(<STRING> input.string, <STRING> regex)
str:tokenize(<STRING> input.string, <STRING> regex, <BOOL> distinct)
QUERY PARAMETERS
Name | Description | Default Value | Possible Data Types | Optional | Dynamic |
---|---|---|---|---|---|
input.string | The input string which needs to be split. |
STRING | No | Yes | |
regex | The string value which is used to tokenize the 'input.string'. |
STRING | No | Yes | |
distinct | This flag is used to return only distinct values. |
false | BOOL | Yes | Yes |
Name | Description | Possible Types |
---|---|---|
token | The attribute which contains a single token. |
STRING |
Examples EXAMPLE 1
define stream inputStream (str string);
@info(name = 'query1')
from inputStream#str:tokenize(str , ',')
select token
insert into outputStream;
This query performs tokenization on the given string. If the str is "Android,Windows8,iOS", then the string is split into 3 events containing the token
attribute values, i.e., Android
, Windows8
and iOS
.