|| apoc.refactor.deleteAndReconnect - APOC 核心文档 - Neo4j 文档

apoc.refactor.deleteAndReconnect

详情

语法

apoc.refactor.deleteAndReconnect(path, nodes [, config ]) :: (nodes, relationships)

描述

PATH 中删除给定的 NODE 值,并重新连接剩余的 NODE 值。

输入参数

名称

类型

描述

path

PATH

包含要删除的节点和要重新连接的剩余节点的路径。

nodes

LIST<NODE>

要删除的节点。

config

MAP

{ relationshipSelectionStrategy = "incoming" :: ["incoming", "outgoing", "merge"] properties :: ["overwrite", "discard", "combine"] }. 默认值为: {}

返回参数

名称

类型

描述

nodes

LIST<NODE>

剩余的节点。

relationships

LIST<RELATIONSHIP>

新的连接关系。

配置参数

该过程支持以下配置参数

配置参数
名称 类型 默认 描述

relationshipSelectionStrategy

Enum[incoming, outgoing, merge]

true

如果为 incoming,则传入关系将附加到下一个节点。如果为 outgoing,则传出关系将附加。如果为 merge,则传入和传出关系将合并并附加。如果它们共享某些属性名称,默认情况下,传入关系的属性具有更高优先级。

properties

Enum[overwrite, discard, combine]

override

仅当 relationshipSelectionStrategy 为 merge 时才会被考虑。详见下方

属性参数
类型 操作

discard

起始节点属性优先

overwrite / override

结束节点属性优先

combine

如果传入和传出节点之间只有一个属性,则将其设置为/保留为单个属性;否则创建一个数组,并尝试强制转换值

用法示例

本节中的示例基于以下示例图

假设我们有一个简单的数据集,例如

CREATE (f:One)-[:ALPHA {a:'b'}]->(b:Two)-[:BETA {a:'d', e:'f', g: 'h'}]->(c:Three)-[:GAMMA {aa: 'one'}]->(d:Four)-[:DELTA {aa: 'bb', cc: 'dd', ee: 'ff'}]->(e:Five {foo: 'bar', baz: 'baa'}), (:Other)-[:Pippo {goku: 'gohan', vegeta: 'trunks'}]->(:Other2), (:Other)-[:Pippo2 {krilin: 'maron'}]->(:Other2)

因此,我们可以执行

MATCH p=(f:One)-->(b:Two)-->(c:Three)-->(d:Four)-->(e:Five) WITH p, [b,d] as list CALL apoc.refactor.deleteAndReconnect(p, list) YIELD nodes, relationships RETURN nodes, relationships;
结果
nodes relationships

[{"identity":0,"labels":["One"],"properties":{}},{"identity":2,"labels":["Three"],"properties":{}},{"identity":4,"labels":["Five"],"properties":{"baz":"baa","foo":"bar"}}]

[{"identity":6,"start":0,"end":2,"type":"ALPHA","properties":{"a":"b"}},{"identity":7,"start":2,"end":4,"type":"GAMMA","properties":{"aa":"one"}}]

MATCH p=(f:One)-->(b:Two)-->(c:Three)-->(d:Four)-->(e:Five) WITH p, [b,d] as list CALL apoc.refactor.deleteAndReconnect(p, list, {relationshipSelectionStrategy: 'outgoing'}) YIELD nodes, relationships RETURN nodes, relationships;
结果
nodes relationships

[{"identity":1,"labels":["One"],"properties":{}},{"identity":0,"labels":["Three"],"properties":{}},{"identity":4,"labels":["Five"],"properties":{"baz":"baa","foo":"bar"}}]

[{"identity":6,"start":1,"end":0,"type":"BETA","properties":{"a":"d","e":"f","g":"h"}},{"identity":7,"start":0,"end":4,"type":"DELTA","properties":{"aa":"bb","cc":"dd","ee":"ff"}}]

MATCH p=(f:One)-->(b:Two)-->(c:Three)-->(d:Four)-->(e:Five) WITH p, [b,d] as list CALL apoc.refactor.deleteAndReconnect(p, list, {relationshipSelectionStrategy: 'merge'}) YIELD nodes, relationships RETURN nodes, relationships;
结果
nodes relationships

[{"identity":2,"labels":["One"],"properties":{}},{"identity":0,"labels":["Three"],"properties":{}},{"identity":4,"labels":["Five"],"properties":{"baz":"baa","foo":"bar"}}]

[{"identity":6,"start":2,"end":0,"type":"ALPHA_BETA","properties":{"a":"d","e":"f","g":"h"}},{"identity":7,"start":0,"end":4,"type":"GAMMA_DELTA","properties":{"aa":"bb","cc":"dd","ee":"ff"}}]

MATCH p=(f:One)-->(b:Two)-->(c:Three)-->(d:Four)-->(e:Five) WITH p, [b,d] as list CALL apoc.refactor.deleteAndReconnect(p, list, {properties: 'combine', relationshipSelectionStrategy: 'merge'}) YIELD nodes, relationships RETURN nodes, relationships;
结果
nodes relationships

[{"identity":2,"labels":["One"],"properties":{}},{"identity":0,"labels":["Three"],"properties":{}},{"identity":4,"labels":["Five"],"properties":{"baz":"baa","foo":"bar"}}]

[{"identity":4,"start":2,"end":0,"type":"ALPHA_BETA","properties":{"a":["b","d"],"e":"f","g":"h"}},{"identity":5,"start":0,"end":4,"type":"GAMMA_DELTA","properties":{"aa":["one","bb"],"cc":"dd","ee":"ff"}}]

MATCH p=(f:One)-->(b:Two)-->(c:Three)-->(d:Four)-->(e:Five) WITH p, [b,d] as list CALL apoc.refactor.deleteAndReconnect(p, list, {relTypesToAttach: ['one', 'two']}) YIELD nodes, relationships RETURN nodes, relationships;
结果
nodes relationships

[{"identity":0,"labels":["One"],"properties":{}},{"identity":2,"labels":["Three"],"properties":{}},{"identity":4,"labels":["Five"],"properties":{"baz":"baa","foo":"bar"}}]

[{"identity":6,"start":1,"end":0,"type":"ALPHA","properties":{"a":"b"}},{"identity":7,"start":0,"end":4,"type":"GAMMA","properties":{"aa":"one"}}]

MATCH p=(f:One)-->(b:Two)-->(c:Three)-->(d:Four)-->(e:Five), ()-[rel:Pippo]->(), ()-[rel2:Pippo2]->() WITH p, [b,d] as list, collect(rel)+rel2 as rels CALL apoc.refactor.deleteAndReconnect(p, list, {relsToAttach: rels}) YIELD nodes, relationships RETURN nodes, relationships
结果
nodes relationships

[{"identity":1,"labels":["One"],"properties":{}},{"identity":0,"labels":["Three"],"properties":{}},{"identity":4,"labels":["Five"],"properties":{"baz":"baa","foo":"bar"}}]

[{"identity":4,"start":1,"end":0,"type":"ALPHA","properties":{"a":"b"}},{"identity":5,"start":0,"end":4,"type":"GAMMA","properties":{"aa":"one"}}]

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