From 031ba53b230c30a3cacb27aed55dfc953eda93f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E6=99=93=E9=9D=92?= <86282370+izhuxiaoqing@users.noreply.github.com> Date: Fri, 15 Oct 2021 14:21:46 +0800 Subject: [PATCH] Update 1.get-subgraph.md --- .../16.subgraph-and-path/1.get-subgraph.md | 51 ++++++++++--------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/docs-2.0/3.ngql-guide/16.subgraph-and-path/1.get-subgraph.md b/docs-2.0/3.ngql-guide/16.subgraph-and-path/1.get-subgraph.md index 999aee5a1d8..cc4f0e6dbed 100644 --- a/docs-2.0/3.ngql-guide/16.subgraph-and-path/1.get-subgraph.md +++ b/docs-2.0/3.ngql-guide/16.subgraph-and-path/1.get-subgraph.md @@ -6,9 +6,8 @@ The `GET SUBGRAPH` statement retrieves information of vertices and edges reachab ```ngql GET SUBGRAPH [WITH PROP] [ STEPS] FROM {, ...} -[IN , ...] -[OUT , ...] -[BOTH , ...]; +[{IN | OUT | BOTH} , ...] +[YIELD [VERTICES AS ] [,EDGES AS ]]; ``` - `WITH PROP` shows the properties. If not specified, the properties will be hidden. @@ -19,6 +18,8 @@ GET SUBGRAPH [WITH PROP] [ STEPS] FROM {, ...} - `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). @@ -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 {}]] | +-------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------+ ``` @@ -49,14 +50,14 @@ 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. @@ -64,9 +65,9 @@ The following graph is used as the sample. * 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}]] | +------------------------------------------------------+-------------------------------------------------------------------------+ @@ -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 {}]] | ++---------------------------+--------------------------------------------+ ```