Skip to content

GET SUBGRAPH

The GET SUBGRAPH statement retrieves information of vertices and edges reachable from the start vertices over the specified types of edges.

Syntax

GET SUBGRAPH [<step_count> STEPS] FROM {<vid>, <vid>...}
[IN <edge_type>, <edge_type>...]
[OUT <edge_type>, <edge_type>...]
[BOTH <edge_type>, <edge_type>...]
Clause Description
STEPS Specifies the steps to go from the start vertices. A step_count must be a non-negative integer. Its default value is 1. When <step_count> is specified to N, the Nebula Graph returns zero to N steps subgraph.
FROM Specifies the start vertices.
IN Gets the subgraphs from the start vertices over the specified incoming edges (edges pointing to the start vertices).
OUT Gets the subgraphs from the start vertices over the specified outgoing edges (edges pointing out from the start vertices).
BOTH Gets the subgraphs from the start vertices over the specified types of edges, both incoming and outgoing.

When the traversal direction is not specified, both the incoming and outgoing edges are returned.

Examples

The following graph is used as the sample.

A sample graph for GET SUBGRAPH

  • Go one step from the vertex with VID "player100" over all types of edges and get the subgraph.
    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]                                                                                      |
    +--------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
    Got 2 rows (time spent 6289/7423 us)
    

    The returned subgraph is as follows.

GET SUBGRAPH FROM "player100"

  • Go one step from the vertex with VID "player100" over incoming follow edges and get the subgraph.
    nebula> GET SUBGRAPH 1 STEPS FROM "player100" IN follow;
    +-----------+--------+
    | _vertices | _edges |
    +-----------+--------+
    | []        | []     |
    +-----------+--------+
    | []        | []     |
    +-----------+--------+
    Got 2 rows (time spent 2292/3091 us)
    

    There is no incoming follow edge to "player100", so no vertex or edge is returned.

  • Go one step from the vertex "player100" over outgoing serve edges and get the subgraph.
    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]              | []                                                           |
    +---------------------------------------------+--------------------------------------------------------------+
    Got 2 rows (time spent 2107/2547 us)
    

    The returned subgraph is as follows.

GET SUBGRAPH FROM "100" OUT serve


Last update: April 15, 2021
Back to top