简体   繁体   English

OrientDB中的两步查询

[英]2-steps query in OrientDB

I'm evaluating OrientDB and Neo4j in this simple toy example composed by: 我在由以下组成的简单玩具示例中评估OrientDB和Neo4j:

  • Employees, identified by eid 雇员,由eid确定
  • Meetings, identified by mid and having start and end attributes encoding their start and end DateTime. 会议由确定mid和有startend属性编码的开始和结束日期时间。

Both entities are represented by different classes of vertices, namely Employee and CalendarEvent , which are connected by Involves edges specifying that CalendarEvent-[Involves]->Employee . 这两个实体都由不同类的顶点表示,即EmployeeCalendarEvent ,它们通过Involves边连接,指定了CalendarEvent-[Involves]->Employee

My task is to write a query that returns, for each pair of employees, the date/time of their first meeting and the number of meetings they co-attended. 我的任务是编写一个查询,为每对员工返回他们第一次开会的日期/时间以及他们共同参加的会议次数。 In Cypher I would write something like: 在Cypher中,我将编写如下内容:

MATCH (e0: Employee)<-[:INVOLVES]-(c:CalendarEvent)-[:INVOLVES]->(e1: Employee)
WHERE e0.eid > e1.eid
RETURN e0.eid, e1.eid, min(c.start) as first_met, count(*) as frequency

I wrote the following query for OrientDB: 我为OrientDB编写了以下查询:

SELECT eid, other, count(*) AS frequency, min(start) as first_met
FROM (
  SELECT eid, event.start as start, event.out('Involves').eid as other
  FROM (
    SELECT 
    eid, 
    in('Involves') as event
    FROM Employee UNWIND event
    ) UNWIND other ) 
GROUP BY eid, other

but it seems over-complicated to me. 但是对我来说似乎太复杂了。 Does anybody knows if there is an easier way to express the same query? 有人知道是否存在一种更简单的方式来表达相同的查询吗?

yes, your query is correct and this is what you have to do in current version (2.1.x). 是的,您的查询是正确的,这是您在当前版本(2.1.x)中必须执行的操作。

From 2.2, with MATCH statement ( https://github.com/orientechnologies/orientdb-docs/blob/master/source/SQL-Match.md ), you will be able to write a query very similar to Cypher version: 从2.2开始,使用MATCH语句( https://github.com/orientechnologies/orientdb-docs/blob/master/source/SQL-Match.md ),您将能够编写与Cypher版本非常相似的查询:

select eid0, eid1, min(start) as firstMet, count(*) from (
    MATCH {class:Person, as:e0}.in("Involves"){as: meeting}.out("Involves"){as:e1}
    return e0.eid as eid0, e1.eid as eid1, meeting.start as start
) group by eid0, eid1

This feature is till in beta, probably in final version you will have more operators in the MATCH statement itself and the query will be even shorter 此功能直到beta为止,可能在最终版本中,您将在MATCH语句本身中包含更多运算符,并且查询会更短

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

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