Skip to content

isEmpty

Description

Returns true if the array contains no elements, or false otherwise.

  • Supported element types include string, bool, number, interval, timestamp, regexp, and enum.

Syntax

Like many functions in DataPrime, isEmpty supports two notations, function and method notation. These interchangeable forms allow flexibility in how you structure expressions.

isEmpty(array: array<T>): bool
(array: array<T>).isEmpty(): bool

Arguments

NameTypeRequiredDescription
arrayarraytrueThe array to check for emptiness

Example

Use case 1: Check if an array is empty

You can directly test whether an array has any elements:

create is_empty from isEmpty(my_array)

This produces a new boolean field indicating whether the array is empty.

Use case 2: Optimize execution by skipping work when arrays are empty

Suppose you have documents like the following:

{
    "names": ["Chris", "John", "Ariel"]
},
{
    "names": []
}

If you want to join names into a string but avoid unnecessary computation for empty arrays, you can combine isEmpty with an if statement:

create msg from if(!names.isEmpty(), names.arrayJoin(','), '')
create msg from if(!isEmpty(names), names.arrayJoin(','), '')

Output

For the above input, the results will look like:

{
    "names": ["Chris", "John", "Ariel"],
    "msg": "Chris,John,Ariel"
},
{
    "names": [],
    "msg": ""
}