简体   繁体   English

OrientDB从起始顶点获取所有连接的顶点

[英]OrientDB get all connected vertices from a starting vertex

I'm working with Neo4j and OrientDB and I will compare their performance and functionality regarding traversal (Java Traversal API in Neo4j and Native Fluent API in OrientDB). 我正在与Neo4j和OrientDB一起工作,我将比较它们在遍历方面的性能和功能(Neo4j中的Java遍历API和OrientDB中的Native Fluent API)。

For OrientDB it should be possible to start at a specific vertex and get all vertices which are reachable and also an intersection of the property access on each individual step exists. 对于OrientDB,应该有可能从特定的顶点开始并获得所有可达的顶点,并且每个步骤的属性访问都存在交集。 If you have for example the graph A --> B --> C --> D , where A, B and C has access = www and D has the values access = https , the vertices A, B and C should be returned. 例如,如果您有图A-> B-> C-> D ,其中A,B和C具有access = wwwD的值具有access = https ,则应返回顶点A,B和C

I recently asked a question and afterwards I posted my solution, how comparison on properties is possible on Neo4j. 我最近问了一个问题,然后我发布了解决方案,如何在Neo4j上进行属性比较。

Neo4j node property comparison during traversal 遍历期间的Neo4j节点属性比较

In Neo4j it is possible to create a TraversalDescription, which describes the rules and the bahavior of the traversal. 在Neo4j中,可以创建一个TraversalDescription,该描述描述了遍历的规则和行为。 For example the following: the AccesListEvaluator will compare the property of two connected nodes, as you can see on the posted solution for above mentioned Neo4j comparison. 例如以下内容: AccesListEvaluator将比较两个连接节点的属性,正如您在上述Neo4j比较发布的解决方案中所看到的。

TraversalDescription td = db.traversalDescription().depthFirst()
            .relationships(RelationshipLabel.REFERENCED_BY, Direction.OUTGOING)
            .evaluator(new AccessListEvaluator());

If you execute the following code example, you will get back all reachable nodes from the startNode and you could iterate over them and extract all their properties. 如果执行以下代码示例,则将从startNode取回所有可到达的节点,并且可以对其进行迭代并提取其所有属性。

td.traverse(startNode).nodes();

I need alle the nodes, because I have to extract their properties and store it in a own data structure. 我需要所有节点,因为我必须提取它们的属性并将其存储在自己的数据结构中。

Is a similar solution with the OrientDB Native Fluent API possible? OrientDB本机Fluent API是否可能提供类似的解决方案? I checked the manual Java Traverse , but I'm not able to deviate a working solution from the given examples. 我检查了Java Traverse手册,但无法从给出的示例中偏离有效的解决方案。 If I'm execute the following code example I just get the properties and the IN and OUT connections of the target. 如果执行以下代码示例,则仅获取属性以及目标的IN和OUT连接。

for (OIdentifiable oi : new OTraverse().field("in").field("out").target(new ORecordId("#24:0"))) {
            System.out.println(oi);
}

For me it looks like, that you only get back the possible connections to other nodes. 对我而言,您似乎只取回了与其他节点的可能连接。 Is there any chance, with the Native API to get each vertex and the properties of each vertex? 是否有机会使用Native API获取每个顶点以及每个顶点的属性?

Hopefully my question is understandable. 希望我的问题是可以理解的。 Thanks in advance 提前致谢

I think I'm working on a similar problem. 我想我正在解决类似的问题。 I'm using python (PyOrient) to connect to OrientDB and I'm generally using the SQL syntax. 我正在使用python(PyOrient)连接到OrientDB,并且通常使用SQL语法。 I've been trying to leverage either TRAVERSE or a fetchPlan. 我一直在尝试利用TRAVERSE或fetchPlan。

When I use TRAVERSE I'm able to get all of the vertices and eges with properties with a query like this in console (same result in studio): 当我使用TRAVERSE时,可以在控制台中通过如下查询获得具有属性的所有顶点和实例(在Studio中具有相同结果):

