语句 find().edges()
可以对边进行过滤,并返回满足条件的边。类似于传统数据库中的表查询操作。
语法:
- 语句别名:支持,结构为 EDGE
- 支持前缀 OPTIONAL,子查询无结果时返回
null
- 可选参数:
参数 | 类型 | 规范 | 描述 | 参数别名类型 |
---|---|---|---|---|
limit() |
int | -1 或 >=0 | 子查询返回结果的条数,-1 表示返回所有结果 | 不支持 |
未定义语句别名时系统将定义 edges 为语句别名,此时不能在后面的语句中再次使用 edges 为其它数据定义别名,否则会引发重名报错。
示例图集:(以下示例将在本图基础上运行)
在空图集中依次运行以下各行代码以创建该图数据: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{*}
|---------------------- @mentor ----------------------|
| _uuid | _from | _to | _from_uuid | _to_uuid | year |
|-------|-------|------|------------|----------|------|
| 1 | P002 | S001 | 2 | 3 | 2020 |
| 2 | P001 | S001 | 1 | 3 | 2021 |
| 3 | P001 | S002 | 1 | 4 | 2021 |
| 4 | P001 | S003 | 1 | 5 | 2022 |
|---------------------- @assist ----------------------|
| _uuid | _from | _to | _from_uuid | _to_uuid | year |
|-------|-------|------|------------|----------|------|
| 5 | S001 | P002 | 3 | 2 | 2020 |
| 6 | S002 | P001 | 4 | 1 | 2022 |
过滤 ID
示例:查询 _uuid
为 1、3 的边,携带全部属性值
find().edges([1,3]) as e
return e{*}
|---------------------- @mentor ----------------------|
| _uuid | _from | _to | _from_uuid | _to_uuid | year |
|-------|-------|------|------------|----------|------|
| 1 | P002 | S001 | 2 | 3 | 2020 |
| 3 | P001 | S002 | 1 | 4 | 2021 |
过滤 FROM/TO
示例:查询以 P001 为起点的边,携带全部属性值
find().edges({_from == "P001"}) as e
return e{*}
|---------------------- @mentor ----------------------|
| _uuid | _from | _to | _from_uuid | _to_uuid | year |
|-------|-------|------|------------|----------|------|
| 2 | P001 | S001 | 1 | 3 | 2021 |
| 3 | P001 | S002 | 1 | 4 | 2021 |
| 4 | P001 | S003 | 1 | 5 | 2022 |
示例:查询以 P001 为终点的边,携带全部属性值
find().edges({_to == "P001"}) as e
return e{*}
|---------------------- @assist ----------------------|
| _uuid | _from | _to | _from_uuid | _to_uuid | year |
|-------|-------|------|------------|----------|------|
| 6 | S002 | P001 | 4 | 1 | 2022 |
过滤 Schema
示例:查询 @assist 边,携带全部属性值
find().edges({@assist}) as e
return e{*}
|---------------------- @assist ----------------------|
| _uuid | _from | _to | _from_uuid | _to_uuid | year |
|-------|-------|------|------------|----------|------|
| 5 | S001 | P002 | 3 | 2 | 2020 |
| 6 | S002 | P001 | 4 | 1 | 2022 |
过滤属性值
示例:查询 year 等于 2020 的边,携带全部属性值
find().edges({year == 2020}) as e
return e{*}
|---------------------- @mentor ----------------------|
| _uuid | _from | _to | _from_uuid | _to_uuid | year |
|-------|-------|------|------------|----------|------|
| 1 | P002 | S001 | 2 | 3 | 2020 |
|---------------------- @assist ----------------------|
| _uuid | _from | _to | _from_uuid | _to_uuid | year |
|-------|-------|------|------------|----------|------|
| 5 | S001 | P002 | 3 | 2 | 2020 |
过滤 Schema、属性值
示例:查询 year 等于 2020 的 @assist 边,携带全部属性值
find().edges({@assist.year == 2020}) as e
return e{*}
|---------------------- @assist ----------------------|
| _uuid | _from | _to | _from_uuid | _to_uuid | year |
|-------|-------|------|------------|----------|------|
| 5 | S001 | P002 | 3 | 2 | 2020 |
limit()
示例:查询 3 条边,携带全部属性值
find().edges().limit(3) as e
return e{*}
|---------------------- @mentor ----------------------|
| _uuid | _from | _to | _from_uuid | _to_uuid | year |
|-------|-------|------|------------|----------|------|
| 1 | P002 | S001 | 2 | 3 | 2020 |
| 2 | P001 | S001 | 1 | 3 | 2021 |
| 3 | P001 | S002 | 1 | 4 | 2021 |
使用默认的语句别名
示例:查询 3 条边,携带全部属性值
find().edges().limit(3)
return edges{*}
|---------------------- @mentor ----------------------|
| _uuid | _from | _to | _from_uuid | _to_uuid | year |
|-------|-------|------|------------|----------|------|
| 1 | P002 | S001 | 2 | 3 | 2020 |
| 2 | P001 | S001 | 1 | 3 | 2021 |
| 3 | P001 | S002 | 1 | 4 | 2021 |
使用 OPTIONAL
示例:查询以 S003 为起点的边,携带全部属性值;如无结果则返回 null
optional find().edges({_from == "S003"}) as e
return e{*}
null
分析:如不使用前缀 OPTIONAL,则无返回。