简体   繁体   English

OrientDB从查询中选择顶点,边对

[英]OrientDB select Vertex, Edge pairs from query

In an OrientDb graph database, I'm trying to get some information about Vertex, Edge pairs. 在OrientDb图数据库中,我试图获取有关“顶点”,“边缘”对的信息。

For example, consider the following case: 例如,考虑以下情况:

V1 ---E1---> V2
   ---E2---> V3 --E3--> V2

I would like to have as result the following 3 rows; 结果,我希望获得以下3行;

V1, E1
V1, E2
V3, E3

I've tried the following: 我尝试了以下方法:

select label, flatten(out.label) from V
select label from (select flatten(out) from V)
select label, flatten(out) from V
select flatten(out) from V
select $current, label from (traverse out from V while $depth <= 1) where $depth = 1

But none of these solutions seem to return what I want. 但是这些解决方案似乎都没有返回我想要的。 How can I return Vertex, Edge pairs? 如何返回顶点,边对?

FLATTEN operator works alone, because get a field and let it to become the result. FLATTEN运算符是单独工作的,因为得到一个字段并使其成为结果。 I don't understand what you want to do. 我不明白你想做什么。 Can you write the expected output please? 你能写出预期的输出吗?

What you are trying to do is actually extremely simple with OrientDB, it seems you are overthinking the issue. 对于OrientDB,您实际上想做的事情非常简单,似乎您对此问题的思考过多。

Let's create your example: 让我们创建您的示例:

V1 ---E1---> V2
   ---E2---> V3 --E3--> V2

In OrientDB, you would do this as follows: 在OrientDB中,您将执行以下操作:

/* Create nodes */
CREATE CLASS Node EXTENDS V
CREATE PROPERTY Node.name STRING (MANDATORY TRUE)
CREATE VERTEX Node SET name = 'V1'
CREATE VERTEX Node SET name = 'V2'
CREATE VERTEX Node SET name = 'V3'

/* Create edges */
CREATE CLASS Link EXTENDS E
CREATE PROPERTY Link.name STRING (MANDATORY TRUE)
CREATE EDGE Link
    FROM (SELECT FROM Node WHERE name = 'V1') 
    TO (SELECT FROM Node WHERE name = 'V2')
    SET name = 'E1'
CREATE EDGE Link
    FROM (SELECT FROM Node WHERE name = 'V1')
    TO (SELECT FROM Node WHERE name = 'V3')
    SET name = 'E2'
CREATE EDGE Link 
    FROM (SELECT FROM Node WHERE name = 'V3')
    TO (SELECT FROM Node WHERE name = 'V2')
    SET name = 'E3'

This creates the following graph: 这将创建以下图形:

示例OrientDB图

Now a little explanation of how to query in OrientDB. 现在对如何在OrientDB中进行查询进行一些解释。 Let's say you load one vertex: SELECT * FROM Node WHERE name = 'V1' . 假设您加载了一个顶点: SELECT * FROM Node WHERE name = 'V1' Then, to load other information, you use: 然后,要加载其他信息,请使用:

  • To load all incoming vertices (skipping the edges): in() 加载所有传入的顶点(跳过边): in()
  • To load all incoming vertices of class Link (skipping the edges): in('Link') 要加载Link类的所有传入顶点(跳过边): in('Link')
  • To load all incoming edges: inE() 加载所有传入边: inE()
  • To load all incoming edges of class Link : inE('Link') 加载类Link所有传入边缘: inE('Link')
  • To load all outgoing vertices (skipping the edges): out() 加载所有传出顶点(跳过边): out()
  • To load all outgoing vertices of class Link (skipping the edges): out('Link') 加载Link类的所有传出顶点(跳过边): out('Link')
  • To load all outgoing edges: outE() 加载所有传出的边: outE()
  • To load all outgoing edges of class Link : outE('Link') 加载类Link所有输出边缘: outE('Link')

So in your case, you want to load all the vertices and their outgoing edges, so we do: 因此,在您的情况下,您想加载所有顶点及其外边缘,因此我们执行以下操作:

SELECT name, outE('Link') FROM Node

Which loads the name of the vertices and a pointer to the outgoing edges: 加载顶点的名称和指向输出边缘的指针:

OrientDB查询示例

If you would like to have a list of the names of the outgoing edges, we simply do: 如果您想获得输出边缘的名称的列表,我们只需执行以下操作:

SELECT name, outE('Link').name FROM Node

Which gives: 这使:

OrientDB查询2的示例

Which is exactly what you asked for in your question. 这正是您在问题中要问的。 As you can see, this is extremely simple to do in OrientDB, you just need to realize that OrientDB is smarter than you think :) 如您所见,这在OrientDB中非常简单,您只需要意识到OrientDB比您想象的要聪明:)

The CYPHER syntax, as used in Neo4j finally rescued me. Neo4j中使用的CYPHER语法最终救了我。

start n=node(*) MATCH (n)-[left]->(n2)<-[right]-(n3) WHERE n.type? ='myType' AND left.line > right.line - 1 AND left.line < right.line + 1 RETURN n, left, n2, right, n3

The node n is the pivoting element, on wich an filter can be provided, just as on each other step within the path. 节点n是枢转元件,就像在路径内的每个其他步骤一样,可以提供一个过滤器。 For me it was important to select a further step depending on an other part of the path. 对我来说,根据路径的其他部分选择进一步的步骤很重要。

With OrientDb I couldnt find a way to relate the properties to each other easily. 使用OrientDb,我无法找到一种轻松地将属性彼此关联的方法。

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

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