Text functions
This page describes the available functions to assist with performing text manipulation such as concatenation, case conversion, string length calculation, and pattern matching via regular expressions.
concat#
concat(str, ...) - concatenates a string from one or more input values.
| firstName | lastName | concat |
|---|---|---|
| Tim | Thompson | Tim Thompson |
| Anna | Thompson | Anna Thompson |
| Anna | Mason | Anna Mason |
| Tom | Johnson | Tom Johnson |
| Tim | Smith | Tim Smith |
tip
concat() can be used to generate line protocol. See an example below.
length#
length(string) - reads length of string value type (result is int)
length(symbol) - reads length of symbol value type (result is int)
length(blob) - reads length of binary value type (result is long)
- a
string - a
symbol - a
binaryblob
| a | b |
|---|---|
| AARON | 5 |
| AMELIE | 6 |
| TOM | 3 |
| null | -1 |
left#
left(string, count) - extracts a substring of the given length from a string
(starting from left).
Arguments:
stringis a string to extract from.countis an integer specifying the count of characters to be extracted into a substring.
Return value:
Returns a string with the extracted characters.
Examples:
| name | l |
|---|---|
| AARON | AAR |
| AMELIE | AME |
| TOM | TOM |
right#
right(string, count) - extracts a substring of the given length from a string
(starting from right).
Arguments:
stringis a string to extract from.countis an integer specifying the count of characters to be extracted into a substring.
Return value:
Returns a string with the extracted characters.
Examples:
| name | l |
|---|---|
| AARON | ON |
| AMELIE | IE |
| TOM | OM |
strpos#
strpos(string, substring) - searches for a substring in a string, and returns
the position. If the substring is not found, this function returns 0. The
performed search is case-sensitive.
Arguments:
stringis a string to search in.substringis a string to search for.
Return value:
Returns an integer for the substring position. Positions start from 1.
Examples:
| name | idx |
|---|---|
| Tim Thompson | 5 |
| Anna Thompson | 6 |
| Anna Mason | 0 |
| Tom Johnson | 0 |
Assuming we have a table example_table with a single string type column col:
| col |
|---|
| apple,pear |
| cat,dog |
| ... |
As a more advanced example, we can use strpos() to split the string values of
col, in this case splitting at the comma , character. By using
left()/right() functions, we can choose the string values at the left and
right of the comma:
| col | col1 | col2 |
|---|---|---|
| apple,pear | apple | pear |
| cat,dog | cat | dog |
substring#
substring(string, start, length) - extracts a substring from the given string.
Arguments:
stringis a string to extract from.startis an integer specifying the position of the first character to be extracted. Positions start from1.lengthis an integer specifying the count of characters to be extracted. Should be non-negative.
Return value:
Returns a string with the extracted characters. If any part the arguments is null,
the function returns null.
Examples:
| id | country |
|---|---|
| UK2022072619373 | UK |
| UK2022072703162 | UK |
| US2022072676246 | US |
If the start argument is negative, the output depends on the value of start+length:
- If
start+lengthis greater than 1, the substring stops at positionstart+length - 1. - If
start+lengthis zero, the output is empty string. - If
start+lengthis less than zero, the output isnull.
| substring |
|---|
| Lor |
~
string ~ regex - matches string value to regex
symbol ~ regex - matches symbol value to regex
!~#
string !~ regex - checks if string value does not match regex
symbol !~ regex - checks if symbol value does not match regex
to_lowercase#
to_lowercase(string) - converts all string characters to lowercase
to_uppercase#
to_uppercase(string) - converts all string characters to uppercase