TOC
- Condition expressions on multiple hops in MATCH
- FIND PATH
- Use MATCH to get STATS
- Important reference variable and functions you could miss!
- nGQL MATCH v.s. OpenCypher MATCH
- Escaping key words
- RETURN values should be explicitly specified in latest
WITH
Clause
Table of contents generated with markdown-toc
Good to read/know URLs:
- FAQ EN, FAQ CN 出问题先过一下
- Learning_Path, 学习路劲 学习路径
- https://siwei.io article/video/toolings
- Blog, 中文博客
Condition expressions on multiple hops in MATCH
https://discuss.nebula-graph.com.cn/t/topic/6625/5
如果想要通过描述多跳的边的过滤条件,比如-[e:follow*2]->
,这时候 e
不再是单条边时候的数据类型了,而是一列边组成的列表,例如:
以下语句可以运行但是没有返回数据,因为e
是一个列表,没有.degree
的属性。
nebula> MATCH p=(v:player{name:"Tim Duncan"})-[e:follow*2]->(v2) \
WHERE e.degree > 1 \
RETURN DISTINCT v2 AS Friends;
这是正确的表达:
nebula> MATCH p=(v:player{name:"Tim Duncan"})-[e:follow*2]->(v2) \
WHERE ALL(e_ in e WHERE e_.degree > 0) \
RETURN DISTINCT v2 AS Friends;
进一步,这是表达对多跳边的第一跳的边属性过滤的表达:
nebula> MATCH p=(v:player{name:"Tim Duncan"})-[e:follow*2]->(v2) \
WHERE e[0].degree > 98 \
RETURN DISTINCT v2 AS Friends;
还有一种表达,用花括号,注意花括号要在星号之后:
(root@nebula) [basketballplayer]> match (n:player)-[e:follow{degree:95}*3]-(v) return n
[ERROR (-1004)]: SyntaxError: syntax error near `*3]-(v) '
Fri, 26 Nov 2021 17:11:34 CST
(root@nebula) [basketballplayer]> match (n:player)-[e:follow*3{degree:95}]-(v) return n
+-------------------------------------------------------+
| n |
+-------------------------------------------------------+
| ("player100" :player{age: 42, name: "Tim Duncan"}) |
+-------------------------------------------------------+
| ("player125" :player{age: 41, name: "Manu Ginobili"}) |
+-------------------------------------------------------+
FIND PATH
https://discuss.nebula-graph.com.cn/t/topic/6636
Use MATCH to get STATS
We shoud use STATS JOB instead.
Wrong:
MATCH (v:player) return COUNT(v)
We should use:
SUBMIT JOB STATS;
# Wait for its being finished
SHOW STATS;
+---------+------------+-------+
| Type | Name | Count |
+---------+------------+-------+
| "Tag" | "player" | 51 |
| "Tag" | "team" | 30 |
| "Edge" | "follow" | 81 |
| "Edge" | "serve" | 152 |
| "Space" | "vertices" | 81 |
| "Space" | "edges" | 233 |
+---------+------------+-------+
Important reference variable and functions you could miss!
How to describe wildcard edge properties?
- functions you may miss: https://docs.nebula-graph.com.cn/2.6.1/3.ngql-guide/6.functions-and-expressions/4.schema/
- reference variables: https://docs.nebula-graph.com.cn/2.6.1/3.ngql-guide/5.operators/5.property-reference/
(root@nebula) [basketballplayer]> go from "player100" over * YIELD properties(edge)
+------------------------------------+
| properties(EDGE) |
+------------------------------------+
| {end_year: 2016, start_year: 1997} |
+------------------------------------+
| {degree: 95} |
+------------------------------------+
| {degree: 95} |
+------------------------------------+
Got 3 rows (time spent 1379/50293 us)
Fri, 26 Nov 2021 12:12:44 CST
(root@nebula) [basketballplayer]> go from "player100" over * WHERE properties(edge).degree > 1 YIELD properties(edge)
+------------------+
| properties(EDGE) |
+------------------+
| {degree: 95} |
+------------------+
| {degree: 95} |
+------------------+
Got 2 rows (time spent 1518/35277 us)
Fri, 26 Nov 2021 12:13:13 CST
nGQL MATCH v.s. OpenCypher MATCH
- https://docs.nebula-graph.com.cn/2.6.1/3.ngql-guide/1.nGQL-overview/1.overview/#ngql_opencypher_10
- https://docs.nebula-graph.io/2.6.1/3.ngql-guide/1.nGQL-overview/1.overview/#ngql_opencypher_10
Escaping key words
i.e. User
is a keyword, we should quote it with `.
(root@nebula) [amundsen]> MATCH (u:User) WHERE id(u) == "" RETURN u
[ERROR (-1009)]: SemanticError: `user': Unknown tag
(root@nebula) [amundsen]> MATCH (u:`User`) WHERE id(u) == "" RETURN u
+---+
| u |
+---+
+---+
Empty set (time spent 3313/9641 us)
WITH
Clause
RETURN values should be explicitly specified in latest TBD
Get dst/src in bidirect traversal