简体   繁体   English

OrientDB遍历(子),同时连接到顶点并获得另一个顶点

[英]OrientDB traverse (children) while connected to a vertex and get an other vertex

I'm not sure the title is the best way to phrase it, here's the structure: 我不确定标题是用来表达它的最佳方式,这里是结构:

Structure 结构体

Here's the db json backup if you want to import it to test it: http://pastebin.com/iw2d3uuy 这是db json备份,如果你想导入它来测试它: http//pastebin.com/iw2d3uuy

I'd like to get the Dishes eaten by the Humans living in Continent 1 until a _Parent Human moved to Continent 2. Which means the target is Dish 1 & 2. 我想让生活在大陆1的人类吃掉菜肴,直到_Parent Human搬到大陆2.这意味着目标是菜1和2。

If a parent moved to another Continent, I don't want their dish nor the dishes of their children, even if they move back to Continent 1. I don't know if it matters, but a Human can have multiple children. 如果父母移居到另一个大陆,即使他们搬回大陆1,我也不想要他们的菜肴和他们孩子的菜肴。我不知道这是否重要,但是一个人可以有多个孩子。

If there wasn't the condition about the children of a Human who has moved from the Continent, this query would have worked: 如果没有关于从大陆移出的人的子女的条件,这个查询将有效:

SELECT expand(in('_Is_in').in('_Lives').in('_Eaten_by'))
FROM Continent WHERE continent_id = 1

But I guess here we're forced to use (among other things) 但我猜这里我们被迫使用(除其他外)

TRAVERSE out('_Parent') FROM Human WHILE

I've tried to use the while of traverse with a subquery to get all the Humans I'm interested in, before to try to get the Dishes, but I'm not even sure we can use while with a subquery. 我试图使用子查询的遍历时间来获取我感兴趣的所有人类,然后尝试获取菜单,但我甚至不确定我们可以使用子查询。

I hope the structure will help other users to quickly find out if this query is useful to them. 我希望该结构可以帮助其他用户快速找出这个查询是否对他们有用。 If anyone is wondering, I used the Graph tab of OrientDB Studio to make it, along with GIMP. 如果有人想知道,我使用OrientDB Studio的Graph选项卡与GIMP一起制作它。

As a bonus, if anyone knows the Gremlin syntax, it would also be useful to learn it. 作为奖励,如果有人知道Gremlin语法,那么学习它也会很有用。

Please feel free to edit this post as you see fit and contribute your thoughts :) 如果您认为合适,请随时编辑此帖子,并提出您的想法:)

SELECT expand(in('_Eaten_by'))
FROM (TRAVERSE out('_Parent')
      FROM (SELECT from Human WHERE in('_Parent').size() = 0)
      WHILE out('_Lives').out('_Is_in').continent_id = 1)

Explanation: 说明:

  • TRAVERSE out('_Parent') FROM (SELECT FROM Human WHERE in('_Parent').size() = 0) WHILE out('_Lives').out('_Is_in').continent_id = 1

returns Human 1 and 2. 返回人类1和2。

That query traverses Human, starting from Human 1 while the Human is connected to Continent 1. 该查询遍历Human,从Human 1开始,而Human连接到Continent 1。

It starts from in('_Parent').size() = 0 which are the Humans without any _Parent (there's only Human 1 in this case) (size() is the size of the collection of vertices coming in from _Parent). 它从in('_Parent').size() = 0开始.size in('_Parent').size() = 0这是人类没有任何_Parent(在这种情况下只有人类1)(size()是从_Parent进入的顶点集合的大小)。

  • And SELECT expand(in('_Eaten_by')) FROM 并且SELECT expand(in('_Eaten_by')) FROM

gets the Dishes, starting from the Humans we got from the traversal and going through the edge _Eaten_by. 得到菜肴,从我们从遍历中获得的人类开始并经过边缘_Eaten_by。

Note: be sure to always use ' around the vertices and edges names, otherwise the names don't seem to be taken in account. 注意:请务必始终在顶点和边名称周围使用',否则似乎不会考虑名称。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM