GET SUBGRAPH

GET SUBGRAPH语句检索指定边类型的起始点可以到达的点和边的信息,返回子图信息。

语法

  1. GET SUBGRAPH [<step_count> STEPS] FROM {<vid>, <vid>...}
  2. [IN <edge_type>, <edge_type>...]
  3. [OUT <edge_type>, <edge_type>...]
  4. [BOTH <edge_type>, <edge_type>...];
  • step_count:指定从起始点开始的跳数,返回从0到step_count跳的子图。必须是非负整数。默认值为1。

  • vid:指定起始点ID。

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

示例

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

A sample graph for GET SUBGRAPH

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

    1. nebula> GET SUBGRAPH 1 STEPS FROM "player100";
    2. +--------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
    3. | _vertices | _edges |
    4. +--------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
    5. | [(player100) player.name:Tim,player.age:42] | [player100-[follow]->player101@0 degree:96,player100-[follow]->player102@0 degree:90,player100-[serve]->team200@0 end_year:2016,start_year:1997] |
    6. +--------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
    7. | [(player101) player.age:36,player.name:Tony Parker,(player102) player.age:33,player.name:LaMarcus Aldridge,(team200) team.name:Warriors] | [player102-[follow]->player101@0 degree:75] |
    8. +--------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+

    返回的子图如下。

    GET SUBGRAPH FROM "player100"

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

    1. nebula> GET SUBGRAPH 1 STEPS FROM "player100" IN follow;
    2. +-----------+--------+
    3. | _vertices | _edges |
    4. +-----------+--------+
    5. | [] | [] |
    6. +-----------+--------+
    7. | [] | [] |
    8. +-----------+--------+

    因为player100没有follow类型的入边。所以返回的子图为空。

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

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

    返回的子图如下。

    GET SUBGRAPH FROM "100" OUT serve