Evaluate Function Argument on Values in Array

Evaluate the function argument on all values in a flat array

Query

logscale
array:eval(values, asArray=squared, var="x", function={x := x*x})

Introduction

The array:eval() function is used for test purposes. It evaluates the function argument on all values in the array under the array argument overwriting the input array. If an as argument has been supplied, array:eval() will save the result in an array under the supplied prefix. The purpose of this query is to square the value of each item in the array.

Example incoming data might look like this:

values[0]values[1]values[2]
234

Step-by-Step

  1. Starting with the source repository events.

  2. flowchart LR; %%{init: {"flowchart": {"defaultRenderer": "elk"}} }%% repo{{Events}} 0[\Update Field Data\] result{{Result Set}} repo --> 0 0 --> result style 0 fill:#ffbf00; style 0 fill:#ff0000,stroke-width:4px,stroke:#000;
    logscale
    array:eval(values, asArray=squared, var="x", function={x := x*x})

    Squares the value of each item in the array. If input values (x) are 2,3,4 then the output values when squared (x*x) will be 4,9,16.

  3. Event Result set.

Summary and Results

The query is used to square the value of each item in the array. This is a good example of manipulating array values, for example to format the output before display.

Sample output from the incoming example data:

fieldvalue
squared[0]4
squared[1]9
squared[2]16