重写对OrientDB的neo4j查询

时间:2016-01-19 14:59:10

标签: neo4j orientdb orientdb-2.1 nosql

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

D:/

这是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 10我没有得到任何记录。那是为什么?

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

SELEC out() FROM Person LIMIT 10

和“共同演员”查询:

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

我应该使用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 吗?

1 个答案:

答案 0 :(得分:2)

我创建了这个小数据库来试试你的情况:

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的合作演员

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
----+------+-----+-------

第二次查询:找到汤姆汉克斯没有加星标的合作演员

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
----+------+-------+-------

希望有所帮助