Concatenate Values in Arrays With a Defined Prefix and Suffix

Concatenate values in flat arrays using prefix, suffix and separator

Query

flowchart LR; %%{init: {"flowchart": {"defaultRenderer": "elk"}} }%% repo{{Events}} 0>Augment Data] result{{Result Set}} repo --> 0 0 --> result
logscale
concatArray(server, prefix="[", separator=",", suffix="]")

Introduction

The concatArray() method concatenates (joins) two or more arrays and returns a new array, containing the joined arrays. The concatArray() method does not change the existing arrays. For more information, see Array Syntax.

In this example, the concatArray() function concatenates the values of all fields with the same name and an array suffix into a value in a new field, adding a prefix and a suffix to the generated output result.

Example incoming data might look like this:

server[0] := "dopey"
server[1] := "sleepy"
server[2] := "doc"
server[3] := "happy"
server[4] := "sneezy"

Step-by-Step

  1. Starting with the source repository events.

  2. flowchart LR; %%{init: {"flowchart": {"defaultRenderer": "elk"}} }%% repo{{Events}} 0>Augment Data] result{{Result Set}} repo --> 0 0 --> result style 0 fill:#ff0000,stroke-width:4px,stroke:#000;
    logscale
    concatArray(server, prefix="[", separator=",", suffix="]")

    Concatenates the values of fields server[0], server[1] and so on and returns the results as a string named _concatArray enclosed in square brackets, and separated by a comma, which is similar to the written array format.

  3. Event Result set.

Summary and Results

This can be useful to summarize or format a list of items for use in another part of the query.

Sample output from the incoming example data:

server[0]server[1]server[2]server[3]server[4]_concatArray
dopeysleepydochappysneezy[dopey,sleepy,doc,happy,dopey]