我们正在使用新的Cypher 3.1 head()函数,并且在OPTIONALMATCH命令之后的RETURN语句中使用时看到了一些异常(错误?)的行为。看起来,在可选匹配中不匹配的标签会对从 head() 角度收集的数据产生负面影响,同时对 RETURN 语句的其余部分按预期工作。关于我们做错了什么的任何想法,或者这是Neo4j引擎中的意外后果?
MATCH (productLine:ProductLine)-[:CHILD]->(product:Product)-[:CHILD]->(application:Application)-[:MATCHES]->(:Rule {name: 'Tier-0 Application'})
WITH productLine,
application
OPTIONAL MATCH (application)-[mr:MATCHES]->(:Rule {name: 'Multiple Regions'})
WITH application,
mr,
productLine
RETURN
productLine.name AS ProductLine,
head([(productLine)-[:PRODUCT_MANAGER]->(person:Person) | person.name]) AS ProductLineManager,
mr.numServers,
application.id AS AppId
以下是我们看到的:
ProductLine ProductLineManager mr.numServers AppId
PL1 null null IN000041
PL2 LAST,FIRST 6 AP010024
PL3 LAST,FIRST 6 AP107752
PL4 LAST,FIRST 11 AP106560
PL5 null null AP012190
看起来这是一个与模式理解相关的错误,而不是 head() 函数,当有由可选匹配生成的行时。
我能够使用电影图表作为基础重现该错误。
我在 Neo4j 问题跟踪器上为此创建了一个错误,并附有示例。
作为一种解决方法,看起来在最后一个 WITH 或 RETURN 上使用 DISTINCT 可能会导致它返回预期的结果。