Query find().edges()
can apply filters on edges and return those that meet the requirement. This is very similar to table query in traditional database.
Syntax:
- Statement alias: supported (EDGE)
- Prefix: OPTIOANL (returns
null
for any subquery that finds no result) - Optional parameters:
Parameter | Type | Specification | Description | Structure of Custom Alias |
---|---|---|---|---|
limit() |
Int | -1 or >=0 | Number of results to return for each subquery, -1 means to return all results | Not supported |
An alias edges will be automatically defined by system when there is no manually defined alias at the end of the edge query statement; in this case user cannot use edges to define alias for other data in the subsequent UQL statement, otherwise error of duplicated name will be triggered.
Sample graph: (to be used for the following examples)
Run below UQLs one by one in an empty graphset to create graph data: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:"[email protected]"},{_id:"P002",_uuid:2,age:27,email:"[email protected]"}])
insert().into(@student).nodes([{_id:"S001",_uuid:3,age:27,email:"[email protected]"},{_id:"S002",_uuid:4,age:20,email:"[email protected]"},{_id:"S003",_uuid:5,age:25,email:"[email protected]"}])
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}])
No Filter
Example: Find any edge, carry all properties
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 |
Filter ID
Example: Find edges with _uuid
1 or 3, carry all properties
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 |
Filter FROM/TO
Example: Find edges pointing from node P001, carry all properties
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 |
Example: Find edges pointing to node P001, carry all properties
find().edges({_to == "P001"}) as e
return e{*}
|---------------------- @assist ----------------------|
| _uuid | _from | _to | _from_uuid | _to_uuid | year |
|-------|-------|------|------------|----------|------|
| 6 | S002 | P001 | 4 | 1 | 2022 |
Filter Schema
Example: Find edges of @assist, carry all properties
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 |
Filter Property
Example: Find edges with year equal to 2020, carry all properties
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 |
Filter Schema & Property
Example: Find edges of @assist with year equal to 2020, carry all properties
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()
Example: Find 3 edges, carry all properties
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 |
Default Statement Alias
Example: Find 3 edges, carry all properties
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
Example: Find edges pointing from node S003, carry all properties; return null
if no result
optional find().edges({_from == "S003"}) as e
return e{*}
null
Analysis: This query will give no return if not using OPTIONAL.