1
votes

I have a structure that looks something like this:

enter image description here

How can I traverse my Page and get back a flat record so that each row represents all of data from the root node and its edges. My use case is that I'm producing a csv file.

so from the example above, i would like to create a row for each post. Each record should contain all fields from post, the language name, the page name, and the network name.

From what I can tell, when you do any kind of traversal, it only gives you the result of the final vertex and not any data from the vertices in between.

2

2 Answers

1
votes

Try this query:

select *,out('posted_to').name as page,out('posted_to').out('is_language').name as language,out('posted_to').out('is_network').name as network from <class Post> unwind page,language,network 
0
votes

If there are many posts per page, then anchoring the query on the Pages may be more efficient than starting with the Posts.

Ergo:

select focus.in() as post,
       focus.name as page,
       focus.out("is_language").name as language,
       focus.out("is_network").name as network
from (select @this as focus from Page)
unwind post, language, network, page

----+------+-----+----+--------+-------
#   |@CLASS|post |page|language|network
----+------+-----+----+--------+-------
0   |null  |#11:0|1   |Welsh   |1      
1   |null  |#11:1|1   |Welsh   |1      
2   |null  |#11:2|1   |Welsh   |1      
3   |null  |#11:3|1   |Welsh   |1      
4   |null  |#11:4|1   |Welsh   |1      
5   |null  |#11:5|1   |Welsh   |1      
6   |null  |#11:6|1   |Welsh   |1      
----+------+-----+----+--------+-------