概述
使用语句find().edges()
可以从当前图集获取符合过滤条件的边。
语法
find().edges(<filter?>)
- 语句别名:类型为
EDGE
;默认名称为edges
- 方法:
方法 |
参数 |
描述 | 别名类型 |
---|---|---|---|
edges() |
<filter?> |
将过滤条件包裹在{} 中,或使用别名指定待获取的边。留空时会作用在所有边上 |
N/A |
示例图集
在一个空图集中,逐行运行以下语句,创建示例图集:
create().node_schema("User").node_schema("Club").edge_schema("Follows").edge_schema("Joins")
create().node_property(@User, "name").node_property(@Club, "name").edge_property(@Follows, "time", datetime).edge_property(@Joins, "memberNo", uint32).edge_property(@Joins, "time", datetime)
insert().into(@User).nodes([{_id:"U01", name:"Rowlock"},{_id:"U02", name:"Brainy"},{_id:"U03", name:"purplechalk"},{_id:"U04", name:"mochaeach"},{_id:"U05", name:"lionbower"}])
insert().into(@Club).nodes([{_id:"C01", name:"Rowlock Tennis"},{_id:"C02", name:"Super Yacht"}])
insert().into(@Follows).edges([{_from:"U01", _to:"U02", time:"2024-1-5"},{_from:"U02", _to:"U03", time:"2024-2-1"},{_from:"U04", _to:"U02", time:"2024-2-10"},{_from:"U03", _to:"U05", time:"2024-5-3"}])
insert().into(@Joins).edges([{_from:"U02", _to:"C01", memberNo:1, time:"2023-12-14"},{_from:"U05", _to:"C01", memberNo:2, time:"2024-2-25"},{_from:"U04", _to:"C02", memberNo:9, time:"2024-6-15"}])
找所有边
获取所有边:
find().edges() as e
return e{*}
结果:e
_uuid |
_from |
_to |
_from_uuid |
_to_uuid |
schema |
values |
---|---|---|---|---|---|---|
Sys-gen | U01 | U02 | UUID of U01 | UUID of U02 | Follows | {time: "2024-01-05 00:00:00" } |
Sys-gen | U02 | U03 | UUID of U02 | UUID of U03 | Follows | {time: "2024-02-01 00:00:00"} |
Sys-gen | U03 | U05 | UUID of U03 | UUID of U05 | Follows | {time: "2024-05-03 00:00:00"} |
Sys-gen | U04 | U02 | UUID of U04 | UUID of U02 | Follows | {time: "2024-02-10 00:00:00"} |
Sys-gen | U02 | C01 | UUID of U02 | UUID of C01 | Joins | {memberNo: 1, time: "2023-12-14 00:00:00"} |
Sys-gen | U05 | C01 | UUID of U05 | UUID of C01 | Joins | {memberNo: 2, time: "2024-02-25 00:00:00"} |
Sys-gen | U04 | C02 | UUID of U04 | UUID of C02 | Joins | {memberNo: 9, time: "2024-06-15 00:00:00"} |
根据schema找边
获取schema为Joins
的边:
find().edges({@Joins}) as e
return e{*}
结果:e
_uuid |
_from |
_to |
_from_uuid |
_to_uuid |
schema |
values |
---|---|---|---|---|---|---|
Sys-gen | U02 | C01 | UUID of U02 | UUID of C01 | Joins | {memberNo: 1, time: "2023-12-14 00:00:00"} |
Sys-gen | U05 | C01 | UUID of U05 | UUID of C01 | Joins | {memberNo: 2, time: "2024-02-25 00:00:00"} |
Sys-gen | U04 | C02 | UUID of U04 | UUID of C02 | Joins | {memberNo: 9, time: "2024-06-15 00:00:00"} |
获取schema为Joins
或Follows
的边:
find().edges({@Joins || @Follows}) as e
return e{*}
结果:e
_uuid |
_from |
_to |
_from_uuid |
_to_uuid |
schema |
values |
---|---|---|---|---|---|---|
Sys-gen | U01 | U02 | UUID of U01 | UUID of U02 | Follows | {time: "2024-01-05 00:00:00" } |
Sys-gen | U02 | U03 | UUID of U02 | UUID of U03 | Follows | {time: "2024-02-01 00:00:00"} |
Sys-gen | U03 | U05 | UUID of U03 | UUID of U05 | Follows | {time: "2024-05-03 00:00:00"} |
Sys-gen | U04 | U02 | UUID of U04 | UUID of U02 | Follows | {time: "2024-02-10 00:00:00"} |
Sys-gen | U02 | C01 | UUID of U02 | UUID of C01 | Joins | {memberNo: 1, time: "2023-12-14 00:00:00"} |
Sys-gen | U05 | C01 | UUID of U05 | UUID of C01 | Joins | {memberNo: 2, time: "2024-02-25 00:00:00"} |
Sys-gen | U04 | C02 | UUID of U04 | UUID of C02 | Joins | {memberNo: 9, time: "2024-06-15 00:00:00"} |
根据属性找边
在过滤条件中,属性可与schema共同使用,也可独立使用。独立使用时,适用于所有具备该属性的边,而不论其schema。特别注意,系统属性_uuid
、_from
、_to
、_from_uuid
和_to_uuid
无法与schema共同使用(如@Joins._uuid
)。
获取@Joins
下memberNo
属性为2的边:
find().edges({@Joins.memberNo == 2}) as e
return e.time
结果:
e.time |
---|
2024-02-25 00:00:00 |
获取time
大于2024-5-1的边:
find().edges({time > "2024-5-1"}) as e
return e{*}
结果:e
_uuid |
_from |
_to |
_from_uuid |
_to_uuid |
schema |
values |
---|---|---|---|---|---|---|
Sys-gen | U03 | U05 | UUID of U03 | UUID of U05 | Follows | {time: "2024-05-03 00:00:00"} |
Sys-gen | U04 | C02 | UUID of U04 | UUID of C02 | Joins | {memberNo: 9, time: "2024-06-15 00:00:00"} |
获取_from
为U01或U04的边:
find().edges({_from in ["U01", "U04"]}) as e
return e{*}
结果:e
_uuid |
_from |
_to |
_from_uuid |
_to_uuid |
schema |
values |
---|---|---|---|---|---|---|
Sys-gen | U01 | U02 | UUID of U01 | UUID of U02 | Follows | {createdOn: "2024-01-05 00:00:00" } |
Sys-gen | U04 | U02 | UUID of U04 | UUID of U02 | Follows | {createdOn: "2024-02-10 00:00:00"} |
Sys-gen | U04 | C02 | UUID of U04 | UUID of C02 | Joins | {memberNo: 9} |
使用默认别名
在find().edges()
语句中,可以使用默认别名edges
,,无需显式声明。
获取所有边并返回其time
(同时默认返回schema和系统属性):
find().edges()
return edges{time}
结果:edges
_uuid |
_from |
_to |
_from_uuid |
_to_uuid |
schema |
time |
---|---|---|---|---|---|---|
Sys-gen | U01 | U02 | UUID of U01 | UUID of U02 | Follows | 2024-01-05 00:00:00 |
Sys-gen | U02 | U03 | UUID of U02 | UUID of U03 | Follows | 2024-02-01 00:00:00 |
Sys-gen | U03 | U05 | UUID of U03 | UUID of U05 | Follows | 2024-05-03 00:00:00 |
Sys-gen | U04 | U02 | UUID of U04 | UUID of U02 | Follows | 2024-02-10 00:00:00 |
Sys-gen | U02 | C01 | UUID of U02 | UUID of C01 | Joins | 2023-12-14 00:00:00 |
Sys-gen | U05 | C01 | UUID of U05 | UUID of C01 | Joins | 2024-02-25 00:00:00 |
Sys-gen | U04 | C02 | UUID of U04 | UUID of C02 | Joins | 2024-06-15 00:00:00 |
限制边数量
紧跟在find().edges()
语句之后使用LIMIT
语句,可以限制传递给后续语句的边数。
获取任意3个@Follows
边:
find().edges({@Follows}) as e limit 3
return e.time
结果:
e.time |
---|
2024-02-10 00:00:00 |
2024-02-01 00:00:00 |
2024-01-05 00:00:00 |
使用前缀OPTIONAL
在此查询中,find().edges()
语句会执行三次,每次使用num
中的一条记录。使用前缀OPTIONAL
后,如果执行过程中未找到结果,查询将返回null
:
uncollect [1,2,3] as num
optional find().edges({memberNo == num}) as e
return e.time
结果:
e.time |
---|
2023-12-14 00:00:00 |
2024-02-25 00:00:00 |
null |
如果不使用前缀OPTIONAL
,只会返回两条记录:
uncollect [1,2,3] as num
find().edges({memberNo == num}) as e
return e.time
结果:
e.time |
---|
2023-12-14 00:00:00 |
2024-02-25 00:00:00 |