Split Comma-Separated Strings in Array Into New Array

Split comma-separated strings in array into new flat array and extend with new values using the array:append() function

Query

logscale
splitString(field=numbers,by=",",as=numbarr)
| array:append(array="numbarr[]", values=[4])

Introduction

The array:append() function can be used to create a new array based on values from another flat array, provided that the input array has continuous, sequential indexes with no missing indexes.

Example incoming data might look like this:

|-----------------------|
| numbers   | "1,2,3"   |
|-----------------------|

Step-by-Step

  1. Starting with the source repository events.

  2. flowchart LR; %%{init: {"flowchart": {"defaultRenderer": "elk"}} }%% repo{{Events}} 0[\Add Field/] result{{Result Set}} repo --> 0 0 --> result style 0 fill:#ff0000,stroke-width:4px,stroke:#000;
    logscale
    splitString(field=numbers,by=",",as=numbarr)
    | array:append(array="numbarr[]", values=[4])

    Splits the comma-separated strings in the field numbers into a new array named numbarr[], and then extends this array with new values.

  3. Event Result set.

Summary and Results

This query is used to create a new flat array based on values from another flat array,

Sample output from the incoming example data:

numbarr[0]numbarr[1]numbarr[2]numbarr[3]
1234