如何正确调用apoc.map.groupBy()?

时间:2017-04-27 05:19:42

标签: neo4j cypher neo4j-apoc

当我这样称呼时:

MATCH (node:Wallet)
WITH collect(node) AS nodes
CALL apoc.algo.pageRankWithConfig(nodes,{types:'SendTo'}) YIELD node, score
WITH nodes, collect({id:toString(id(node)),score:score}) as ranks
call apoc.map.groupBy(ranks,'id') as ranksById
CALL apoc.algo.closeness(['SendTo'],nodes,'INCOMING') YIELD node, score
RETURN node, ranksById[toString(id(node))] as rank, score

抛出此错误:

Invalid input 'a': expected whitespace, comment, result fields of a procedure, LOAD CSV, START, MATCH, UNWIND, MERGE, CREATE, SET, DELETE, REMOVE, FOREACH, WITH, CALL, RETURN, UNION, ';' or end of input (line 5, column 35 (offset: 224))
"call apoc.map.groupBy(ranks,'id') as ranksById"
                                   ^

当我试图以这种方式调用它时:

MATCH (node:Wallet)
WITH collect(node) AS nodes
CALL apoc.algo.pageRankWithConfig(nodes,{types:'SendTo'}) YIELD node, score
WITH nodes, collect({id:toString(id(node)),score:score}) as ranks
call apoc.map.groupBy(ranks,'id') YIELD values
CALL apoc.algo.closeness(['SendTo'],nodes,'INCOMING') YIELD node, score
RETURN node, values[toString(id(node))] as rank, score 

错误是: There is no procedure with the name `apoc.map.groupBy` registered for this database instance. Please ensure you've spelled the procedure name correctly and that the procedure is properly deployed.

当我使用call apoc.help('apoc.map.groupBy')核对时,该方法已注册,签名为apoc.map.groupBy(values :: LIST? OF ANY?, key :: STRING?) :: (MAP?)

我应该如何正确地呼叫apoc.map.groupBy

1 个答案:

答案 0 :(得分:1)

这是因为apoc.map.groupBy()是一个函数,而不是一个过程。 Neo4j 3.1引入了自定义用户函数(可以作为表达式内联调用,不需要CALL或YIELD),因此将一些过程更改为函数以获得更好的灵活性。

将您的CALL行更改为WITH,如下所示:

WITH nodes, apoc.map.groupBy(ranks,'id') as values
...