给定一群节点,如何查找两两之间是否存在联系

  • nebula 版本:2.6.2
  • spark-connector 版本:2.6.2

如题,给定一群节点,怎么直接展示两两之间的联系关系。
目前studio给定的图算法只能两个节点最短路径,是否可以指定多个节点

你问的是 Studio 是否支持查询多点之间的关系吗?

比如查询年龄大于 43 的 player 和 名字以 “S” 开头的 team 两个点集之间的两两之间是否存在边:


(root@nebula) [nba]> """
                  -> match (v:player) where v.player.age>43 
                  -> match (n:team) where n.team.name starts with "S" 
                  -> with v,n,(v)-->(n) as l 
                  -> return v.player.name,n.team.name,case when size(l)<>0 then true else false end AS hasConnection
                  -> """
+-------------------+-------------+---------------+
| v.player.name     | n.team.name | hasConnection |
+-------------------+-------------+---------------+
| "Steve Nash"      | "Spurs"     | false         |
| "Steve Nash"      | "Suns"      | true          |
| "Shaquile O'Neal" | "Spurs"     | false         |
| "Shaquile O'Neal" | "Suns"      | true          |
| "Grant Hill"      | "Spurs"     | false         |
| "Grant Hill"      | "Suns"      | true          |
| "Jason Kidd"      | "Spurs"     | false         |
| "Jason Kidd"      | "Suns"      | true          |
+-------------------+-------------+---------------+
Got 8 rows (time spent 12977/13382 us)

cypher 的默认语义是匹配满足 pattern 的结果,如果只关心有联系的点,语句可以简化:

(root@nebula) [nba]> match (v:player)-[e]->(n:team) where v.player.age>43 and n.team.name starts with "S" return v.player.name, n.team.name,type(e) as connection_type
+-------------------+-------------+-----------------+
| v.player.name     | n.team.name | connection_type |
+-------------------+-------------+-----------------+
| "Steve Nash"      | "Suns"      | "serve"         |
| "Steve Nash"      | "Suns"      | "serve"         |
| "Shaquile O'Neal" | "Suns"      | "serve"         |
| "Grant Hill"      | "Suns"      | "serve"         |
| "Jason Kidd"      | "Suns"      | "serve"         |
+-------------------+-------------+-----------------+
Got 5 rows (time spent 8906/9291 us)

如果是单个点集内部两两联系也是类似。也可以参考下 find path

3 个赞

好棒的回答,学到了:man_kneeling:

:+1::+1::+1:

此话题已在最后回复的 30 天后被自动关闭。不再允许新回复。