UNCOLLECT releases each element of a list into an independent row and duplicate each original row and its homologous rows into a corresponding number of multiple rows. The released data stream has a length that equals the sum of lengths of all the lists that have been released.
Syntax: UNCOLLECT <expression>
as <alias>
Input
- <expression>: The list to be released
- <alias>: The alias acquired after the list is released, mandatory
For instance, release all the nodes in path, homologous alias path and a1 have 2 rows, after release path and a2 have 6 rows:
n(2).e()[:3].n(4) as path
with pnodes(path) as a1
uncollect a1 as a2
return path, a2
Sample graph: (to be used for the following examples)
create().edge_property(@default, "weight", int32)
insert().into(@default).nodes([{_id:"A", _uuid:1}, {_id:"B", _uuid:2}, {_id:"C", _uuid:3}, {_id:"D", _uuid:4}, {_id:"E", _uuid:5}, {_id:"F", _uuid:6}])
insert().into(@default).edges([{_uuid:1, _from_uuid:1, _to_uuid:3, weight:1}, {_uuid:2, _from_uuid:5, _to_uuid:2 , weight:1}, {_uuid:3, _from_uuid:1, _to_uuid:5 , weight:4}, {_uuid:4, _from_uuid:4, _to_uuid:3 , weight:2}, {_uuid:5, _from_uuid:5, _to_uuid:4 , weight:3}, {_uuid:6, _from_uuid:2, _to_uuid:1 , weight:2}, {_uuid:7, _from_uuid:6, _to_uuid:1 , weight:4}])
Common Usage
Example: Find 2-step paths from A to D, deduplicate all the involved nodes and return
n({_id == "A"}).e()[2].n({_id == "D"}) as p
uncollect pnodes(p) as a
with dedup(a) as b
return b{*}
| _id | _uuid |
|-----|-------|
| A | 1 |
| C | 3 |
| D | 4 |
| E | 5 |