GET SUBGRAPH

    • WITH PROP:展示属性。不添加本参数则隐藏属性。

    • step_count:指定从起始点开始的跳数,返回从0到step_count跳的子图。必须是非负整数。默认值为1。

    • vid:指定起始点ID。

    • edge_type:指定Edge type。可以用INOUTBOTH来指定起始点上该Edge type的方向。默认为BOTH

    以下面的示例图进行演示。

      1. nebula> GET SUBGRAPH 1 STEPS FROM "player100";
      2. +-------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------+
      3. +-------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------+
      4. | [("player100" :player{})] | [[:serve "player100"->"team200" @0 {}], [:follow "player100"->"player101" @0 {}], [:follow "player100"->"player102" @0 {}]] |
      5. | [("team200" :team{}), ("player101" :player{}), ("player102" :player{})] | [[:follow "player102"->"player101" @0 {}]] |
      6. +-------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------+

      返回的子图如下。

      GET SUBGRAPH FROM "player100"

    • 查询从点player100开始、0~1跳、follow类型的入边的子图。

      因为player100没有follow类型的入边。所以仅返回点player100

    • 查询从点player100开始、0~1跳、serve类型的出边的子图,同时展示边的属性。

      1. nebula> GET SUBGRAPH WITH PROP 1 STEPS FROM "player100" OUT serve;
      2. +------------------------------------------------------+-------------------------------------------------------------------------+
      3. | _vertices | _edges |
      4. +------------------------------------------------------+-------------------------------------------------------------------------+
      5. | [("player100" :player{age: 42, name: "Tim Duncan"})] | [[:serve "player100"->"team200" @0 {end_year: 2016, start_year: 1997}]] |
      6. | [("team200" :team{name: "Warriors"})] | [] |
      7. +------------------------------------------------------+-------------------------------------------------------------------------+

      返回的子图如下。

    为了展示子图的完整性,会在满足条件的所有点上额外查询一跳。例如下图。

    • GET SUBGRAPH 1 STEPS FROM "A";查询的满足结果的路径是A->BB->AA->C,为了子图的完整性,会在满足结果的点上额外查询一跳,即B->C

    • GET SUBGRAPH 1 STEPS FROM "A" IN follow;查询的满足结果的路径是B->A,在满足结果的点上额外查询一跳,即A->B

    如果只是查询满足条件的路径或点,建议使用MATCH或语句。例如:

    为什么返回结果中会出现低于step_count跳数的关系?

    查询到没有多余子图数据时会停止查询,且不会返回空值。

    1. nebula> GET SUBGRAPH 100 STEPS FROM "player141" OUT follow;
    2. +-------------------------------------------------------+--------------------------------------------+
    3. | _vertices | _edges |
    4. +-------------------------------------------------------+--------------------------------------------+
    5. | [("player141" :player{age: 43, name: "Ray Allen"})] | [[:follow "player141"->"player124" @0 {}]] |
    6. +-------------------------------------------------------+--------------------------------------------+
    7. | [("player124" :player{age: 33, name: "Rajon Rondo"})] | [[:follow "player124"->"player141" @0 {}]] |
    8. +-------------------------------------------------------+--------------------------------------------+