arrayJoin
Description
Returns a single string by joining the elements of an array using the specified delimiter.
- The element type must be compatible with string conversion.
- Supported element types include
string,bool,number,interval,timestamp,regexp, andenum.
Syntax
Like many functions in DataPrime, arrayJoin supports two notations, function and method. These interchangeable forms allow flexibility in how you structure expressions.
- Function notation
- Method notation
arrayJoin(array: array<T>, delimiter: string): string
(array: array<T>).arrayJoin(delimiter: string): string
Arguments
| Name | Type | Required | Description |
|---|---|---|---|
array | array<T> | true | The array of values to join |
delimiter | string | true | The string delimiter used to join the array elements |
Example
Use case: Build a readable message from array values
Suppose you have a list of users who logged in. Consider the following input:
{
"users": ["Chip", "Ruby", "Glitch", "Cora"],
"action": "LOGIN"
}
By joining the users array with a delimiter, you can generate a human-readable string that combines the array elements with other fields.
Example query
- Function notation
- Method notation
create msg from `Users {arrayJoin(users, ',')} performed action {action}`
create msg from `Users {users.arrayJoin(',')} performed action {action}`
Example output
The result will include a new field msg with the joined string:
{
"users": ["Chip", "Ruby", "Glitch", "Cora"],
"action": "LOGIN",
"msg": "Users Chip,Ruby,Glitch,Cora performed action LOGIN"
}