From 4b756fa048bd688c9134b9532a50b5ac7e9a818f Mon Sep 17 00:00:00 2001 From: cooper-lzy <78672629+cooper-lzy@users.noreply.github.com> Date: Thu, 14 Oct 2021 15:42:04 +0800 Subject: [PATCH 1/2] get subgraph format --- .../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 56169573880..697434da902 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 @@ ```ngql GET SUBGRAPH [WITH PROP] [ STEPS] FROM {, ...} -[IN , ...] -[OUT , ...] -[BOTH , ...]; +[{IN | OUT | BOTH} , ...] +[YIELD [VERTICES AS ] [,EDGES AS ]]; ``` - `WITH PROP`:展示属性。不添加本参数则隐藏属性。 @@ -19,6 +18,8 @@ GET SUBGRAPH [WITH PROP] [ STEPS] FROM {, ...} - `edge_type`:指定Edge type。可以用`IN`、`OUT`和`BOTH`来指定起始点上该Edge type的方向。默认为`BOTH`。 +- `YIELD`:定义输出结果。可以仅返回点或边。必须设置别名。不使用`YIELD`定义输出结果时,默认返回`_vertices`和`_edges`。 + !!! note `GET SUBGRAPH`语句检索的路径类型为`trail`,即检索的路径只有点可以重复,边不可以重复。详情请参见[路径](../../1.introduction/2.1.path.md)。 @@ -32,13 +33,13 @@ GET SUBGRAPH [WITH PROP] [ STEPS] FROM {, ...} - 查询从点`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 {}]] | +-------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------+ ``` @@ -49,14 +50,14 @@ GET SUBGRAPH [WITH PROP] [ STEPS] FROM {, ...} - 查询从点`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`。 @@ -64,9 +65,9 @@ GET SUBGRAPH [WITH PROP] [ STEPS] FROM {, ...} - 查询从点`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}]] | +------------------------------------------------------+-------------------------------------------------------------------------+ @@ -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 {}]] | ++---------------------------+--------------------------------------------+ ``` From 40ec82f32251097169fef990bb5ba6eb28a2efea Mon Sep 17 00:00:00 2001 From: cooper-lzy <78672629+cooper-lzy@users.noreply.github.com> Date: Thu, 14 Oct 2021 15:55:39 +0800 Subject: [PATCH 2/2] update --- docs-2.0/3.ngql-guide/16.subgraph-and-path/1.get-subgraph.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 697434da902..a1ae1019073 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 @@ -18,7 +18,7 @@ GET SUBGRAPH [WITH PROP] [ STEPS] FROM {, ...} - `edge_type`:指定Edge type。可以用`IN`、`OUT`和`BOTH`来指定起始点上该Edge type的方向。默认为`BOTH`。 -- `YIELD`:定义输出结果。可以仅返回点或边。必须设置别名。不使用`YIELD`定义输出结果时,默认返回`_vertices`和`_edges`。 +- `YIELD`:定义需要返回的输出。可以仅返回点或边。必须设置别名。不使用`YIELD`定义输出结果时,默认返回`_vertices`和`_edges`。 !!! note