为 OrientDB 重写 neo4j 查询

Rewrite neo4j queries for OrientDB

我正在测试 neo4j 与 OrientDB 图形数据库的性能。我正在使用 neo4j 网站上提供的 MoiveDatabase 数据集。我已按照说明进行操作:

export-graphml -t -o /tmp/out.graphml
CREATE DATABASE plocal:/tmp/db/test
IMPORT DATABASE /tmp/out.graphml storeVertexIds=true

这是 classes 输出,所以我猜导入没问题。

CLASSES
----------------------+------------------------------------+------------+----------------+
 NAME                 | SUPERCLASS                         | CLUSTERS   | RECORDS        |
----------------------+------------------------------------+------------+----------------+
 ACTS_IN              | [E]                                | 14         |          94700 |
 DIRECTED             | [E]                                | 13         |          11915 |
 E                    |                                    | 10         |              0 |
 FRIEND               | [E]                                | 16         |              6 |
 Movie                | [V]                                | 12         |           6379 |
 OFunction            |                                    | 6          |              0 |
 OIdentity            |                                    | -          |              0 |
 ORestricted          |                                    | -          |              0 |
 ORIDs                |                                    | 8          |              0 |
 ORole                | [OIdentity]                        | 4          |              3 |
 OSchedule            |                                    | 7          |              0 |
 OTriggered           |                                    | -          |              0 |
 OUser                | [OIdentity]                        | 5          |              3 |
 Person               | [V]                                | 11         |          50013 |
 RATED                | [E]                                | 15         |             30 |
 V                    |                                    | 9          |          61752 |
----------------------+------------------------------------+------------+----------------+
 TOTAL = 16                                                                       224801 |
----------------------+------------------------------------+------------+----------------+

但是当我尝试执行这个查询时: SELECT in() FROM Movie LIMIT 10SELEC out() FROM Person LIMIT 10 我没有得到任何记录。这是为什么?

我正在尝试重写共同演员查询:

 MATCH (tom:Person {name:"Tom Hanks"})-[:ACTED_IN]->(:Movie)<-[:ACTED_IN]-(coActor:Person)
 RETURN coActor.name 

和"co-co-actors"查询:

MATCH (tom:Person)-[:ACTED_IN]->(movie1)<-[:ACTED_IN]-(coActor:Person),
(coActor)-[:ACTED_IN]->(movie2)<-[:ACTED_IN]-(coCoActor:Person)
WHERE tom.name = "Tom Hanks" AND   NOT    (tom)-[:ACTED_IN]->(movie2)

RETURN coCoActor.name

我应该为此使用 TRAVERSE 吗?

我创建了这个小数据库来尝试你的案例:

create class Person extends V
create class Movie extends V
create class acts_In extends E
create class directed extends E
create class friend extends E
create class rated extends E

create property Person.name String
create property Person.surname String
create property Movie.title String

create vertex Person set name="Tom", surname="Hanks"
create vertex Person set name="Robin", surname="Wright"
create vertex Person set name="Helen", surname="Hunt"
create vertex Person set name="Robert", surname="Zemeckis"
create vertex Person set name="Russell", surname="Crowe"
create vertex Person set name="Ben", surname="Affleck"
create vertex Person set name="Kevin", surname="Macdonald"
create vertex Person set name="John"
create vertex Person set name="Mark"
create vertex Person set name="Paul"
create vertex Person set name="Mel", surname="Gibson"
create vertex Person set name="Nancy", surname="Meyers"
create vertex Movie set title="Forrest Gump"
create vertex Movie set title="Cast Away"
create vertex Movie set title="State of Play"
create vertex Movie set title="What Women Want"

create edge acts_In from (select from Person where name="Tom" and surname="Hanks") to (select from Movie where title="Forrest Gump")
create edge acts_In from (select from Person where name="Tom" and surname="Hanks") to (select from Movie where title="Cast Away")
create edge acts_In from (select from Person where name="Robin" and surname="Wright") to (select from Movie where title="Forrest Gump")
create edge acts_In from (select from Person where name="Robin" and surname="Wright") to (select from Movie where title="State of Play")
create edge acts_In from (select from Person where name="Helen" and surname="Hunt") to (select from Movie where title="Cast Away")
create edge acts_In from (select from Person where name="Helen" and surname="Hunt") to (select from Movie where title="What Women Want")
create edge acts_In from (select from Person where name="Mel" and surname="Gibson") to (select from Movie where title="What Women Want")
create edge acts_In from (select from Person where name="Russell" and surname="Crowe") to (select from Movie where title="State of Play")
create edge acts_In from (select from Person where name="Ben" and surname="Affleck") to (select from Movie where title="State of Play")
create edge friend from (select from Person where name="Mel" and surname="Gibson") to (select from Person where name="Helen" and surname="Hunt")
create edge friend from (select from Person where name="Ben" and surname="Affleck") to (select from Person where name="Russell" and surname="Crowe")
create edge directed from (select from Movie where title="What Women Want") to (select from Person where name="Nancy" and surname="Meyers")
create edge directed from (select from Movie where title="Cast Away") to (select from Person where name="Robert" and surname="Zemeckis")
create edge directed from (select from Movie where title="Forrest Gump") to (select from Person where name="Robert" and surname="Zemeckis")
create edge directed from (select from Movie where title="State of Play") to (select from Person where name="Kevin" and surname="Macdonald")
create edge rated from (select from Movie where title="What Women Want") to (select from Person where name="Paul")
create edge rated from (select from Movie where title="Cast Away") to (select from Person where name="John")
create edge rated from (select from Movie where title="Forrest Gump") to (select from Person where name="Mark")
create edge rated from (select from Movie where title="State of Play") to (select from Person where name="John")

第一次查询: 找到Tom Hanks

的co-actor
select distinct(name) as name, distinct(surname) as surname from (select expand(in('acts_In')) from Movie where in('acts_In').name in 'Tom' 
and in('acts_In').surname in 'Hanks') where name<>'Tom' and in('acts_In').surname<>'Hanks'

输出:

----+------+-----+-------
#   |@CLASS|name |surname
----+------+-----+-------
0   |null  |Robin|Wright
1   |null  |Helen|Hunt
----+------+-----+-------

第二个查询:找到汤姆·汉克斯没有出演的合作co-actor

select name, surname from (select expand($ris)
let $a=(select from Person where out('acts_In').size()>0 and name<>'Tom' and surname<>'Hanks'),
    $b=(select from (select expand(in('acts_In')) from Movie where in('acts_In').name in 'Tom' and in('acts_In').surname in 'Hanks') where name<>'Tom' and in('acts_In').surname<>'Hanks'),
    $ris=difference($a,$b))

输出:

----+------+-------+-------
#   |@CLASS|name   |surname
----+------+-------+-------
0   |null  |Russell|Crowe
1   |null  |Ben    |Affleck
2   |null  |Mel    |Gibson
----+------+-------+-------

希望对您有所帮助