|| apoc.map.submap - APOC 核心文档 - Neo4j 文档

apoc.map.submap

详情

语法

apoc.map.submap(map, keys [, values, fail ])

描述

返回给定键的子映射。如果其中一个键不存在,或缺少默认值,此函数将抛出异常。

参数

名称

类型

描述

map

MAP

要从中提取子映射的映射。

keys

LIST<STRING>

要提取到子映射中的键列表。

values

LIST<ANY>

给定键的默认值。默认值是:[]

fail

BOOLEAN

如果某个键不存在且未提供默认值,则如果为 true,它将抛出异常;否则,返回 null 值。默认值是:true

返回值

MAP

使用示例

以下返回一个只包含键 aMAP

RETURN apoc.map.submap({a:1,b:1},['a']) AS output;
结果
输出

{a: 1}

以下将抛出异常,因为映射不包含键 c

RETURN apoc.map.submap({a:1,b:1},['c']) AS output;
结果

无法调用函数 apoc.map.submap: 原因:java.lang.IllegalArgumentException: 键 c 不在现有键 [a, b] 中

以下返回一个 MAP,其中包含缺失键 c 的默认值 42

RETURN apoc.map.submap({a:1,b:1},['c'], [42]) AS output;
结果
输出

{c: 42}

以下返回一个 MAP,其中包含缺失键 c 的 null 值

RETURN apoc.map.submap({a:1,b:1},['c'], null, false) AS output;
结果
输出

{c: NULL}

© . This site is unofficial and not affiliated with Neo4j, Inc.