FETCHGraph
FETCH
可以获取指定点或边的属性值。
openCypher兼容性Graph
本文操作仅适用于nGQL扩展。
获取点的属性值Graph
语法Graph
FETCH PROP ON {<tag_name>[, tag_name ...] | *}
<vid> [, vid ...]
[YIELD <output>]
参数 | 说明 |
---|---|
tag_name |
标签名称。 |
* |
表示当前图空间中的所有标签。 |
vid |
点ID。 |
output |
指定要返回的信息。详情请参见Graph。如果没有YIELD 子句,将返回所有匹配的信息。 |
基于标签获取点的属性值Graph
在FETCH
语句中指定标签获取对应点的属性值。
nebula> FETCH PROP ON player "player100";
+----------------------------------------------------+
| vertices_ |
+----------------------------------------------------+
| ("player100" :player{age: 42, name: "Tim Duncan"}) |
+----------------------------------------------------+
获取点的指定属性值Graph
使用YIELD
子句指定返回的属性。
nebula> FETCH PROP ON player "player100" \
YIELD player.name;
+-------------+--------------+
| VertexID | player.name |
+-------------+--------------+
| "player100" | "Tim Duncan" |
+-------------+--------------+
获取多个点的属性值Graph
指定多个点ID获取多个点的属性值,点之间用英文逗号(,)分隔。
nebula> FETCH PROP ON player "player101", "player102", "player103";
+-----------------------------------------------------------+
| vertices_ |
+-----------------------------------------------------------+
| ("player101" :player{age: 36, name: "Tony Parker"}) |
+-----------------------------------------------------------+
| ("player102" :player{age: 33, name: "LaMarcus Aldridge"}) |
+-----------------------------------------------------------+
| ("player103" :player{age: 32, name: "Rudy Gay"}) |
+-----------------------------------------------------------+
基于多个标签获取点的属性值Graph
在FETCH
语句中指定多个标签获取属性值。标签之间用英文逗号(,)分隔。
# 创建新标签t1。
nebula> CREATE TAG t1(a string, b int);
# 为点player100添加标签t1。
nebula> INSERT VERTEX t1(a, b) VALUE "player100":("Hello", 100);
# 基于标签player和t1获取点player100上的属性值。
nebula> FETCH PROP ON player, t1 "player100";
+----------------------------------------------------------------------------+
| vertices_ |
+----------------------------------------------------------------------------+
| ("player100" :t1{a: "Hello", b: 100} :player{age: 42, name: "Tim Duncan"}) |
+----------------------------------------------------------------------------+
您可以在FETCH
语句中组合多个标签和多个点。
nebula> FETCH PROP ON player, t1 "player100", "player103";
+----------------------------------------------------------------------------+
| vertices_ |
+----------------------------------------------------------------------------+
| ("player100" :t1{a: "Hello", b: 100} :player{age: 42, name: "Tim Duncan"}) |
+----------------------------------------------------------------------------+
| ("player103" :player{age: 32, name: "Rudy Gay"}) |
+----------------------------------------------------------------------------+
获取点上所有属性值Graph
在FETCH
语句中使用*
获取点上所有属性值。
nebula> FETCH PROP ON * "player100", "player106", "team200";
+----------------------------------------------------------------------------+
| vertices_ |
+----------------------------------------------------------------------------+
| ("player106" :player{age: 25, name: "Kyle Anderson"}) |
+----------------------------------------------------------------------------+
| ("team200" :team{name: "Warriors"}) |
+----------------------------------------------------------------------------+
| ("player100" :t1{a: "Hello", b: 100} :player{age: 42, name: "Tim Duncan"}) |
+----------------------------------------------------------------------------+
获取边的属性值Graph
语法Graph
FETCH PROP ON <edge_type> <src_vid> -> <dst_vid>[@<rank>] [, <src_vid> -> <dst_vid> ...]
[YIELD <output>]
参数 | 说明 |
---|---|
edge_type |
边类型名称。 |
src_vid |
起始点ID,表示边的起点。 |
dst_vid |
目的点ID,表示边的终点。 |
rank |
边的rank。可选参数,默认值为0 。起始点、目的点、边类型和rank可以唯一确定一条边。 |
output |
指定要返回的信息。详情请参见Graph。如果没有YIELD 子句,将返回所有匹配的信息。 |
获取边的所有属性值Graph
# 获取连接player100和team204的边serve的所有属性值。
nebula> FETCH PROP ON serve "player100" -> "team204";
+-----------------------------------------------------------------------+
| edges_ |
+-----------------------------------------------------------------------+
| [:serve "player100"->"team204" @0 {end_year: 2016, start_year: 1997}] |
+-----------------------------------------------------------------------+
获取边的指定属性值Graph
使用YIELD
子句指定返回的属性。
nebula> FETCH PROP ON serve "player100" -> "team204" \
YIELD serve.start_year;
+-------------+------------+-------------+------------------+
| serve._src | serve._dst | serve._rank | serve.start_year |
+-------------+------------+-------------+------------------+
| "player100" | "team204" | 0 | 1997 |
+-------------+------------+-------------+------------------+
获取多条边的属性值Graph
指定多个边模式(<src_vid> -> <dst_vid>[@<rank>]
)获取多个边的属性值。模式之间用英文逗号(,)分隔。
nebula> FETCH PROP ON serve "player100" -> "team204", "player133" -> "team202";
+-----------------------------------------------------------------------+
| edges_ |
+-----------------------------------------------------------------------+
| [:serve "player100"->"team204" @0 {end_year: 2016, start_year: 1997}] |
+-----------------------------------------------------------------------+
| [:serve "player133"->"team202" @0 {end_year: 2011, start_year: 2002}] |
+-----------------------------------------------------------------------+
基于rank获取属性值Graph
如果有多条边,起始点、目的点和边类型都相同,可以通过指定rank获取正确的边属性值。
# 插入不同属性值、不同rank的边。
nebula> insert edge serve(start_year,end_year) \
values "player100"->"team204"@1:(1998, 2017);
nebula> insert edge serve(start_year,end_year) \
values "player100"->"team204"@2:(1990, 2018);
# 默认返回rank为0的边。
nebula> FETCH PROP ON serve "player100" -> "team204";
+-----------------------------------------------------------------------+
| edges_ |
+-----------------------------------------------------------------------+
| [:serve "player100"->"team204" @0 {end_year: 2016, start_year: 1997}] |
+-----------------------------------------------------------------------+
# 要获取rank不为0的边,请在FETCH语句中设置rank。
nebula> FETCH PROP ON serve "player100" -> "team204"@1;
+-----------------------------------------------------------------------+
| edges_ |
+-----------------------------------------------------------------------+
| [:serve "player100"->"team204" @1 {end_year: 2017, start_year: 1998}] |
+-----------------------------------------------------------------------+
复合语句中使用FETCHGraph
将FETCH
与nGQL扩展结合使用是一种常见的方式,例如和GO
一起。
# 返回从点player101开始的follow边的degree值。
nebula> GO FROM "player101" OVER follow \
YIELD follow._src AS s, follow._dst AS d \
| FETCH PROP ON follow $-.s -> $-.d \
YIELD follow.degree;
+-------------+-------------+--------------+---------------+
| follow._src | follow._dst | follow._rank | follow.degree |
+-------------+-------------+--------------+---------------+
| "player101" | "player100" | 0 | 95 |
+-------------+-------------+--------------+---------------+
| "player101" | "player102" | 0 | 90 |
+-------------+-------------+--------------+---------------+
| "player101" | "player125" | 0 | 95 |
+-------------+-------------+--------------+---------------+
您也可以通过自定义变量构建类似的查询。
nebula> $var = GO FROM "player101" OVER follow \
YIELD follow._src AS s, follow._dst AS d; \
FETCH PROP ON follow $var.s -> $var.d \
YIELD follow.degree;
+-------------+-------------+--------------+---------------+
| follow._src | follow._dst | follow._rank | follow.degree |
+-------------+-------------+--------------+---------------+
| "player101" | "player100" | 0 | 95 |
+-------------+-------------+--------------+---------------+
| "player101" | "player102" | 0 | 90 |
+-------------+-------------+--------------+---------------+
| "player101" | "player125" | 0 | 95 |
+-------------+-------------+--------------+---------------+
更多复合语句的详情,请参见Graph。
最后更新: May 12, 2021