在我的数据库中,我有多个具有相同属性的节点,所以我想将所有这些节点合并为一个。这些节点通过“相似”关系连接,因此我使用gds弱连接组件来查找这些社区:
CALL gds.graph.project("similar_officer",["Officer"],["similar"])
CALL gds.wcc.write('similar_officer', { writeProperty: 'community' }) YIELD nodePropertiesWritten, componentCount;
所以每个节点都有一个新的属性community,它标识了一个由“相似”关系连接的community中的所有节点
问题是:我想迭代该命令,将每个社区中的所有节点合并为一个
我在一个社区测试了这段代码:
MATCH (a)
where a.community=235631
with collect(a) as community
CALL apoc.refactor.mergeNodes(community,{properties:"discard", mergeRels:true,preserveExistingSelfRels:false})
YIELD node
RETURN count(*)
它在不到一分钟的时间内就可以工作了,它是最大的社区,所以我写了这个来为每个社区迭代:
call apoc.periodic.iterate('
MATCH (n:Officer)
with n.community as numerocom, collect(n) as nodicom, size(collect(n)) as dimcom
return numerocom, nodicom
','
CALL apoc.refactor.mergeNodes(nodicom,{
properties:"discard", mergeRels:true, preserveExistingSelfRels:false}) YIELD node
return node
',{batchSize:10000, parallel:True})
YIELD batches, total
RETURN batches, total
结果是一个永无止境的查询。我有13428个社区,最大的一个有60个节点。
我该怎么办?
1条答案
按热度按时间j5fpnvbx1#
您的查询存在一些问题。
主要问题可能是您的逻辑试图在每个事务中处理10000个社区(及其所有官员),这可能是每个事务处理的数据太多了。
另一个问题是,你是
COLLECT
的节点 * 两次 * 每个社区。第二次,您只是在计算集合的大小--但是这样做的效率非常低--您应该使用COUNT(n)
而不是SIZE(COLLECT(n))
。但更糟糕的是,你立即扔掉计数,因为你不返回它。所以,你需要完全消除计数。此查询解决了上述问题,可能更适合您。您必须自行决定最适合您的数据的
batchSize
。