【问题标题】:Trying to understand identifiers and collections in MATCH and WHERE试图理解 MATCH 和 WHERE 中的标识符和集合
【发布时间】:2016-02-12 20:31:50
【问题描述】:

我试图了解某些标识符或表达式对应于哪种密码“数据结构”,具体取决于它们的使用方式和位置。 下面我列出我遇到的例子。如果我做对了(在 cmets 中)或者我遗漏了什么,请告诉我。

MATCH (a:MYTYPE { label:'l_a' })
// a corresponds to a collection of nodes

MATCH (b:MYTYPE { label:'l_b' })
// so does b

MATCH p=(a)-[sp1:CF*]->(b)-[sp12:CF]->(c)
// p corresponds to a collection of paths
// a and b correspond to a collection of nodes 
// (or does the previous MATCH of a and b change something?)
// sp1 corresponds to a collection of collections of relationships
// sp12 corresponds to a collection of relationships
// c corresponds to a collection of nodes

WHERE ( p = ... )
// Here, the p corresponds to a path, i.e. there must be a path or (I don't know) on the right side of the =
WHERE ( a = ... )
// a corresponds to a node, i.e. there must be a node on the right side of the =
WHERE ( sp1 = ... )
// sp1 corresponds to a collection of nodes, i.e. there must be a collection of relationships on the right side

//BONUS:
WHERE ( (e)-[sp2:CF*]->(f) ) = ...
// there must be a collection of collections of paths on the right side of the =

【问题讨论】:

  • 在 ` p = ` 的右侧也必须是一条路径,但我不确定它们是否实现相等,如果没有,我会比较 nodes(p) 或 @ 987654323@
  • 我想当你说“a 是节点的集合”时你的意思是当你RETURN a 时你最终会在客户端中得到多行节点?否则,您的假设不正确,ab 之类的内容是每个返回行的单个节点。
  • 迈克尔:是的,你的假设是正确的。我认为“以行结束”这一事实意味着返回的值是一个集合。但现在我意识到不是。
  • @MichaelHunger : 你会建议修改我不正确的问题还是留下这样的答案/cmets?

标签: neo4j cypher


【解决方案1】:

我认为回答所有这些问题的最简单方法是将标识符传递给会抛出错误的函数,告诉您它期望什么以及实际收到什么。我认为你也应该注意你如何使用单词集合,因为它是不正确的。

节点、关系、路径

MATCH (n) RETURN n;

nNode

MATCH ()-[r]-() RETURN r;

rRelationship

MATCH p = ()-[]-()

pPath

收藏

MATCH (n) WITH COLLECT(n) AS c RETURN c;

cCollection<Node>

MATCH ()-[r]-() WITH COLLECT(r) AS c RETURN c;

cCollection<Relationship>

MATCH p = ()-[]-() WITH COLLECT(p) AS c RETURN c;

cCollection<Path>

可变长度路径

MATCH p = ()-[r*..2]-() RETURN p, r;

pPath

rCollection<Relationship>

并参考您的具体示例:

MATCH p = (a)-[sp1:CF*]->(b)-[sp12:CF]->(c)

pPath

aNode

sp1Collection<Relationship>

bNode

sp12 是一个Relationship

cNode

我不确定您对WHERE 子句的要求是什么。也许您可以通过编辑您的问题来澄清。

【讨论】:

  • 正如迈克尔上面的评论所指出的,我错误地认为返回一个标识符并以多行结尾意味着这个标识符代表一个集合。这就是我添加 WHERE 子句的原因。事实上,正如您所建议的那样,我在 WHERE 子句中尝试了几件事来从错误消息中获取信息。与我对 MATCH 部分中标识符的(错误)假设相比,我得到的信息是不同的。如果我现在理解正确的话,在 MATCH 或 WHERE 中使用的标识符的类型(例如节点、节点集合)没有区别,对吧?
  • 对。标识符的数据类型不取决于它遵循的 Cypher 关键字。
  • 这是我一段时间以来看到的关于 Cypher 的最佳问答。但只是为了让@stackoverflowwww 知道还有一些谜团需要探索,关于比较的问题,请查看this console,带有默认图表和最少修改的查询。
猜你喜欢
  • 1970-01-01
  • 2016-07-18
  • 1970-01-01
  • 2013-09-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-11-06
相关资源
最近更新 更多