Skip to content

API Docs - v5.0.1

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> separator, <STRING> distinct, <STRING> order)

QUERY PARAMETERS

Name Description Default Value Possible Data Types Optional Dynamic
key The string that needs to be aggregated. STRING No No
separator The separator that separates each string key after concatenating the keys. , STRING Yes No
distinct This is used to only have distinct values in the concatenated string that is returned. false STRING Yes No
order This parameter accepts 'ASC' or 'DESC' strings to sort the string keys in either ascending or descending order respectively. No order STRING Yes No

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 No
index The variable that specifies the index of the char value that needs to be returned. INT No No

Examples EXAMPLE 1

charAt("WSO2", 1)

In this case, the functiion returns the character that exists at index 1. Hence, it returns 'S'.

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> 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. However, all the specified parameters are required to 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)

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> argn)

QUERY PARAMETERS

Name Description Default Value Possible Data Types Optional Dynamic
argn This 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 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.

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)

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 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)

This extension replaces the templated positions that are marked with an index value in a specified template with the strings provided.

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. The format of the templated fields should be as follows:
{{INDEX}} where 'INDEX' is an integer.
This index is used to map the strings that are used to replace the templated fields.
STRING No No
replacement.strings The strings with which the templated positions in the template need to be replaced.
The minimum of two arguments need to be included in the execution string. There is no upper limit on the number of arguments allowed to be included.
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}} is replaced with the 1st string value provided, which is 'an example'.
{{2}} is replaced with the 2nd string provided, which is 'fillTemplate'
The complete return string is 'This is an example for the fillTemplate function'.

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 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 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 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 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 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 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 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)

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 No
regex The regular expression to be matched with the input string. STRING No No
replacement.string The string 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)

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 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 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 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 input.string into substrings using the value parsed in the split.string and returns the substring at the position specified in 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 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 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)

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, <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 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 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)

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 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)

This function splits the input string into tokens using a given regular expression and returns the split tokens.

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 string which needs to be split. STRING No No
regex The string value which is used to tokenize the 'input.string'. STRING No No
distinct This flag is used to return only distinct values. false BOOL Yes No
Extra Return Attributes
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 text
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.