GO

    本文操作仅适用于原生nGQL。

    • <N> STEPS:指定跳数。如果没有指定跳数,默认值N1。如果N0,Nebula Graph不会检索任何边。

    • M TO N STEPS:遍历M~N跳的边。如果M0,输出结果和M1相同,即GO 0 TO 2GO 1 TO 2是相同的。

    • <edge_type_list>:遍历的Edge type列表。

    • REVERSELY | BIDIRECT:默认情况下检索的是<vertex_list>的出边(正向),REVERSELY表示反向,即检索入边;BIDIRECT 为双向,即检索正向和反向,通过返回 <edge_type>._type 字段判断方向,其正数为正向,负数为反向。

    • WHERE <conditions>:指定遍历的过滤条件。用户可以在起始点、目的点和边使用WHERE子句,还可以结合ANDORNOTXOR一起使用。详情请参见WHERE

    • ORDER BY:指定输出结果的排序规则。详情请参见。

    • LIMIT:限制输出结果的行数。详情请参见LIMIT

    • GROUP BY:根据指定属性的值将输出分组。详情请参见。

    1. # 返回player102所属队伍。
    2. nebula> GO FROM "player102" OVER serve;
    3. +------------+
    4. | serve._dst |
    5. +------------+
    6. | "team203" |
    7. +------------+
    8. | "team204" |
    9. +------------+
    1. # 返回距离player102两跳的朋友。
    2. nebula> GO 2 STEPS FROM "player102" OVER follow;
    3. +-------------+
    4. | follow._dst |
    5. +-------------+
    6. | "player101" |
    7. +-------------+
    8. | "player125" |
    9. +-------------+
    10. ...
    1. # 添加过滤条件。
    2. nebula> GO FROM "player100", "player102" OVER serve \
    3. WHERE serve.start_year > 1995 \
    4. YIELD DISTINCT $$.team.name AS team_name, serve.start_year AS start_year, $^.player.name AS player_name;
    5. +-----------------+------------+---------------------+
    6. | team_name | start_year | player_name |
    7. | "Spurs" | 1997 | "Tim Duncan" |
    8. +-----------------+------------+---------------------+
    9. | "Trail Blazers" | 2006 | "LaMarcus Aldridge" |
    10. +-----------------+------------+---------------------+
    11. | "Spurs" | 2015 | "LaMarcus Aldridge" |
    12. +-----------------+------------+---------------------+
    1. # 返回player100的入边。
    2. nebula> GO FROM "player100" OVER follow REVERSELY \
    3. YIELD follow._dst AS destination;
    4. +-------------+
    5. | destination |
    6. | "player101" |
    7. +-------------+
    8. | "player102" |
    9. +-------------+
    10. ...
    11. # 该MATCH查询与上一个GO查询具有相同的语义。
    12. nebula> MATCH (v)<-[e:follow]- (v2) WHERE id(v) == 'player100' \
    13. RETURN id(v2) AS destination;
    14. +-------------+
    15. | destination |
    16. +-------------+
    17. | "player101" |
    18. +-------------+
    19. | "player102" |
    20. +-------------+
    21. ...
    1. # 查询player100的朋友和朋友所属队伍。
    2. nebula> GO FROM "player100" OVER follow REVERSELY \
    3. YIELD follow._dst AS id | \
    4. GO FROM $-.id OVER serve \
    5. WHERE $^.player.age > 20 \
    6. YIELD $^.player.name AS FriendOf, $$.team.name AS Team;
    7. +---------------------+-----------------+
    8. | FriendOf | Team |
    9. +---------------------+-----------------+
    10. | "Tony Parker" | "Spurs" |
    11. +---------------------+-----------------+
    12. | "Tony Parker" | "Hornets" |
    13. +---------------------+-----------------+
    14. ...
    15. # 该MATCH查询与上一个GO查询具有相同的语义。
    16. nebula> MATCH (v)<-[e:follow]- (v2)-[e2:serve]->(v3) \
    17. WHERE id(v) == 'player100' \
    18. RETURN v2.name AS FriendOf, v3.name AS Team;
    19. +---------------------+-----------------+
    20. | FriendOf | Team |
    21. +---------------------+-----------------+
    22. | "Tony Parker" | "Spurs" |
    23. +---------------------+-----------------+
    24. | "Tony Parker" | "Hornets" |
    25. +---------------------+-----------------+
    26. ...
    1. nebula> GO FROM "player102" OVER follow BIDIRECT \
    2. YIELD follow._dst AS both;
    3. +-------------+
    4. | both |
    5. +-------------+
    6. +-------------+
    7. | "player101" |
    8. +-------------+
    9. ...
    10. # 该MATCH查询与上一个GO查询具有相同的语义。
    11. nebula> MATCH (v) -[e:follow]-(v2) \
    12. WHERE id(v)== "player102" \
    13. RETURN id(v2) AS both;
    14. +-------------+
    15. | both |
    16. +-------------+
    17. | "player101" |
    18. +-------------+
    19. | "player103" |
    20. +-------------+
    21. ...
    1. # 根据年龄分组。
    2. nebula> GO 2 STEPS FROM "player100" OVER follow \
    3. YIELD follow._src AS src, follow._dst AS dst, $$.player.age AS age \
    4. | GROUP BY $-.dst \
    5. YIELD $-.dst AS dst, collect_set($-.src) AS src, collect($-.age) AS age
    6. +-------------+----------------------------+----------+
    7. | dst | src | age |
    8. +-------------+----------------------------+----------+
    9. | "player125" | ["player101"] | [41] |
    10. +-------------+----------------------------+----------+
    11. | "player100" | ["player125", "player101"] | [42, 42] |
    12. +-------------+----------------------------+----------+
    13. | "player102" | ["player101"] | [33] |
    14. +-------------+----------------------------+----------+
    1. # 分组并限制输出结果的行数。
    2. nebula> $a = GO FROM "player100" OVER follow YIELD follow._src AS src, follow._dst AS dst; \
    3. GO 2 STEPS FROM $a.dst OVER follow \
    4. YIELD $a.src AS src, $a.dst, follow._src, follow._dst \
    5. | ORDER BY $-.src | OFFSET 1 LIMIT 2;
    6. +-------------+-------------+-------------+-------------+
    7. | src | $a.dst | follow._src | follow._dst |
    8. +-------------+-------------+-------------+-------------+
    9. | "player100" | "player125" | "player100" | "player101" |
    10. +-------------+-------------+-------------+-------------+
    11. | "player100" | "player101" | "player100" | "player125" |
    12. +-------------+-------------+-------------+-------------+
    1. # 在多个边上通过IS NOT EMPTY进行判断。
    2. nebula> GO FROM "player100" OVER * WHERE $$.player.name IS NOT EMPTY YIELD follow._dst;
    3. +-------------+
    4. | follow._dst |
    5. +-------------+
    6. | "player125" |
    7. +-------------+
    8. +-------------+