with n, collect(nodes(p)) as listOflistOfnodes, collect(relationships(p)) as listOfListOfrelationships.The final result on line 8 consist of the root node, and one list of unique nodes from all the paths, and one list of the unique relationships from all the paths. Lines 6 and 7 repeat the process for the relationships. Line 5 recollects the stream of nodes with the distinct clause, resulting in a list of unique nodes. To flatten the list of lists and apply the distinct clause on rows, lines 3 and 4 unwinds the list of lists of nodes twice to get a stream of nodes. The result of line 2 is a single row consisting of node n and two collections of lists. The rest of the query manipulates theses lists to remove the duplicates and flatten them into lists of unique nodes and relationships.īack to the query, step 2 passes the single root node to the next phase of the query, forcing the collect methods to aggregate over all the paths, like a group by clause in sql. The list of lists for the nodes and relationships also contain duplicates. The result is a list containing lists of nodes and the same for the relationships. Instead, it appends each list into a new list representing. The issue here is that the collect method does not merge the individual lists from each path into a collection that represent the union of all the nodes and relationships. Line 2 aggregates the node and relationship collections using the collect method to reduce the data from all the paths to one collection to meet your requirement. You can get all the nodes along path p as a collection using the nodes(p) function and relationships using the relationships(p) function. The query binds the paths to the variable p, producing one result row for each path. The first line of the query results in rows representing each path anchored to the node of interest. Return n.name, distinctNodes, collect(distinct element) as distinctRelationshipsĪm I addressing your requirement? I am assuming you want the collection of nodes and relationships for the subgraph originating a root node. With n, collect(distinct element) as distinctNodes, listOfListOfrelationships With n, collect(nodes(p)) as listOflistOfnodes, collect(relationships(p)) as listOfListOfrelationships That explains why the double unwind is done twice. ![]() The inner list is the nodes along one path. This is necessary since the collect(nodes(p)) operation results in a list of lists. The following query will get all the paths originating from one root node, consolidate all the nodes and relationships from all the paths, then perform some double unwinding to eliminate the duplicates using the DISTINCT clause. The nodes and relationships in the collections of paths contain duplicates among the paths, due to the hierarchical nature of the data. Each path will contain all of the nodes and relationships along its path. When you query for a path, you will get a result for each path.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |