Constructs a new MAP from the entries of input for which predicate returns true.
Syntax
map<K, V> map_filter(map<K, V> <input>, function<K, V, boolean> <predicate>)
Parameters
-
input: Required. A MAP value.
KandVrepresent the key type and value type of the map. -
predicate: Required. A built-in function, user-defined function, or expression used to evaluate each entry in
input. The first parameter maps to the key and the second maps to the value. The return type must be BOOLEAN.
Return value
Returns a MAP of the same type as input, containing only the entries for which predicate returns true.
Examples
Example 1: Filter entries where the sum of key and value exceeds 10.
-- Returns {-30:100, 20:50}.
SELECT map_filter(map(10, -20, 20, 50, -30, 100, 21, null), (k, v) -> (k+v) > 10);
The -> symbol is Lambda function syntax. For details, see Lambda functions.
Related functions
MAP_FILTER is a complex type function. For more information about functions that process complex types such as ARRAY, MAP, STRUCT, and JSON, see Complex type functions.