UNCOLLECT can expand each element in an array into an independent row and duplicate each row of it homologous alias as multiple rows. The expanded data stream has a number of rows that equals the sum of lengths of all the arrays in the input alias.
Syntax: UNCOLLECT <expression>
as <alias>
Input
- <expression>: The ARRAY type of alias to be expanded
- <alias>: The alias acquired after the ARRAY is expanded, mandatory
n(2).e()[:3].n(4) as path
with pnodes(path) as a1
uncollect a1 as a2
return path, a2
In the UQL above, UNCOLLECT expands an ARRAY alias a1 into 6 rows and acquires a2, and duplicates its homologous alias path into 6 rows:
Common Usage
Example: find paths from Card CA001 to CA003 within 3 steps, deduplicate the nodes on the paths and return
ab().src({_id == "CA001"}).dest({_id == "CA003"}).depth(:3) as p
with pnodes(p) as a
uncollect a as n
return distinct(n)