Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update 1.get-subgraph.md #808

Merged
merged 1 commit into from
Oct 18, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ The `GET SUBGRAPH` statement retrieves information of vertices and edges reachab

```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` shows the properties. If not specified, the properties will be hidden.
Expand All @@ -19,6 +18,8 @@ GET SUBGRAPH [WITH PROP] [<step_count> STEPS] FROM {<vid>, <vid>...}

- `edge_type` specifies the edge type. You can use `IN`, `OUT`, and `BOTH` to specify the traversal direction of the edge type. The default is `BOTH`.

- `YIELD` defines the output that needs to be returned. You can return only vertexes or edges. The alias must be set. When you do not use `YIELD` to define the output result, `_vertices` and `_edges` are returned by default.

!!! note

The path type of `GET SUBGRAPH` is `trail`. Only vertices can be repeatedly visited in graph traversal. For more information, see [Path](../../1.introduction/2.1.path.md).
Expand All @@ -32,13 +33,13 @@ The following graph is used as the sample.
* This example goes one step from the vertex `player100` over all edge types and gets the subgraph.

```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 @@ The following graph is used as the sample.
* This example goes one step from the vertex `player100` over incoming `follow` edges and gets the subgraph.

```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{})] | [] |
+---------------------------+---------------+
| [] | [] |
+---------------------------+---------------+
```

There is no incoming `follow` edge to `player100`, so no vertex or edge is returned.

* This example goes one step from the vertex `player100` over outgoing `serve` edges, gets the subgraph, and shows the property of the edge.

```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 @@ -103,12 +104,12 @@ nebula> go 1 steps from "A" over follow;
The query stops when there is not enough subgraph data and will not return the null value.

```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 {}]] |
+---------------------------+--------------------------------------------+
```