Skip to main content

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

NameDescriptionDefault ValuePossible Data TypesOptionalDynamic
input.stringThe input string to be replaced.STRINGNoYes
split.stringThe string value to be used to split the input.string.STRINGNoYes
group.numberThe index of the split group.INTNoYes

Example 1

@info(name = 'splitExample')
SELECT str:split('gdn,ABM,NSFT', ',', 0) AS splitAtIndex;

The splitExample demonstrates the use of the str:split() function to split the input string by a specified delimiter and return the string at the given index. In this example, the input string is 'gdn,ABM,NSFT', the delimiter is ',', and the index is 0. The function returns 'gdn', which is the string at index 0 after splitting the input string by the specified delimiter.

Example 2

CREATE STREAM InputDataStream (eventTime long, inputString string, delimiter string, indexToReturn int);
CREATE SINK STREAM OutputStream (eventTime long, splitAtIndex string);

@info(name = 'splitStreamWorker')
INSERT INTO OutputStream
SELECT eventTime, str:split(inputString, delimiter, indexToReturn) AS splitAtIndex
FROM InputDataStream;

The splitStreamWorker processes events from the InputDataStream and uses the str:split() function to split the inputString attribute by the specified delimiter attribute and return the string at the given indexToReturn attribute. The query outputs the eventTime and the resulting splitAtIndex for each event to the OutputStream.