neo4j - 为 OrientDB 重写 neo4j 查询

标签 neo4j orientdb orientdb-2.1 nosql

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

我正在尝试重写 co-actors 查询:

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

和“共同 Actor ”查询:

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")

第一个查询:查找汤姆·汉克斯的合作 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
----+------+-----+-------

第二个查询:查找汤姆·汉克斯未曾主演的联合 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
----+------+-------+-------

希望对你有帮助

关于neo4j - 为 OrientDB 重写 neo4j 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34880046/

相关文章:

python - 无法使用py2neo删除具有关系的neo4j节点

java - 加密 Neo4j 关系

tcp - 如何将 TCP 流量从外部路由到 Kubernetes 集群内的服务?

OrientDB,查找索引插入点

Neo4j 在创建节点时向节点添加属性或特性

Neo4j 索引和遗留数据

java - 在 OrientDB 中使用 Java 创建图形数据库模式

c# - 如何在 OrientDB .Net API 中执行 Massiveinsert?

java - OrientDB - Java进程: memory out of control