OrientDB: How to flatten nested heirarchy into a single record

瘦欲@ 提交于 2021-01-28 12:10:40

问题


I have a structure that looks something like this:

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.


回答1:


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 



回答2:


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      
----+------+-----+----+--------+-------


来源:https://stackoverflow.com/questions/34428378/orientdb-how-to-flatten-nested-heirarchy-into-a-single-record

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!