由于当前版本的Neo4jClient不支持UNWIND,我在重写以下Cypher查询时遇到了麻烦:
MATCH (:A{UId:someByteArray})--(b1:B)-[:C]-(b2:B)
MATCH p = (b1)-[:C*]->(b2)
WITH b1.someString as s1, b2.someString as s2, p,
EXTRACT(c IN RELATIONSHIPS(p) | c.someValue) AS valuesAlias
UNWIND(valuesAlias) AS va
WITH s1, s2, length(NODES(p)) as pLength, MIN(va) AS minVA
WITH s1, s2, MAX(minVA) as maxMinVA, MIN(pLength) AS minPL
RETURN s1, s2, maxMinVA
的变体
答案 0 :(得分:1)
为了记录,现在Neo4jClient支持UNWIND。
答案 1 :(得分:0)
基本上需要用REDUCE / CASE语句替换UNWIND / MIN,如以下查询所示:
MATCH (:A{UId:someByteArray})--(b1:B)-[:C]-(b2:B)
MATCH p = (b1)-[:C*]->(b2)
WITH b1.someString as s1, b2.someString as s2, p,
EXTRACT(c IN RELATIONSHIPS(p) | c.someValue) AS valuesAlias
WITH s1, s2, p, length(NODES(p)) as pLength,
REDUCE(curVA=9999999999, va in valuesAlias |
CASE
WHEN va < curVA THEN va
ELSE curVA
END
) AS minVA
WITH s1, s2, MAX(minVA) as maxMinVA, MIN(pLength) AS minPL
RETURN s1, s2, maxMinVA
产生的结果完全相同,包括排序,但我想这一般不能保证。