简体   繁体   English

什么是neo4j cypher中的模式理解和自定义投影

[英]What is pattern comprehension and custom projection in neo4j cypher

I was reading cypher refcard in which I came across following: 我正在阅读cypher refcard ,其中我遇到了以下内容:

Pattern comprehensions may be used to do a custom projection from a match directly into a list: 模式推导可用于从匹配中直接进行自定义投影到列表中:

MATCH (a)
RETURN [(a)-->(b) WHERE b.name = 'Bob' | b.age]

I prepared simple graph and tried similar looking queries on it. 我准备了简单的图表并尝试了类似的查询。 But it kept giving error Invalid input 'W': expected whitespace, comment, a relationship pattern on WHERE . 但它一直给出错误Invalid input 'W': expected whitespace, comment, a relationship pattern WHEREInvalid input 'W': expected whitespace, comment, a relationship pattern

Q1. Q1。 Whats the meaning of the above cypher, should it return all paths (a)-->(b) with b.name=Bob or return b.age ? 什么是上述密码的含义,如果它返回所有路径(a)-->(b) b.name=Bob或返回b.age

Q2. Q2。 I never saw path specification (a)-->(b) after RETURN . 我从未在RETURN之后看到路径规范(a)-->(b) Obviously I am missing some basics here. 显然我在这里缺少一些基础知识。 Whats that? 那是什么?

NOTE: Pattern comprehension was only introduced in Neo4j 3.1, versions 3.0.x and below won't have this feature. 注意:模式理解仅在Neo4j 3.1中引入,版本3.0.x及以下版本不具备此功能。

Answer to Q1 : The meaning in this example is: "Given variable a (since it is in scope from earlier in the query) find an outgoing relation to some node and bind it to the variable b where node b 's name property is 'Bob'. Populate a list with the age property of every b node. 对Q1的回答 :这个例子中的含义是:“给定变量a (因为它在查询中较早的范围内)找到与某个节点的传出关系并将其绑定到变量b ,其中节点b的名称属性为' Bob'。使用每个b节点的age属性填充列表。

The | | in this context separates the pattern and where clause from the expression of what values to populate into the resulting list. 在此上下文中,将pattern和where子句与要填充到结果列表中的值的表达式分开。

Not sure I'm following what you're asking about in Q2. 不确定我是否跟随你在Q2的要求。

For your specific usage, why it's giving you an error, we need to be able to see what you're doing with it to figure out the problem. 对于您的具体用法,为什么它会给您一个错误,我们需要能够看到您正在使用它来解决问题。 Can you add that to your description? 你能将它添加到你的描述中吗?

Though if I was to venture a guess, you might be using a pattern in the pattern comprehension that doesn't have any relationships, something like this: 虽然如果我冒险猜测,你可能会在模式理解中使用一种没有任何关系的模式,如下所示:

return [(a:Person) | a.name] as names

Currently usages like this will fail when there is no relationship in the pattern, something I consider a bug, and filed as such to the issues list. 目前这种用法在模式中没有任何关系时会失败,我认为这是一个错误,并且如此提交到问题列表中。

For more info, here's the pattern comprehension entry in the dev guide, and a longer writeup about pattern comprehension (and map projection). 有关更多信息,请参阅开发指南中的模式理解条目 ,以及有关模式理解(和地图投影)的更长篇幅

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM