PPL Lambda functions
Note
To see which AWS data source integrations support this PPL function, see Functions.
EXISTS
Usage: exists(array,
lambda)
evaluates whether a Lambda predicate holds for one or
more elements in the array.
Argument type: ARRAY, LAMBDA
Return type: BOOLEAN. Returns
TRUE
if at least one element in the array satisfies the
Lambda predicate, otherwise FALSE
.
Examples:
os> source=people | eval array = json_array(1, -1, 2), result = exists(array, x -> x > 0) | fields result fetched rows / total rows = 1/1 +-----------+ | result | +-----------+ | true | +-----------+ os> source=people | eval array = json_array(-1, -3, -2), result = exists(array, x -> x > 0) | fields result fetched rows / total rows = 1/1 +-----------+ | result | +-----------+ | false | +-----------+
FILTER
Usage: filter(array,
lambda)
filters the input array using the given Lambda
function.
Argument type: ARRAY, LAMBDA
Return type: ARRAY. An ARRAY that contains all elements in the input array that satisfy the lambda predicate.
Examples:
os> source=people | eval array = json_array(1, -1, 2), result = filter(array, x -> x > 0) | fields result fetched rows / total rows = 1/1 +-----------+ | result | +-----------+ | [1, 2] | +-----------+ os> source=people | eval array = json_array(-1, -3, -2), result = filter(array, x -> x > 0) | fields result fetched rows / total rows = 1/1 +-----------+ | result | +-----------+ | [] | +-----------+
TRANSFORM
Usage: transform(array,
lambda)
transforms elements in an array using the Lambda
transform function. The second argument implies the index of the element if
using binary Lambda function. This is similar to a map
in
functional programming.
Argument type: ARRAY, LAMBDA
Return type: ARRAY. An ARRAY that contains the result of applying the lambda transform function to each element in the input array.
Examples:
os> source=people | eval array = json_array(1, 2, 3), result = transform(array, x -> x + 1) | fields result fetched rows / total rows = 1/1 +--------------+ | result | +--------------+ | [2, 3, 4] | +--------------+ os> source=people | eval array = json_array(1, 2, 3), result = transform(array, (x, i) -> x + i) | fields result fetched rows / total rows = 1/1 +--------------+ | result | +--------------+ | [1, 3, 5] | +--------------+
REDUCE
Usage: reduce(array, start,
merge_lambda, finish_lambda)
reduces an array to a single value
by applying lambda functions. The function applies the merge_lambda to the
start value and all array elements, then applies the
finish_lambda
to the result.
Argument type: ARRAY, ANY, LAMBDA, LAMBDA
Return type: ANY. The final result of applying the Lambda functions to the start value and the input array.
Examples:
os> source=people | eval array = json_array(1, 2, 3), result = reduce(array, 0, (acc, x) -> acc + x) | fields result fetched rows / total rows = 1/1 +-----------+ | result | +-----------+ | 6 | +-----------+ os> source=people | eval array = json_array(1, 2, 3), result = reduce(array, 10, (acc, x) -> acc + x) | fields result fetched rows / total rows = 1/1 +-----------+ | result | +-----------+ | 16 | +-----------+ os> source=people | eval array = json_array(1, 2, 3), result = reduce(array, 0, (acc, x) -> acc + x, acc -> acc * 10) | fields result fetched rows / total rows = 1/1 +-----------+ | result | +-----------+ | 60 | +-----------+