get_item#

Description#

Given an array and a computed index, return the item at that index in the array. The first item has index 0, and the supplied index value may not be negative.

If the requested item does not exist, get_item() returns a null value of type variant. See variant_null() for more about null variant.

To index from the end, calculate the array_length() and subtract the desired value to determine the index. You may also use slice_array() with a negative index, although this is less efficient.

If you know the exact index value (it does not need to be computed) it is more efficient to index using regular brackets: myarray[3] is more efficient than get_item(myarray, 3).

For more advanced extraction and filtering on array data, see get_jmespath.

Return type#

variable

Domain#

This is a scalar function (calculates a single output value for a single input row.)

Categories#

Usage#

get_item(array, item)

Argument

Type

Optional

Repeatable

Restrictions

array

array

no

no

none

item

int64

no

no

none

Examples#

make_col someindex:1
make_col somearray:array(parse_json("[5,17,3,8,2,20]"))
make_col final:int64(get_item(somearray, someindex))
drop_col someindex, somearray

Make a new column final that contains the value 17. It does this by constructing an array in a temporary column somearray and an index in a temporary column someindex and then looking up the value of that index in the array. Because object lookup returns variant, the code casts the value to an int64.