关于match语句查路径去除环路问题

nebula版本号2.0.1 java-client版本号2.0.0

match p=()-[r:Relation]-()
unwind nodes§ as w with p,size(collect(Distinct w)) as len where len = length§+1
return p

这是之前使用neo4j的查询路径语句 ,第二行去除有环路的路径。

但是在nebula中查出来一直是空数据 请问如果nebula中使用match语句查询路径怎么去除循环路径呢

1 个赞

查询语句发引用的

我这边做了一个简单测试,nebula 和 neo4j 的结果是一致的。会不会是数据或者索引的问题

neo4j test:

neo4j@neo4j> create (v1:node{id:1})-[:E]->(v2:node{id:2})-[:E]->(v1);
0 rows available after 66 ms, consumed after another 0 ms
Added 2 nodes, Created 2 relationships, Set 2 properties, Added 2 labels
neo4j@neo4j> match p=(:node)-[:E]->()-[:E]->(:node) return p;
+-------------------------------------------------------------+
| p                                                           |
+-------------------------------------------------------------+
| (:node {id: 1})-[:E]->(:node {id: 2})-[:E]->(:node {id: 1}) |
| (:node {id: 2})-[:E]->(:node {id: 1})-[:E]->(:node {id: 2}) |
+-------------------------------------------------------------+

2 rows available after 47 ms, consumed after another 2 ms
neo4j@neo4j> match p=(:node)-[:E]->()-[:E]->(:node) unwind nodes(p) as w with p,size(collect(distinct w)) as len where len=length(p)+1 return p;
+---+
| p |
+---+
+---+

nebula test:

Execution succeeded (time spent 862/1085 us)

(czp@nebula) [nba]> create tag node(id int)
Execution succeeded (time spent 893/1084 us)

(czp@nebula) [nba]> insert vertex node(id) values "node1":(1)
Execution succeeded (time spent 953/1157 us)

(czp@nebula) [nba]> insert vertex node(id) values "node2":(2)
Execution succeeded (time spent 821/1010 us)

(czp@nebula) [nba]> create tag index node_index on node(id)
Execution succeeded (time spent 827/1011 us)

(czp@nebula) [nba]> rebuild tag index node_index
+------------+
| New Job Id |
+------------+
| 50         |
+------------+

(czp@nebula) [nba]> show jobs
+--------+---------------------+------------+-------------------------+-------------------------+
| Job Id | Command             | Status     | Start Time              | Stop Time               |
+--------+---------------------+------------+-------------------------+-------------------------+
| 50     | "REBUILD_TAG_INDEX" | "FINISHED" | 2021-06-23T03:13:36.000 | 2021-06-23T03:13:36.000 |

(czp@nebula) [nba]> insert edge E() values "node1"->"node2":()
Execution succeeded (time spent 965/1154 us)

(czp@nebula) [nba]> insert edge E() values "node2"->"node1":()
Execution succeeded (time spent 849/1030 us)

(czp@nebula) [nba]> match p=(:node)-[:E]->(:node)-[:E]->(:node) return p;
+----------------------------------------------------------------------------------------------+
| p                                                                                            |
+----------------------------------------------------------------------------------------------+
| <("node1" :node{id: 1})-[:E@0 {}]->("node2" :node{id: 2})-[:E@0 {}]->("node1" :node{id: 1})> |
+----------------------------------------------------------------------------------------------+
| <("node2" :node{id: 2})-[:E@0 {}]->("node1" :node{id: 1})-[:E@0 {}]->("node2" :node{id: 2})> |
+----------------------------------------------------------------------------------------------+
Got 2 rows (time spent 3448/3682 us)

(czp@nebula) [nba]> match p=(:node)-[:E]->(:node)-[:E]->(:node) unwind nodes(p) as w with p,size(collect(distinct w)) as len where len==length(p)+1 return p;
+---+
| p |
+---+
+---+
Empty set (time spent 3871/4055 us)
1 个赞

该话题在最后一个回复创建后30天后自动关闭。不再允许新的回复。

浙ICP备20010487号