Collection Operators

Collection operators test or count the elements of a collection or sequence.

Operator | Description | Usage | First or Only Operand (op1) | Second Operand (op2) | Third Operand (op3) | Result Type | See Also |

COUNT LENGTH | Returns the number of elements in a collection or sequence. | COUNT(op1) | Collection or sequence of any type | — | — | Integer | |

IS_EMPTY | Returns true if the collection or sequence has zero elements. | IS_EMPTY(op1) | Collection or sequence of any type | — | — | Boolean | |

ALL_EQUAL | Returns true if all elements of op1 is equal to the comparison value op2. | ALL_EQUAL(op1, op2) op1 ALL_EQUAL op2 | Collection or sequence of any type | Element type of op1 | — | Boolean | |

ANY_EQUAL | Returns true if at least one element of op1 is equal to the comparison value op2. | ANY_EQUAL(op1, op2) op1 ANY_EQUAL op2 | Collection or sequence of any type | Element type of op1 | — | Boolean | |

IN | Returns true if the comparison value op1 is equal to any element in the collection or sequence op2. | IN(op1, op2) op1 IN op2 | Any type | Collection or sequence of element type op1 | — | Boolean | |

OF_EQUAL SOME_EQUAL | Returns true if at least op1 elements of op2 are equal to the comparison value op3. | OF_EQUAL(op1, op2, op3) | Integer | Collection or sequence of any type | Element type of op2 | Boolean | |

ALL | Returns true if all elements of op1 satisfies the predicate expression op2. | ALL(op1, op2) op1 ALL (op2) | Collection or sequence of embedded objects or references | Boolean | — | Boolean | |

ANY | Returns true if at least one element of op1 satisfies the predicate expression op2. | ANY(op1, op2) op1 ANY (op2) | Collection or sequence of embedded objects or references | Boolean | — | Boolean | |

OF SOME | Returns true if at least op1 elements of op2 satisfies the predicate expression op3. | OF(op1, op2, op3) | Integer | Collection or sequence of embedded objects or references | Boolean | Boolean |

Quick Look

Return the number of vehicles in the rental company:

`FROM RentalCompany RETURN COUNT(vehicles);`

Return the number of vehicles in the rental company that are currently in service:

`FROM RentalCompany RETURN COUNT(vehicles[retired == false]) as NumVehiclesInService;`

Return the licenses of vehicles with no service records:

`FROM Vehicle WHERE IS_EMPTY(servRecs) RETURN license;`

Return the vehicle categories that contain at least one model with 4 doors:

`FROM VehicleCategory WHERE ANY_EQUAL(models.doors, 4) RETURN name;`

`FROM VehicleCategory WHERE models.doors ANY_EQUAL 4 RETURN name;`

Return the licenses of vehicles with at least one oil change in their service records:

`FROM Vehicle WHERE 'oil change' IN servRecs RETURN license;`

Return the vehicle categories that contain at least one model with 4 doors:

`FROM VehicleCategory WHERE ANY(models, doors == 4) RETURN name;`

`FROM VehicleCategory WHERE models ANY (doors == 4) RETURN name;`

Return the vehicle categories that contain at least 3 models with more than 2 doors:

`FROM VehicleCategory WHERE OF(3, models, doors > 2) RETURN name;`

Discussion

For general information about operator formats, operands, and precedence, see About Operator Expressions.

Counting or Testing the Number of Elements

COUNT returns the number of elements in the collection or sequence operand. The result includes any null elements, such as elements that were previously cleared but not removed.

COUNT returns 0 if the operand evaluates to a null value. COUNT returns the size of a fixed-size list, even if no element values have ever been set.

IS_EMPTY returns true if the operand is a collection or sequence with no elements, or if the operand evaluates to null. IS_EMPTY returns false if the operand has any elements, even if all of the elements are null, such as elements that were previously cleared but not removed. IS_EMPTY always returns false for a fixed-size list, even if no element values have ever been set.

Testing Elements Based on Equality

ANY_EQUAL, ALL_EQUAL, and OF_EQUAL return true if at least one, all, or n elements of a collection or sequence are equal to a comparison value. IN returns true if the comparison value is equal to at least one element of a collection or sequence.

The elements and the comparison value must be the same data type.

These operators return false if the collection or sequence operand evaluates to a null value.

If the collection or sequence being tested contains any null elements, those elements are treated as non-qualifying—that is, as not equal to the comparison value. Consequently, a null element causes the ALL_EQUAL operator to return false.

Testing Elements Based on a Predicate

ANY, ALL, and OF evaluate to true if at least one, all, or n elements of a collection or sequence qualify by satisfying a predicate expression.

These operators return false if the collection or sequence operand evaluates to a null value.