orientdb {db=FetchPlanTesting}> traverse * from level01

----+------+---------+------------------+------------+------+------+-------------
#   |@RID  |@CLASS   |name              |in_belongsTo|out   |in    |out_belongsTo
----+------+---------+------------------+------------+------+------+-------------
0   |#11:0 |Level01  |Item01_at_Level01 |[size=2]    |null  |null  |null
1   |#20:1 |belongsTo|null              |null        |#12:1 |#11:0 |null
2   |#12:1 |Level02  |Item02_at_Level02 |[size=2]    |null  |null  |[size=1]
3   |#20:4 |belongsTo|null              |null        |#13:0 |#12:1 |null
4   |#13:0 |Level03  |Item01_at_Level03 |[size=2]    |null  |null  |[size=1]
5   |#20:19|belongsTo|null              |null        |#14:7 |#13:0 |null
6   |#14:7 |Level04  |Item08_at_Level04 |[size=2]    |null  |null  |[size=1]
7   |#20:34|belongsTo|null              |null        |#15:6 |#14:7 |null
8   |#15:6 |Level05  |Item07_at_Level05 |null        |null  |null  |[size=1]
9   |#20:50|belongsTo|null              |null        |#15:22|#14:7 |null
10  |#15:22|Level05  |Item023_at_Level05|null        |null  |null  |[size=1]
11  |#20:27|belongsTo|null              |null        |#14:15|#13:0 |null
12  |#14:15|Level04  |Item016_at_Level04|[size=2]    |null  |null  |[size=1]
13  |#20:42|belongsTo|null              |null        |#15:14|#14:15|null
14  |#15:14|Level05  |Item015_at_Level05|null        |null  |null  |[size=1]
15  |#20:58|belongsTo|null              |null        |#15:30|#14:15|null
16  |#15:30|Level05  |Item031_at_Level05|null        |null  |null  |[size=1]
17  |#20:8 |belongsTo|null              |null        |#13:4 |#12:1 |null
18  |#13:4 |Level03  |Item05_at_Level03 |[size=2]    |null  |null  |[size=1]
19  |#20:15|belongsTo|null              |null        |#14:3 |#13:4 |null
----+------+---------+------------------+------------+------+------+-------------
LIMIT EXCEEDED: resultset contains more items not displayed (limit=20)

The only property I have on any nodes is name . 我在任何节点上拥有的唯一属性是name I seem to recall that I could filter out the belongsTo edges (or at least only look for specific classes), but I've switched to trying a fetchPlan so I can get a nested JSON blob returned instead. 我似乎记得我可以过滤掉belongsTo边缘(或者至少仅查找特定的类),但是我已经切换到尝试fetchPlan,这样我可以获取嵌套的JSON blob来代替。 That query is easy enough (`, but I'm trying to figure out how best to limit the depth and not actually return the edges as part of the result. 该查询很容易(`,但是我试图弄清楚如何最好地限制深度,而不实际返回边缘作为结果的一部分。

Here's that query and result in console (same in studio): orientdb {db=FetchPlanTesting}> SELECT @this.toJSON('fetchPlan:*:-1') from 11:0 这是在控制台(与Studio相同)中的查询和结果:orientdb {db = FetchPlanTesting}>从11:0选择SELECT @ this.toJSON('fetchPlan:*:-1')

----+------+--------------------------------------------------------------------------------------------------------------------------------------------
#   |@CLASS|this
----+------+--------------------------------------------------------------------------------------------------------------------------------------------
0   |null  |{"name":"Item01_at_Level01","in_belongsTo":[{"out":{"name":"Item02_at_Level02","in_belongsTo":[{"out":{"name":"Item01_at_Level03","in_bel...
----+------+--------------------------------------------------------------------------------------------------------------------------------------------

1 item(s) found. Query executed in 0.024 sec(s).

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

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