apoc.map.submap
Function
apoc.map.submap(map MAP<STRING, ANY>, keys LIST<STRING>, values LIST<ANY>, fail BOOLEAN)
- returns a sub-map for the given keys.
If one of the keys does not exist, or lacks a default value, this function will throw an exception.
Signature
apoc.map.submap(map :: MAP, keys :: LIST<STRING>, values = [] :: LIST<ANY>, fail = true :: BOOLEAN) :: MAP
Input parameters
Name | Type | Default |
---|---|---|
map |
MAP |
null |
keys |
LIST<STRING> |
null |
values |
LIST<ANY> |
[] |
fail |
BOOLEAN |
true |
Usage Examples
The following returns a MAP
containing only the key a
:
RETURN apoc.map.submap({a:1,b:1},['a']) AS output;
Output |
---|
{a: 1} |
The following throw an exception because the map doesn’t contain the key c
:
RETURN apoc.map.submap({a:1,b:1},['c']) AS output;
Failed to invoke function |
The following returns a MAP
containing a default value of 42
for the missing key c
:
RETURN apoc.map.submap({a:1,b:1},['c'], [42]) AS output;
Output |
---|
{c: 42} |
The following returns a MAP
containing a null value for the missing key c
:
RETURN apoc.map.submap({a:1,b:1},['c'], null, false) AS output;
Output |
---|
{c: NULL} |