概述
找边子句find().edges()
从图集中获取符合过滤条件的边。
语法
字句别名: 数据类型为EDGE;默认别名为edges
方法 |
参数类型 |
参数规范 |
必须 |
描述 | 别名 |
---|---|---|---|---|---|
edges() |
Filter | / | 是 | 用来获取指定边的过滤条件 | N/A |
limit() |
Integer | ≥-1 | 否 | 每个子查询返回的结果数,-1 表示返回所有 |
N/A |
示例
示例图集
![](https://img.ultipa.cn/draw/draw_aa36dc7bd3dc4b74b15f4b47eb76292a.jpg?v='1716968983671')
在一个空图集中,逐行运行以下语句,创建示例图集:
create().node_schema("professor").node_schema("student").edge_schema("mentor").edge_schema("assist")
create().node_property(@*, "age", int32).node_property(@*, "email", string).edge_property(@*, "year", int32)
insert().into(@professor).nodes([{_id:"P001",_uuid:1,age:53,email:"test@yahoo.cn"},{_id:"P002",_uuid:2,age:27,email:"test@ultipa.com"}])
insert().into(@student).nodes([{_id:"S001",_uuid:3,age:27,email:"test@yeah.net"},{_id:"S002",_uuid:4,age:20,email:"test@w3.org"},{_id:"S003",_uuid:5,age:25,email:"test@gmail.com"}])
insert().into(@mentor).edges([{_uuid:1, _from_uuid:2, _to_uuid:3, year:2020},{_uuid:2, _from_uuid:1, _to_uuid:3, year:2021},{_uuid:3, _from_uuid:1, _to_uuid:4, year:2021},{_uuid:4, _from_uuid:1, _to_uuid:5, year:2022}])
insert().into(@assist).edges([{_uuid:5, _from_uuid:3, _to_uuid:2, year:2020},{_uuid:6, _from_uuid:4, _to_uuid:1, year:2022}])
无过滤条件
find().edges() as e
return e{*}
结果:
_uuid | _from | _to | _from_uuid |
_to_uuid | Schema | year |
---|---|---|---|---|---|---|
1 | P002 | S001 | 2 | 3 | mentor | 2020 |
2 | P001 | S001 | 1 | 3 | mentor | 2021 |
3 | P001 | S002 | 1 | 4 | mentor | 2021 |
4 | P001 | S003 | 1 | 5 | mentor | 2022 |
_uuid | _from | _to | _from_uuid |
_to_uuid | Schema | year |
---|---|---|---|---|---|---|
5 | S001 | P002 | 3 | 2 | assist | 2020 |
6 | S002 | P001 | 4 | 1 | assist | 2022 |
过滤UUID
find().edges(1) as e
return e{*}
过滤条件
{_uuid == 1}
可简写为1
。
结果:
_uuid | _from | _to | _from_uuid |
_to_uuid | Schema | year |
---|---|---|---|---|---|---|
1 | P002 | S001 | 2 | 3 | mentor | 2020 |
find().edges([1,3]) as e
return e{*}
过滤条件
{_uuid in [1,3]}
可简写为[1,3]
。
结果:
_uuid | _from | _to | _from_uuid |
_to_uuid | Schema | year |
---|---|---|---|---|---|---|
1 | P002 | S001 | 2 | 3 | mentor | 2020 |
3 | P001 | S002 | 1 | 4 | mentor | 2021 |
过滤起点
find().edges({_from == "P001"}) as e
return e{*}
结果:
_uuid | _from | _to | _from_uuid |
_to_uuid | Schema | year |
---|---|---|---|---|---|---|
2 | P001 | S001 | 1 | 3 | mentor | 2021 |
3 | P001 | S002 | 1 | 4 | mentor | 2021 |
4 | P001 | S003 | 1 | 5 | mentor | 2022 |
过滤终点
find().edges({_to == "P001"}) as e
return e{*}
结果:
_uuid | _from | _to | _from_uuid |
_to_uuid | Schema | year |
---|---|---|---|---|---|---|
6 | S002 | P001 | 4 | 1 | assist | 2022 |
过滤Schema
find().edges({@assist}) as e
return e{*}
结果:
_uuid | _from | _to | _from_uuid |
_to_uuid | Schema | year |
---|---|---|---|---|---|---|
5 | S001 | P002 | 3 | 2 | assist | 2020 |
6 | S002 | P001 | 4 | 1 | assist | 2022 |
find().edges({@assist || @mentor}) as e
return e{*}
结果:
_uuid | _from | _to | _from_uuid |
_to_uuid | Schema | year |
---|---|---|---|---|---|---|
1 | P002 | S001 | 2 | 3 | mentor | 2020 |
2 | P001 | S001 | 1 | 3 | mentor | 2021 |
3 | P001 | S002 | 1 | 4 | mentor | 2021 |
4 | P001 | S003 | 1 | 5 | mentor | 2022 |
_uuid | _from | _to | _from_uuid |
_to_uuid | Schema | year |
---|---|---|---|---|---|---|
5 | S001 | P002 | 3 | 2 | assist | 2020 |
6 | S002 | P001 | 4 | 1 | assist | 2022 |
过滤属性值
find().edges({year == 2020}) as e
return e{*}
结果:
_uuid | _from | _to | _from_uuid |
_to_uuid | Schema | year |
---|---|---|---|---|---|---|
1 | P002 | S001 | 2 | 3 | mentor | 2020 |
_uuid | _from | _to | _from_uuid |
_to_uuid | Schema | year |
---|---|---|---|---|---|---|
5 | S001 | P002 | 3 | 2 | assist | 2020 |
过滤Schema和属性值
find().edges({@assist.year == 2020}) as e
return e{*}
结果:
_uuid | _from | _to | _from_uuid |
_to_uuid | Schema | year |
---|---|---|---|---|---|---|
5 | S001 | P002 | 3 | 2 | assist | 2020 |
使用默认子句别名
find().edges().limit(3)
return edges{*}
结果:
_uuid | _from | _to | _from_uuid |
_to_uuid | Schema | year |
---|---|---|---|---|---|---|
1 | P002 | S001 | 2 | 3 | mentor | 2020 |
2 | P001 | S001 | 1 | 3 | mentor | 2021 |
3 | P001 | S002 | 1 | 4 | mentor | 2021 |
限制查询数量
find().edges().limit(3) as e
return e{*}
结果:
_uuid | _from | _to | _from_uuid |
_to_uuid | Schema | year |
---|---|---|---|---|---|---|
1 | P002 | S001 | 2 | 3 | mentor | 2020 |
2 | P001 | S001 | 1 | 3 | mentor | 2021 |
3 | P001 | S002 | 1 | 4 | mentor | 2021 |
使用前缀OPTIONAL
uncollect [2022, 2023, 2024] as value
optional find().edges({year == value}) as e
return e{*}
结果:
_uuid | _from | _to | _from_uuid |
_to_uuid | Schema | year |
---|---|---|---|---|---|---|
4 | P001 | S003 | 1 | 5 | mentor | 2022 |
_uuid | _from | _to | _from_uuid |
_to_uuid | Schema | year |
---|---|---|---|---|---|---|
6 | S002 | P001 | 4 | 1 | assist | 2022 |
_uuid | _from | _to | _from_uuid |
_to_uuid | Schema |
---|---|---|---|---|---|
null | null | null | null | null | null |
null | null | null | null | null | null |
如果没有使用前缀OPTIONAL
,查询无结果时无返回值。