diff --git a/docs-2.0/3.ngql-guide/6.functions-and-expressions/4.schema.md b/docs-2.0/3.ngql-guide/6.functions-and-expressions/4.schema.md index 497fbfe86a2..c577cceee5d 100644 --- a/docs-2.0/3.ngql-guide/6.functions-and-expressions/4.schema.md +++ b/docs-2.0/3.ngql-guide/6.functions-and-expressions/4.schema.md @@ -13,6 +13,8 @@ Nebula Graph支持以下Schema函数。 |list labels(vertex) | 返回点的Tag,与tags()作用相同,用于兼容openCypher语法。| |map properties(vertex_or_edge) | 接收点或边并返回其属性。| |string type(edge) | 返回边的Edge type。| +|src(edge)|返回边的起始点ID。数据类型和点ID的类型保持一致。| +|dst(edge)|返回边的目的点ID。数据类型和点ID的类型保持一致。| |vertex startNode(path) | 获取一条边或一条路径并返回它的起始点ID。| |string endNode(path) | 获取一条边或一条路径并返回它的目的点ID。| |int rank(edge) | 返回边的rank。| diff --git a/docs-2.0/3.ngql-guide/7.general-query-statements/3.go.md b/docs-2.0/3.ngql-guide/7.general-query-statements/3.go.md index 8fe4ad7d0ea..3eeb74d47fb 100644 --- a/docs-2.0/3.ngql-guide/7.general-query-statements/3.go.md +++ b/docs-2.0/3.ngql-guide/7.general-query-statements/3.go.md @@ -13,14 +13,10 @@ GO [[ TO] STEPS ] FROM OVER [{REVERSELY | BIDIRECT}] [ WHERE  ] [YIELD [DISTINCT] ] +[| GROUP BY {col_name | expr | position} YIELD ] [| ORDER BY [{ASC | DESC}]] [| LIMIT [,] ] -GO [[ TO] STEPS ] FROM -OVER [{REVERSELY | BIDIRECT}] -[ WHERE  ] -[| GROUP BY {col_name | expr | position} YIELD ] - ::= [, ...] @@ -52,7 +48,9 @@ OVER [{REVERSELY | BIDIRECT}] 遍历多个Edge type时,`WHERE`子句有一些限制。例如不支持`WHERE edge1.prop1 > edge2.prop2`。 -- `YIELD [DISTINCT] `:指定输出结果。详情请参见[YIELD](../8.clauses-and-options/yield.md)。如果没有指定,默认返回目的点ID。 +- `YIELD [DISTINCT] `:定义需要返回的输出。` `建议使用[Schema函数](../6.functions-and-expressions/4.schema.md),当前支持`src(edge)`、`dst(edge)`、`type(edge)`、`rank(edge)`、`properties(edge)`、`id(vertex)`、`properties(vertex)`。详情请参见[YIELD](../8.clauses-and-options/yield.md)。如果没有指定,默认返回目的点ID。 + +- `GROUP BY`:根据指定属性的值将输出分组。详情请参见[GROUP BY](../8.clauses-and-options/group-by.md)。分组后需要再次使用`YIELD`定义需要返回的输出。 - `ORDER BY`:指定输出结果的排序规则。详情请参见[ORDER BY](../8.clauses-and-options/order-by.md)。 @@ -62,8 +60,6 @@ OVER [{REVERSELY | BIDIRECT}] - `LIMIT`:限制输出结果的行数。详情请参见[LIMIT](../8.clauses-and-options/limit.md)。 -- `GROUP BY`:根据指定属性的值将输出分组。详情请参见[GROUP BY](../8.clauses-and-options/group-by.md)。 - ## 示例 ```ngql @@ -94,8 +90,9 @@ nebula> GO 2 STEPS FROM "player102" OVER follow; ```ngql # 添加过滤条件。 nebula> GO FROM "player100", "player102" OVER serve \ - WHERE serve.start_year > 1995 \ - YIELD DISTINCT $$.team.name AS team_name, serve.start_year AS start_year, $^.player.name AS player_name; + WHERE properties(edge).start_year > 1995 \ + YIELD DISTINCT properties($$).name AS team_name, properties(edge).start_year AS start_year, properties($^).name AS player_name; + +-----------------+------------+---------------------+ | team_name | start_year | player_name | +-----------------+------------+---------------------+ @@ -108,24 +105,24 @@ nebula> GO FROM "player100", "player102" OVER serve \ ``` ```ngql -# 遍历多个Edge type。属性没有值时,会显示__EMPTY__。 +# 遍历多个Edge type。属性没有值时,会显示UNKNOWN_PROP。 nebula> GO FROM "player100" OVER follow, serve \ - YIELD follow.degree, serve.start_year; -+---------------+------------------+ -| follow.degree | serve.start_year | -+---------------+------------------+ -| 95 | __EMPTY__ | -+---------------+------------------+ -| 95 | __EMPTY__ | -+---------------+------------------+ -| __EMPTY__ | 1997 | -+---------------+------------------+ + YIELD properties(edge).degree, properties(edge).start_year; ++-------------------------+-----------------------------+ +| properties(EDGE).degree | properties(EDGE).start_year | ++-------------------------+-----------------------------+ +| 95 | UNKNOWN_PROP | ++-------------------------+-----------------------------+ +| 95 | UNKNOWN_PROP | ++-------------------------+-----------------------------+ +| UNKNOWN_PROP | 1997 | ++-------------------------+-----------------------------+ ``` ```ngql # 返回player100入方向的邻居点。 nebula> GO FROM "player100" OVER follow REVERSELY \ - YIELD follow._dst AS destination; + YIELD src(edge) AS destination; +-------------+ | destination | +-------------+ @@ -151,16 +148,16 @@ nebula> MATCH (v)<-[e:follow]- (v2) WHERE id(v) == 'player100' \ ```ngql # 查询player100的朋友和朋友所属队伍。 nebula> GO FROM "player100" OVER follow REVERSELY \ - YIELD follow._dst AS id | \ + YIELD src(edge) AS id | \ GO FROM $-.id OVER serve \ - WHERE $^.player.age > 20 \ - YIELD $^.player.name AS FriendOf, $$.team.name AS Team; + WHERE properties($^).age > 20 \ + YIELD properties($^).name AS FriendOf, properties($$).name AS Team; +---------------------+-----------------+ | FriendOf | Team | +---------------------+-----------------+ -| "Tony Parker" | "Spurs" | +| "Danny Green" | "Spurs" | +---------------------+-----------------+ -| "Tony Parker" | "Hornets" | +| "Danny Green" | "Cavaliers" | +---------------------+-----------------+ ... @@ -180,8 +177,8 @@ nebula> MATCH (v)<-[e:follow]- (v2)-[e2:serve]->(v3) \ ```ngql # 返回player102所有邻居点。 -nebula> GO FROM "player102" OVER follow BIDIRECT \ - YIELD follow._dst AS both; +nebula> GO FROM "player102" OVER follow \ + YIELD dst(edge) AS both; +-------------+ | both | +-------------+ @@ -208,7 +205,7 @@ nebula> MATCH (v) -[e:follow]-(v2) \ ```ngql # 查询player100 1~2跳内的朋友。 nebula> GO 1 TO 2 STEPS FROM "player100" OVER follow \ - YIELD follow._dst AS destination; + YIELD dst(edge) AS destination; +-------------+ | destination | +-------------+ @@ -234,9 +231,9 @@ nebula> MATCH (v) -[e:follow*1..2]->(v2) \ ```ngql # 根据年龄分组。 nebula> GO 2 STEPS FROM "player100" OVER follow \ - YIELD follow._src AS src, follow._dst AS dst, $$.player.age AS age \ + YIELD src(edge) AS src, dst(edge) AS dst, properties($$).age AS age \ | GROUP BY $-.dst \ - YIELD $-.dst AS dst, collect_set($-.src) AS src, collect($-.age) AS age + YIELD $-.dst AS dst, collect_set($-.src) AS src, collect($-.age) AS age; +-------------+----------------------------+----------+ | dst | src | age | +-------------+----------------------------+----------+ @@ -250,9 +247,9 @@ nebula> GO 2 STEPS FROM "player100" OVER follow \ ```ngql # 分组并限制输出结果的行数。 -nebula> $a = GO FROM "player100" OVER follow YIELD follow._src AS src, follow._dst AS dst; \ +nebula> $a = GO FROM "player100" OVER follow YIELD src(edge) AS src, dst(edge) AS dst; \ GO 2 STEPS FROM $a.dst OVER follow \ - YIELD $a.src AS src, $a.dst, follow._src, follow._dst \ + YIELD $a.src AS src, $a.dst, src(edge), dst(edge) \ | ORDER BY $-.src | OFFSET 1 LIMIT 2; +-------------+-------------+-------------+-------------+ | src | $a.dst | follow._src | follow._dst | @@ -265,7 +262,7 @@ nebula> $a = GO FROM "player100" OVER follow YIELD follow._src AS src, follow._d ```ngql # 在多个边上通过IS NOT EMPTY进行判断。 -nebula> GO FROM "player100" OVER * WHERE $$.player.name IS NOT EMPTY YIELD follow._dst; +nebula> GO FROM "player100" OVER follow WHERE properties($$).name IS NOT EMPTY YIELD dst(edge); +-------------+ | follow._dst | +-------------+ diff --git a/docs-2.0/3.ngql-guide/8.clauses-and-options/yield.md b/docs-2.0/3.ngql-guide/8.clauses-and-options/yield.md index 23fb43d7f1d..6f643e4a95d 100644 --- a/docs-2.0/3.ngql-guide/8.clauses-and-options/yield.md +++ b/docs-2.0/3.ngql-guide/8.clauses-and-options/yield.md @@ -24,7 +24,7 @@ !!! note 下文示例中的`$$`、`$-`等是引用符号,详情请参见[引用符](../5.operators/5.property-reference.md)。 - + ## YIELD子句 ### 语法 @@ -45,7 +45,7 @@ YIELD [DISTINCT] [AS ] [, [AS ] ...]; ```ngql nebula> GO FROM "player100" OVER follow \ - YIELD $$.player.name AS Friend, $$.player.age AS Age; + YIELD properties($$).name AS Friend, properties($$).age AS Age; +-----------------+-----+ | Friend | Age | +-----------------+-----+ @@ -72,11 +72,11 @@ YIELD [DISTINCT] [AS ] [, [AS ] ...]; ```ngql nebula> LOOKUP ON player WHERE player.name == "Tony Parker" \ YIELD player.name, player.age; - ======================================= - | VertexID | player.name | player.age | - ======================================= - | 101 | Tony Parker | 36 | - --------------------------------------- + +-------------+---------------+------------+ + | VertexID | player.name | player.age | + +-------------+---------------+------------+ + | "player101" | "Tony Parker" | 36 | + +-------------+---------------+------------+ ``` ## YIELD语句 @@ -102,7 +102,7 @@ YIELD [DISTINCT] [AS ] [, [AS ] ...] ```ngql # 查找player100关注的player,并计算他们的平均年龄。 nebula> GO FROM "player100" OVER follow \ - YIELD follow._dst AS ID \ + YIELD dst(edge) AS ID \ | FETCH PROP ON player $-.ID \ YIELD player.age AS Age \ | YIELD AVG($-.Age) as Avg_age, count(*)as Num_friends; @@ -116,7 +116,7 @@ nebula> GO FROM "player100" OVER follow \ ```ngql # 查找player101关注的player,返回degree大于90的player。 nebula> $var1 = GO FROM "player101" OVER follow \ - YIELD follow.degree AS Degree, follow._dst as ID; \ + YIELD properties(edge).degree AS Degree, dst(edge) as ID; \ YIELD $var1.ID AS ID WHERE $var1.Degree > 90; +-------------+ | ID |