Function collect()
arranges each row of a data column into an array, in their original order, and returns this array. Only one row from the data stream will be kept after this function is called, and all the rest rows will be abandoned.
Arguments:
- Any value <any>, auto-abstraction: UUID of NODE/EDGE, row index (starting from 0) of PATH, or the array formed by the elements in the row of TABLE
Returns:
- Array <array>
ATTR
Example: find 10 nodes and collect their schema
find().nodes([1,2,3,4,5,6,7,8,9,10]) as n
return collect(n.@)
NODE
Example: find 10 @product
nodes, collect their UUID
find().nodes({@product}) as n
limit 10
return collect(n)
EDGE
Example: find 10 @transfer
edges, collect their UUID
find().edges({@transfer}) as e
limit 10
return collect(e)
PATH
Example: find 10 shortest paths from Card CA001 within 2 steps, list the paths by the destination card's balances by descending order, and collect the column number of the paths.
n({_id == "CA001"}).e({@transfer})[2].n(as n).limit(10) as p
order by n.balance desc
return collect(p)
Analysis: the column number of the paths in the stream starts from 0,
ARRAY
Example: find paths from Card CA001 within 3 steps, count the number of the nodes of each path, then collect these nodes
n({_id == "CA001"}).e()[3].n() as p
with pnodes(p) as a
return collect(a)