跳转至

GET SUBGRAPHGraph

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

语法Graph

GET SUBGRAPH [<step_count> STEPS] FROM {<vid>, <vid>...}
[IN <edge_type>, <edge_type>...]
[OUT <edge_type>, <edge_type>...]
[BOTH <edge_type>, <edge_type>...];
  • step_count:指定从起始点开始的跳数,返回从0到step_count跳的子图。必须是非负整数。默认值为1。
  • vid:指定起始点ID。
  • edge_type:指定边类型。可以用INOUTBOTH来指定起始点上该边类型的方向。默认为BOTH

示例Graph

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

A sample graph for GET SUBGRAPH

  • 查询从点player100开始、0~1跳、所有边类型的子图。
    nebula> GET SUBGRAPH 1 STEPS FROM "player100";
    +--------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
    | _vertices                                                                                                                | _edges                                                                                                                                           |
    +--------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
    | [(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] |
    +--------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
    | [(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]                                                                                      |
    +--------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
    

    返回的子图如下。

    GET SUBGRAPH FROM "player100"

  • 查询从点player100开始、0~1跳、follow类型的入边的子图。
    nebula> GET SUBGRAPH 1 STEPS FROM "player100" IN follow;
    +-----------+--------+
    | _vertices | _edges |
    +-----------+--------+
    | []        | []     |
    +-----------+--------+
    | []        | []     |
    +-----------+--------+
    

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

  • 查询从点player100开始、0~1跳、serve类型的出边的子图。
    nebula> GET SUBGRAPH 1 STEPS FROM "player100" OUT serve;
    +---------------------------------------------+--------------------------------------------------------------+
    | _vertices                                   | _edges                                                       |
    +---------------------------------------------+--------------------------------------------------------------+
    | [(player100) player.age:42,player.name:Tim] | [player100-[serve]->team200@0 start_year:1997,end_year:2016] |
    +---------------------------------------------+--------------------------------------------------------------+
    | [(team200) team.name:Warriors]              | []                                                           |
    +---------------------------------------------+--------------------------------------------------------------+
    

    返回的子图如下。

    GET SUBGRAPH FROM "100" OUT serve


最后更新: 2021年4月15日
Back to top