我有一个是这样的一个暗号代码:
start n=node(*)
match p=n-[r:OWES*1..200]->n
return extract(s in relationships(p) : s.amount),
extract(t in nodes(p) : t.name),
length(p)
查询还给与关系连接闭路循环节点欠下高达200级深。 给出的结果是:
2
[155.55, 100641359]
[LJUBOJEVIC STR I PRZIONA KAFE VL.LJ , SASA , LJUBOJEVIC STR I PRZIONA KAFE VL.LJ ]
2
[100641359, 155.55]
[SASA , LJUBOJEVIC STR I PRZIONA KAFE VL.LJ , SASA ]
3
[100641359, 100641367, 550111.55]
[SASA , LJUBOJEVIC STR I PRZIONA KAFE VL.LJ , ADVOKAT KOSTIC JEVREM VRBAS , SASA ]
3
[100641367, 550111.55, 100641359]
[LJUBOJEVIC STR I PRZIONA KAFE VL.LJ , ADVOKAT KOSTIC JEVREM VRBAS , SASA , LJUBOJEVIC STR I PRZIONA KAFE VL.LJ ]
3
[550111.55, 100641359, 100641367]
[ADVOKAT KOSTIC JEVREM VRBAS , SASA , LJUBOJEVIC STR I PRZIONA KAFE VL.LJ , ADVOKAT KOSTIC JEVREM VRBAS ]
所以,我得到我的结果返回次以上,如果是3间的关系,我得到3个结果,2我得到diferent顺序2个相同的结果。如何从*在不放弃改变我的暗号,以一个路径得到一次导致一个暗号。 如果没有暗号我能处理这某种方式在Java中。
这是使用的Cypher 2.0,因为我正在使用的StartNode功能。
这是一个有点怪异,但它的工作原理。 无添加一些严重制约,以保持整体的集合的大小下来,我不会使用它。
CREATE
(a {name:'A'}),
(b {name:'B'}),
(c {name:'C'}),
(d {name:'D'}),
(e {name:'E'}),
(f {name:'F'}),
a-[:OWES {amount:100}]->b,
b-[:OWES {amount:200}]->c,
c-[:OWES {amount:300}]->a,
e-[:OWES {amount:400}]->f,
f-[:OWES {amount:500}]->e
start nn=node(*)
MATCH nn-[nr:OWES]->()
WITH nn, nr ORDER BY nn.name, nr.amount
WITH COLLECT([nn, nr.amount]) as sortedPairs
START n=node(*)
match p=n-[r:OWES*1..200]->n
WITH sortedPairs,
extract(s in r: [STARTNODE(s), s.amount]) as pairs
WITH
filter(sp in sortedPairs: ANY(f in pairs WHERE HEAD(f) = HEAD(sp) AND LAST(f) = LAST(sp))) as finalPairs
return distinct
extract(s in finalPairs : HEAD(s)),
extract(s in finalPairs : LAST(s)),
length(finalPairs)
结果:详细查询结果查询结果
+----------------------------------------------------------------------------------------------------------------------+
| extract(s in finalPairs : HEAD(s)) | extract(s in finalPairs : LAST(s)) | length(finalPairs) |
+----------------------------------------------------------------------------------------------------------------------+
| [Node[39]{name:"E"},Node[38]{name:"F"}] | [400,500] | 2 |
| [Node[43]{name:"A"},Node[42]{name:"B"},Node[41]{name:"C"}] | [100,200,300] | 3 |
+----------------------------------------------------------------------------------------------------------------------+
2 rows
13 ms
Execution Plan
Distinct(_rows=2, _db_hits=0)
ColumnFilter(symKeys=["sortedPairs", "pairs", "finalPairs"], returnItemNames=["finalPairs"], _rows=5, _db_hits=0)
Extract(symKeys=["sortedPairs", "pairs"], exprKeys=["finalPairs"], _rows=5, _db_hits=0)
ColumnFilter(symKeys=["n", "sortedPairs", " UNNAMED155", "pairs", "p", "r"], returnItemNames=["sortedPairs", "pairs"], _rows=5, _db_hits=0)
Extract(symKeys=["n", "sortedPairs", " UNNAMED155", "p", "r"], exprKeys=["pairs"], _rows=5, _db_hits=13)
ExtractPath(name="p", patterns=[" UNNAMED155=n-[:OWES*1..200]->n"], _rows=5, _db_hits=0)
PatternMatch(g="(n)-[' UNNAMED155']-(n)", _rows=5, _db_hits=0)
AllNodes(identifier="n", _rows=6, _db_hits=6)
ColumnFilter(symKeys=[" INTERNAL_AGGREGATEfbdcf75a-046d-4501-9696-1e2c80469b29"], returnItemNames=["sortedPairs"], _rows=1, _db_hits=0)
EagerAggregation(keys=[], aggregates=["( INTERNAL_AGGREGATEfbdcf75a-046d-4501-9696-1e2c80469b29,Collect)"], _rows=1, _db_hits=5)
ColumnFilter(symKeys=["nr", " UNNAMEDS-2101388511", " UNNAMEDS2003458696", "nn", " UNNAMED39"], returnItemNames=["nn", "nr"], _rows=5, _db_hits=0)
Sort(descr=["SortItem(Cached( UNNAMEDS2003458696 of type Any),true)", "SortItem(Cached( UNNAMEDS-2101388511 of type Any),true)"], _rows=5, _db_hits=0)
Extract(symKeys=["nn", " UNNAMED39", "nr"], exprKeys=[" UNNAMEDS2003458696", " UNNAMEDS-2101388511"], _rows=5, _db_hits=10)
PatternMatch(g="(nn)-['nr']-( UNNAMED39)", _rows=5, _db_hits=0)
AllNodes(identifier="nn", _rows=6, _db_hits=6)