Skip to content

Commit

Permalink
get subgraph format (#1058)
Browse files Browse the repository at this point in the history
* get subgraph format

* update
  • Loading branch information
cooper-lzy authored Oct 15, 2021
1 parent 26a24b2 commit 96f7566
Showing 1 changed file with 26 additions and 25 deletions.
51 changes: 26 additions & 25 deletions docs-2.0/3.ngql-guide/16.subgraph-and-path/1.get-subgraph.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@

```ngql
GET SUBGRAPH [WITH PROP] [<step_count> STEPS] FROM {<vid>, <vid>...}
[IN <edge_type>, <edge_type>...]
[OUT <edge_type>, <edge_type>...]
[BOTH <edge_type>, <edge_type>...];
[{IN | OUT | BOTH} <edge_type>, <edge_type>...]
[YIELD [VERTICES AS <vertex_alias>] [,EDGES AS <edge_alias>]];
```

- `WITH PROP`:展示属性。不添加本参数则隐藏属性。
Expand All @@ -19,6 +18,8 @@ GET SUBGRAPH [WITH PROP] [<step_count> STEPS] FROM {<vid>, <vid>...}

- `edge_type`:指定Edge type。可以用`IN``OUT``BOTH`来指定起始点上该Edge type的方向。默认为`BOTH`

- `YIELD`:定义需要返回的输出。可以仅返回点或边。必须设置别名。不使用`YIELD`定义输出结果时,默认返回`_vertices``_edges`

!!! note

`GET SUBGRAPH`语句检索的路径类型为`trail`,即检索的路径只有点可以重复,边不可以重复。详情请参见[路径](../../1.introduction/2.1.path.md)。
Expand All @@ -32,13 +33,13 @@ GET SUBGRAPH [WITH PROP] [<step_count> STEPS] FROM {<vid>, <vid>...}
- 查询从点`player100`开始、0~1跳、所有Edge type的子图。

```ngql
nebula> GET SUBGRAPH 1 STEPS FROM "player100";
nebula> GET SUBGRAPH 1 STEPS FROM "player100" YIELD VERTICES AS nodes, EDGES AS relationships;
+-------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------+
| _vertices | _edges |
| nodes | relationships |
+-------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------+
| [("player100" :player{})] | [[:serve "player100"->"team200" @0 {}], [:follow "player100"->"player101" @0 {}], [:follow "player100"->"player102" @0 {}]] |
| [("player100" :player{})] | [[:follow "player100"->"player101" @0 {}], [:follow "player100"->"player102" @0 {}], [:serve "player100"->"team200" @0 {}]] |
+-------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------+
| [("team200" :team{}), ("player101" :player{}), ("player102" :player{})] | [[:follow "player102"->"player101" @0 {}]] |
| [("player101" :player{}), ("player102" :player{}), ("team200" :team{})] | [[:follow "player102"->"player101" @0 {}]] |
+-------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------+
```
Expand All @@ -49,24 +50,24 @@ GET SUBGRAPH [WITH PROP] [<step_count> STEPS] FROM {<vid>, <vid>...}
- 查询从点`player100`开始、0~1跳、`follow`类型的入边的子图。
```ngql
nebula> GET SUBGRAPH 1 STEPS FROM "player100" IN follow;
+---------------------------+--------+
| _vertices | _edges |
+---------------------------+--------+
| [("player100" :player{})] | [] |
+---------------------------+--------+
| [] | [] |
+---------------------------+--------+
nebula> GET SUBGRAPH 1 STEPS FROM "player100" IN follow YIELD VERTICES AS nodes, EDGES AS relationships;
+---------------------------+---------------+
| nodes | relationships |
+---------------------------+---------------+
| [("player100" :player{})] | [] |
+---------------------------+---------------+
| [] | [] |
+---------------------------+---------------+
```
因为`player100`没有`follow`类型的入边。所以仅返回点`player100`。
- 查询从点`player100`开始、0~1跳、`serve`类型的出边的子图,同时展示边的属性。
```ngql
nebula> GET SUBGRAPH WITH PROP 1 STEPS FROM "player100" OUT serve;
nebula> GET SUBGRAPH WITH PROP 1 STEPS FROM "player100" OUT serve YIELD VERTICES AS nodes, EDGES AS relationships;
+------------------------------------------------------+-------------------------------------------------------------------------+
| _vertices | _edges |
| nodes | relationships |
+------------------------------------------------------+-------------------------------------------------------------------------+
| [("player100" :player{age: 42, name: "Tim Duncan"})] | [[:serve "player100"->"team200" @0 {end_year: 2016, start_year: 1997}]] |
+------------------------------------------------------+-------------------------------------------------------------------------+
Expand Down Expand Up @@ -102,12 +103,12 @@ nebula> go 1 steps from "A" over follow;
查询到没有多余子图数据时会停止查询,且不会返回空值。

```ngql
nebula> GET SUBGRAPH 100 STEPS FROM "player141" OUT follow;
+-------------------------------------------------------+--------------------------------------------+
| _vertices | _edges |
+-------------------------------------------------------+--------------------------------------------+
| [("player141" :player{age: 43, name: "Ray Allen"})] | [[:follow "player141"->"player124" @0 {}]] |
+-------------------------------------------------------+--------------------------------------------+
| [("player124" :player{age: 33, name: "Rajon Rondo"})] | [[:follow "player124"->"player141" @0 {}]] |
+-------------------------------------------------------+--------------------------------------------+
nebula> GET SUBGRAPH 100 STEPS FROM "player141" OUT follow YIELD VERTICES AS nodes, EDGES AS relationships;
+---------------------------+--------------------------------------------+
| nodes | relationships |
+---------------------------+--------------------------------------------+
| [("player141" :player{})] | [[:follow "player141"->"player124" @0 {}]] |
+---------------------------+--------------------------------------------+
| [("player124" :player{})] | [[:follow "player124"->"player141" @0 {}]] |
+---------------------------+--------------------------------------------+
```

0 comments on commit 96f7566

Please sign in to comment.