apoc.export.cypher.graph
|
此过程不被认为是多线程安全运行的。因此,并行运行时不支持它。更多信息,请参阅Cypher 手册 → 并行运行时。 |
语法 |
|
||
描述 |
将给定的图(包括索引)导出为 Cypher 语句到提供的文件(默认:Cypher Shell)。 |
||
输入参数 |
名称 |
类型 |
描述 |
|
|
要导出的图。 |
|
|
|
数据将导出到的文件名称。 |
|
|
|
|
|
返回参数 |
名称 |
类型 |
描述 |
|
|
数据导出到的文件名称。 |
|
|
|
导出运行时批处理的数量。 |
|
|
|
导出数据的摘要。 |
|
|
|
文件导出的格式。 |
|
|
|
导出节点的数量。 |
|
|
|
导出关系的数量。 |
|
|
|
导出属性的数量。 |
|
|
|
导出的持续时间。 |
|
|
|
返回的行数。 |
|
|
|
导出运行时批处理的大小。 |
|
|
|
执行的 Cypher 语句。 |
|
|
|
执行的节点语句。 |
|
|
|
执行的关系语句。 |
|
|
|
执行的模式语句。 |
|
|
|
执行的清理语句。 |
|
用法示例
本节中的示例基于以下示例图
CREATE (TheMatrix:Movie {title:'The Matrix', released:1999, tagline:'Welcome to the Real World'})
CREATE (Keanu:Person {name:'Keanu Reeves', born:1964})
CREATE (Carrie:Person {name:'Carrie-Anne Moss', born:1967})
CREATE (Laurence:Person {name:'Laurence Fishburne', born:1961})
CREATE (Hugo:Person {name:'Hugo Weaving', born:1960})
CREATE (LillyW:Person {name:'Lilly Wachowski', born:1967})
CREATE (LanaW:Person {name:'Lana Wachowski', born:1965})
CREATE (JoelS:Person {name:'Joel Silver', born:1952})
CREATE
(Keanu)-[:ACTED_IN {roles:['Neo']}]->(TheMatrix),
(Carrie)-[:ACTED_IN {roles:['Trinity']}]->(TheMatrix),
(Laurence)-[:ACTED_IN {roles:['Morpheus']}]->(TheMatrix),
(Hugo)-[:ACTED_IN {roles:['Agent Smith']}]->(TheMatrix),
(LillyW)-[:DIRECTED]->(TheMatrix),
(LanaW)-[:DIRECTED]->(TheMatrix),
(JoelS)-[:PRODUCED]->(TheMatrix);
下面的 Neo4j Browser 可视化显示了导入的图
apoc.export.cypher.graph 过程将虚拟图导出到 CSV 文件或作为流。
本节中的示例基于一个虚拟图,该图包含所有 PRODUCED 关系以及该关系两端的节点。它们还使用apoc.graph.fromPaths通过从每个查询中第一个 MATCH 子句收集的数据中提取节点和关系来生成虚拟子图,并且 apoc.export.cypher.graph 过程使用此子图。
在以下示例中,由 apoc.graph.fromPaths 生成的虚拟图以 Cypher 语句的形式导出到文件 movies-producers.cypher
MATCH path = (:Person)-[produced:PRODUCED]->(:Movie)
WITH collect(path) AS paths
CALL apoc.graph.fromPaths(paths, "producers", {})
YIELD graph AS g
CALL apoc.export.cypher.graph(g, "movies-producers.cypher", {})
YIELD file, nodes, relationships, properties
RETURN file, nodes, relationships, properties;
| file | nodes | relationships | properties |
|---|---|---|---|
"movies-producers.cypher" |
2 |
1 |
5 |
下一个示例需要以下设置
:begin
CREATE CONSTRAINT uniqueConstraint FOR (node:`UNIQUE IMPORT LABEL`) REQUIRE (node.`UNIQUE IMPORT ID`) IS UNIQUE;
:commit
:begin
UNWIND [{_id:31450, properties:{tagline:"Welcome to the Real World", title:"The Matrix", released:1999}}] AS row
CREATE (n:`UNIQUE IMPORT LABEL`{`UNIQUE IMPORT ID`: row._id}) SET n += row.properties SET n:Movie;
UNWIND [{_id:31457, properties:{born:1952, name:"Joel Silver"}}] AS row
CREATE (n:`UNIQUE IMPORT LABEL`{`UNIQUE IMPORT ID`: row._id}) SET n += row.properties SET n:Person;
:commit
:begin
UNWIND [{start: {_id:31457}, end: {_id:31450}, properties:{}}] AS row
MATCH (start:`UNIQUE IMPORT LABEL`{`UNIQUE IMPORT ID`: row.start._id})
MATCH (end:`UNIQUE IMPORT LABEL`{`UNIQUE IMPORT ID`: row.end._id})
CREATE (start)-[r:PRODUCED]->(end) SET r += row.properties;
:commit
:begin
MATCH (n:`UNIQUE IMPORT LABEL`) WITH n LIMIT 20000 REMOVE n:`UNIQUE IMPORT LABEL` REMOVE n.`UNIQUE IMPORT ID`;
:commit
:begin
DROP CONSTRAINT uniqueConstraint;
:commit
以下查询将虚拟图的流从静态值存储返回到 cypherStatements 列
MATCH path = (:Person)-[produced:PRODUCED]->(:Movie)
WITH collect(path) AS paths
CALL apoc.graph.fromPaths(paths, "producers", {})
YIELD graph AS g
CALL apoc.export.cypher.graph(g, null, {stream: true})
YIELD file, nodes, relationships, properties, cypherStatements
RETURN file, nodes, relationships, properties, cypherStatements;
| file | nodes | relationships | properties | cypherStatements |
|---|---|---|---|---|
NULL |
2 |
1 |
5 |
":begin CREATE CONSTRAINT uniqueConstraint FOR (node:`UNIQUE IMPORT LABEL`) REQUIRE (node. |