Skip to main content

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

NameDescriptionDefault ValuePossible Data TypesOptional
input.valueThe input string of which the char value at the given position needs to be returned.STRINGNo
indexThe variable that specifies the index of the char value that needs to be returned.INTNo

Example 1

CREATE STREAM InputDataStream (eventTime long, symbol string, volume long);

CREATE SINK STREAM OutputStream (eventTime long, firstChar string, volume long);

@info(name = 'charAtQuery')
INSERT INTO OutputStream
SELECT eventTime, str:charAt(symbol, 0) AS firstChar, volume
FROM InputDataStream;

The charAtQuery processes events from the InputDataStream and extracts the first character of the symbol attribute using the str:charAt() function. The query outputs the eventTime, the first character of the symbol, and the volume of the events to the OutputStream.