API Docs - v4.0.16
Str
groupConcat (Aggregate Function)
Returns concated string keys by aggregating all the events separating them by the given separator.
Syntax
<STRING> str:groupConcat(<STRING> key, <STRING> separator, <STRING> distinct, <STRING> order)
QUERY PARAMETERS
Name | Description | Default Value | Possible Data Types | Optional | Dynamic |
---|---|---|---|---|---|
key | The string that need to be aggregated. | STRING | No | No | |
separator | The separator that separates each string key getting aggregated. | , | STRING | Yes | No |
distinct | To only have distinct string keys in the the aggregation. | false | STRING | Yes | No |
order | Accepts 'ASC' or 'DESC' strings to sort the string keys by ascending or descending order. | No order | STRING | Yes | No |
Examples EXAMPLE 1
from InputStream#window.time(5 min)
select str:groupConcat("key") as groupedKeys
input OutputStream;
This returns a string that is the result of the concatenated keys separated by the given separator.
When we send events having values for the key
'A'
, 'B'
, 'S'
, 'C'
, 'A'
it will return "A,B,S,C,A"
as the output
EXAMPLE 2
from InputStream#window.time(5 min)
select groupConcat("key","-",true,"ASC") as groupedKeys
input OutputStream;
This returns a string that is the result of the concatenated keys separated by the given separator.
When we send events having values for the key
'A'
, 'B'
, 'S'
, 'C'
, 'A'
it will return "A-B-C-S"
as the output
charAt (Function)
Returns the char value as a string value at the specified index.
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 that used to find the character. | STRING | No | No | |
index | The variable that specifies the index. | INT | No | No |
Examples EXAMPLE 1
charAt("WSO2", 1)
This will output the character that exists at index 1. In this case, it will output 'S'.
coalesce (Function)
Returns the value of the first of its input parameters that is not null
Syntax
<INT|LONG|DOUBLE|FLOAT|STRING|BOOL|OBJECT> str:coalesce(<INT|LONG|DOUBLE|FLOAT|STRING|BOOL|OBJECT> argn)
QUERY PARAMETERS
Name | Description | Default Value | Possible Data Types | Optional | Dynamic |
---|---|---|---|---|---|
argn | It can have one or more input parameters in any data type. All the specified parameters should be of the same type. | INT LONG DOUBLE FLOAT STRING BOOL OBJECT |
No | No |
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)
Returns a string that is the result of concatenating two or more string values.
Syntax
<STRING> str:concat(<STRING> argn)
QUERY PARAMETERS
Name | Description | Default Value | Possible Data Types | Optional | Dynamic |
---|---|---|---|---|---|
argn | It can have two or more string type input parameters. |
STRING | No | No |
Examples EXAMPLE 1
concat("D533", "8JU^", "XYZ")
This returns a string value by concatenating the given arguments. In this case, it will return "D5338JU^XYZ" as the output
contains (Function)
This method returns true
if theinput.string
contains the specified sequence of char values in the search.string
.
Syntax
<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 | No | |
search.string | The string value to be searched for in the input.string . |
STRING | No | No |
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)
Compares two strings lexicographically.
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 | No | |
arg2 | The second input string argument. This is compared with the first argument. | STRING | No | No |
Examples EXAMPLE 1
equalsIgnoreCase("WSO2", "wso2")
This returns a boolean value as the output. In this scenario, it returns "true".
fillTemplate (Function)
Replaces the templated positions in a given template with provided strings which matches withthe index in the template.
Syntax
<STRING> str:fillTemplate(<STRING> template, <STRING|INT|LONG|DOUBLE|FLOAT|BOOL> replacement.strings)
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. Templated fields should be in following the format {{INDEX}} where INDEX is an integer. This index is used to map the strings which are used to replace the templated fields. |
STRING | No | No | |
replacement.strings | Strings to replace the templated positions in the template. There can be any number of arguments from the 2nd argument. |
STRING INT LONG DOUBLE FLOAT BOOL |
No | No |
Examples EXAMPLE 1
str:fillTemplate("This is {{1}} for the {{2}} function", 'an example', 'fillTemplate')
In this example, the template is 'This is {{1}} for the {{2}} function'.Here the templated string {{1}} will be replaced with the 1st string value provided ('an example').
{{2}} will be replaced with the 2nd string provided ('fillTemplate')
The return string will be 'This is an example for the fillTemplate function'.
hex (Function)
Returns a hexadecimal string representation of str,
where each byte of each character in str is converted 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 | No |
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 this 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 | No |
Examples EXAMPLE 1
length("Hello World")
This outputs the length of the provided string. In this scenario, the, output is 11
.
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 | No |
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 whether this 'string' matches the given regular expression 'regex' or not.
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 | No | |
regex | The regular expression to be matched with the input string. | STRING | No | No |
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 a 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 | No | |
times | The number of times the input.string needs to be repeated . | INT | No | No |
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)
Replaces each substring of this string that matches the given expression with the given replacement.
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 | No | |
regex | The regular expression to be matched with the input string. | STRING | No | No | |
replacement.string | The striing with which each substring that matches the given expression should be replaced. | STRING | No | No |
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)
Replaces the first substring of this string that matches the given expression, with the given replacement.
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 | No | |
regex | The regular expression with which the input string should be matched. | STRING | No | No | |
replacement.string | The string with which the first substring of input string that matches the regular expression should be replaced. | STRING | No | No |
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 reverse ordered string of the input.
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 | No |
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 source string by split.string
and returns the substring specified via the group.number
.
Syntax
<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 | No | |
split.string | The string value to be used to split the input.string . |
STRING | No | No | |
group.number | The index of the split group | INT | No | No |
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.
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 | No | |
arg2 | The second input string argument that should be compared with the first argument lexicographically. | STRING | No | No |
Examples EXAMPLE 1
strcmp("AbCDefghiJ KLMN", 'Hello')
This compares two strings lexicographically and outputs an integer value
substr (Function)
This returns a new string that is a substring of this string
Syntax
<STRING> str:substr(<STRING> input.string, <INT> begin.index, <INT> length, <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 | No | |
begin.index | Starting index to consider for the substring. | INT | No | No | |
length | The length of the substring. | INT | No | No | |
regex | The regular expression that should be matched with the input string.. | STRING | No | No | |
group.number | The regex group number | INT | No | No |
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 string with leading and trailing whitespace omitted
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 | No |
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)
unhex(str)
interprets each pair of characters in the argument as a hexadecimal number
and converts it to the byte represented by the number
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 | No |
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 | No |
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)
Tokenize the string by delimiters and return as tokens. A new event will be created for each token
Syntax
str:tokenize(<STRING> input.string, <STRING> regex, <BOOL> distinct)
QUERY PARAMETERS
Name | Description | Default Value | Possible Data Types | Optional | Dynamic |
---|---|---|---|---|---|
input.string | The input text which should be split. | STRING | No | No | |
regex | The string value to be used to tokenize the 'input.string'. | STRING | No | No | |
distinct | Flag to return only distinct values | false | BOOL | Yes | No |
Name | Description | Possible Types |
---|---|---|
token | Attribute which contains a single token. | STRING |
Examples EXAMPLE 1
define stream inputStream (str string);
@info(name = 'query1')
from inputStream#str:tokenize(str , ',')
select text
insert into outputStream;
This query performs tokenization for the given string. If the str is "Android,Windows8,iOS", then 3 events containing token
attribute value, Android
, Windows8
, iOS
in order.