OrientDB 中的两步查询

2-steps query in OrientDB

我正在这个由以下人员组成的简单玩具示例中评估 OrientDB 和 Neo4j:

两个实体都由不同的 类 个顶点表示,即 EmployeeCalendarEvent,它们由 Involves 条边连接,指定 CalendarEvent-[Involves]->Employee

我的任务是编写一个查询 returns,对于每对员工,他们第一次会议的 date/time 和他们 co-attended 的会议次数。 在 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

我为 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

但在我看来 over-complicated。 有人知道是否有更简单的方法来表达相同的查询吗?

是的,您的查询是正确的,这就是您在当前版本 (2.1.x) 中必须执行的操作。

从 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

此功能目前处于测试阶段,可能在最终版本中,您将在 MATCH 语句本身中包含更多运算符,并且查询会更短