Checks whether an element in Array a meets the predicate condition.
Syntax
boolean any_match(array<T> <a>, function<T, boolean> <predicate>)
Parameters
a: required. This parameter specifies an array that
T
inarray<T>
specifies the data type of the elements in the array. The elements can be of any data type.predicate: required. This parameter specifies the built-in function, user-defined function, or expression that is used to determine whether all the elements in Array a meet requirements. The data type of the input parameter must be the same as the data type of the elements in Array a.
Return value
A value of the BOOLEAN type is returned. The return value varies based on the following rules:
If one or more elements in Array a meet the predicate condition, true is returned.
If no elements in Array a meet the predicate condition or the array is empty, false is returned.
If an element in Array a is null and other elements do not meet the predicate condition, null is returned.
Examples
Example 1: Check whether an element in
array(1, 2, -10, 100, -30)
meets thexx > 3
condition. Sample statement:-- The return value is true. select any_match(array(1, 2, -10, 100, -30), x-> x > 3);
Example 2: The array is empty. Sample statement:
-- The return value is false. select any_match(array(), x-> x > 3);
Example 3: Check whether an element in
array(1, 2, -10, -20, -30)
meets thex-> x > 3
condition. Sample statement:-- The return value is false. select any_match(array(1, 2, -10, -20, -30), x-> x > 3);
Example 4: Check whether an element in
array(1, 2, null, -10)
meets thex-> x > 3
condition. Sample statement:-- The return value is null. select any_match(array(1, 2, null, -10), x-> x > 3);
Related functions
ANY_MATCH is a complex type function. For more information about the functions that are used to process data of complex data types, such as ARRAY, MAP, STRUCT, and JSON, see Complex type functions.
In the preceding examples, the combination of a hyphen and a closing angle bracket
(->)
is used. For more information about how to use the combination of a hyphen and a closing angle bracket(->)
in Lambda functions, see Lambda functions.