Skip to main content

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)
str:tokenize(<STRING> input.string, <STRING> regex, <BOOL> distinct)

Query Parameters

NameDescriptionDefault ValuePossible Data TypesOptionalDynamic
input.stringThe input string which needs to be split.STRINGNoYes
regexThe string value which is used to tokenize the input.string.STRINGNoYes
distinctThis flag is used to return only distinct values.falseBOOLYesYes

Extra Return Attributes

NameDescriptionPossible Types
tokenThe attribute which contains a single token.STRING

Example 1

CREATE STREAM inputStream (str string);
@info(name = 'query1')

insert into outputStream
select token
from inputStream#str:tokenize(str , ',');

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.