Cypher -Tally报告源自父节点的每种关系类型的深度 [英] Cypher -Tally report on the depth of each relationship type stemming from parent node
问题描述
我试图针对源自父节点的每种关系类型的深度创建统计报告,但遇到以下错误:
I am trying to create tally report on the depth of each relationship type stemming from parent node but I running into issues with the following error:
"Type mismatch: r already defined with conflicting type Relationship (expected Collection<Relationship>)
这是我试图实现的输出:
Here is the output I am attempting to achieve:
[
{
reltype : "123A_RelationshipTitleOne",
depthcount : 5
}, {
reltype : "123A_RelationshipTitleTwo",
depthcount : 9
}, {
reltype : "123A_RelationshipTitleThree",
depthcount : 42
}
]
这是我的密码查询尝试,它产生上述错误.我使用一个变量代替了"123A",但在这里我将"123A"用作清晰的工作示例:
Here is my cypher query attempt that generates the error mentioned above. In place of '123A' I use a a variable but I used '123A' as a legible working example here:
MATCH (n {id: '123A'})
OPTIONAL MATCH (n)-[r]-()
WHERE left( type(r), LENGTH( '123A' )) = '123A'
OPTIONAL MATCH p=(n)-[r*]->(c)
WITH n, COLLECT({
id : type(r),
count : MAX(length(p))
}) AS leafreport
RETURN n, leafreport
非常感谢您能提供的帮助.
I am very grateful for help you can offer.
推荐答案
使用绑定变量r
首先表示一个关系,然后(在第二个OPTIONAL MATCH
中)一个Collection引起type mismatch
错误关系.
The type mismatch
error is being caused by using the bound variable r
to represent first a relationship and then (in the second OPTIONAL MATCH
) a Collection of relationships.
在模式(n)-[r*]->(c)
中,r*
表示可变长度路径,因此r
绑定到与可变长度模式匹配的关系的集合.但是,r
之前已绑定到OPTIONAL MATCH (n)-[r]-()
中的关系,因此会出现错误.如果要检查路径p
中是否包含r
,请使用WHERE
子句.像这样:
In the pattern (n)-[r*]->(c)
, r*
indicates a variable length path so r
is bound to a Collection of relationships that match the variable length pattern. However r
was previously bound to a relationship in OPTIONAL MATCH (n)-[r]-()
, thus the error. If you want to check that r
is in the path, p
, use a WHERE
clause. Something like this:
MATCH (n {id: '123A'})
MATCH (n)-[r]-()
WHERE left( type(r), LENGTH( '123A' )) = '123A'
MATCH p=(n)-[rs*]->(c) WHERE r IN rs
WITH n, {
id : type(r),
count : MAX(length(p))
} AS leafreport
RETURN n, leafreport
我认为您不希望第二个OPTIONAL MATCH
是可选的,因此我将其更改为MATCH
子句
I don't think you want the second OPTIONAL MATCH
to be optional, so I changed it to a MATCH
clause
这篇关于Cypher -Tally报告源自父节点的每种关系类型的深度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!