概述
找点子句find().nodes()
从图集中获取符合过滤条件的点。
语法
子句别名: 数据类型为NODE;默认别名为nodes
方法 |
参数类型 |
参数规范 |
必须 |
描述 | 别名 |
---|---|---|---|---|---|
nodes() |
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().nodes() as n
return n{*}
结果:
_id | _uuid | Schema | age | email |
---|---|---|---|---|
P001 | 1 | professor | 53 | test@yahoo.cn |
P002 | 2 | professor | 27 | test@ultipa.com |
_id | _uuid | Schema | age | email |
---|---|---|---|---|
S001 | 3 | student | 27 | test@yeah.net |
S002 | 4 | student | 20 | test@w3.org |
S003 | 5 | student | 25 | test@gmail.com |
过滤ID
find().nodes({_id == "S001"}) as n
return n{*}
结果:
_id | _uuid | Schema | age | email |
---|---|---|---|---|
S001 | 3 | student | 27 | test@yeah.net |
find().nodes({_id in ["P001", "P002"]}) as n
return n{*}
结果:
_id | _uuid | Schema | age | email |
---|---|---|---|---|
P001 | 1 | professor | 53 | test@yahoo.cn |
P002 | 2 | professor | 27 | test@ultipa.com |
过滤UUID
find().nodes(1) as n
return n{*}
过滤条件
{_uuid == 1}
可简写为1
。
结果:
_id | _uuid | Schema | age | email |
---|---|---|---|---|
P001 | 1 | professor | 53 | test@yahoo.cn |
find().nodes([1,3]) as n
return n{*}
过滤条件
{_uuid in [1,3]}
可简写为[1,3]
。
结果:
_id | _uuid | Schema | age | email |
---|---|---|---|---|
P001 | 1 | professor | 53 | test@yahoo.cn |
_id | _uuid | Schema | age | email |
---|---|---|---|---|
S001 | 3 | student | 27 | test@yeah.net |
过滤Schema
find().nodes({@student}) as n
return n{*}
结果:
_id | _uuid | Schema | age | email |
---|---|---|---|---|
S001 | 3 | student | 27 | test@yeah.net |
S002 | 4 | student | 20 | test@w3.org |
S003 | 5 | student | 25 | test@gmail.com |
find().nodes({@student || @professor}) as n
return n{*}
结果:
_id | _uuid | Schema | age | email |
---|---|---|---|---|
P001 | 1 | professor | 53 | test@yahoo.cn |
P002 | 2 | professor | 27 | test@ultipa.com |
_id | _uuid | Schema | age | email |
---|---|---|---|---|
S001 | 3 | student | 27 | test@yeah.net |
S002 | 4 | student | 20 | test@w3.org |
S003 | 5 | student | 25 | test@gmail.com |
过滤属性值
find().nodes({age > 30}) as n
return n{*}
结果:
_id | _uuid | Schema | age | email |
---|---|---|---|---|
P001 | 1 | professor | 53 | test@yahoo.cn |
过滤Schema和属性值
find().nodes({@student.age > 25}) as n
return n{*}
结果:
_id | _uuid | Schema | age | email |
---|---|---|---|---|
S001 | 3 | student | 27 | test@yeah.net |
使用默认子句别名
find().nodes().limit(1)
return nodes{*}
结果:
_id | _uuid | Schema | age | email |
---|---|---|---|---|
P001 | 1 | professor | 53 | test@yahoo.cn |
限制查询数量
find().nodes().limit(3) as n
return n{*}
结果:
_id | _uuid | Schema | age | email |
---|---|---|---|---|
P001 | 1 | professor | 53 | test@yahoo.cn |
P002 | 2 | professor | 27 | test@ultipa.com |
_id | _uuid | Schema | age | email |
---|---|---|---|---|
S001 | 3 | student | 27 | test@yeah.net |
使用前缀OPTIONAL
uncollect [53, 55, 57] as value
optional find().nodes({age == value}) as n
return n{*}
结果:
_id | _uuid | Schema | age | email |
---|---|---|---|---|
P001 | 1 | professor | 53 | test@yahoo.cn |
_id | _uuid | Schema |
---|---|---|
null | null | null |
null | null | null |
如果没有使用前缀OPTIONAL
,查询无结果时无返回值。