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
:指定边类型。可以用IN
、OUT
和BOTH
来指定起始点上该边类型的方向。默认为BOTH
。
示例Graph
以下面的示例图进行演示。
- 查询从点
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] | +--------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
返回的子图如下。
- 查询从点
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] | [] | +---------------------------------------------+--------------------------------------------------------------+
返回的子图如下。
最后更新: April 15, 2021