apoc.export.cypher.graph过程
|
此过程不建议在多线程中运行,因此并行运行时(Parallel runtime)不支持该过程。有关更多信息,请参阅 Cypher 手册 → 并行运行时。 |
语法 |
|
||
描述 |
将给定的图(包括索引)以 Cypher 语句的形式导出到指定文件(默认:Cypher Shell)。 |
||
输入参数 |
名称 |
类型 |
描述 |
|
|
要导出的图。 |
|
|
|
要导出数据的文件名。 |
|
|
|
|
|
返回参数 |
名称 |
类型 |
描述 |
|
|
数据导出到的文件名。 |
|
|
|
导出过程执行的批次数。 |
|
|
|
导出数据的摘要。 |
|
|
|
文件的导出格式。 |
|
|
|
已导出节点的数量。 |
|
|
|
已导出关系的数量。 |
|
|
|
已导出属性的数量。 |
|
|
|
导出所花费的时间。 |
|
|
|
返回的行数。 |
|
|
|
导出过程执行的批处理大小。 |
|
|
|
已执行的 Cypher 语句。 |
|
|
|
已执行的节点语句。 |
|
|
|
已执行的关系语句。 |
|
|
|
已执行的模式(Schema)语句。 |
|
|
|
已执行的清理语句。 |
|
使用示例
本节中的示例基于以下示例图
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 过程将虚拟图 (virtual 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 | 节点 | relationships | 属性 |
|---|---|---|---|
"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 | 节点 | relationships | 属性 | cypherStatements |
|---|---|---|---|---|
NULL |
2 |
1 |
5 |
":begin CREATE CONSTRAINT uniqueConstraint FOR (node:`UNIQUE IMPORT LABEL`) REQUIRE (node. |