|| apoc.export.cypher.graph - APOC 核心文档 - Neo4j 文档

apoc.export.cypher.graph

此过程不被认为是多线程安全运行的。因此,并行运行时不支持它。更多信息,请参阅Cypher 手册 → 并行运行时

详情

语法

apoc.export.cypher.graph(graph, file [, config ]) :: (file, batches, source, format, nodes, relationships, properties, time, rows, batchSize, cypherStatements, nodeStatements, relationshipStatements, schemaStatements, cleanupStatements)

描述

将给定的图(包括索引)导出为 Cypher 语句到提供的文件(默认:Cypher Shell)。

输入参数

名称

类型

描述

graph

MAP

要导出的图。

file

STRING

数据将导出到的文件名称。

config

MAP

{ stream = false :: BOOLEAN, batchSize = 20000 :: INTEGER, bulkImport = false :: BOOLEAN, timeoutSeconds = 100 :: INTEGER, compression = 'None' :: STRING, charset = 'UTF_8' :: STRING, sampling = false :: BOOLEAN, samplingConfig :: MAP }。默认值为:{}

返回参数

名称

类型

描述

file

STRING

数据导出到的文件名称。

batches

INTEGER

导出运行时批处理的数量。

source

STRING

导出数据的摘要。

format

STRING

文件导出的格式。

nodes

INTEGER

导出节点的数量。

relationships

INTEGER

导出关系的数量。

properties

INTEGER

导出属性的数量。

time

INTEGER

导出的持续时间。

rows

INTEGER

返回的行数。

batchSize

INTEGER

导出运行时批处理的大小。

cypherStatements

ANY

执行的 Cypher 语句。

nodeStatements

ANY

执行的节点语句。

relationshipStatements

ANY

执行的关系语句。

schemaStatements

ANY

执行的模式语句。

cleanupStatements

ANY

执行的清理语句。

用法示例

本节中的示例基于以下示例图

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 可视化显示了导入的图

play movies
图 1. 电影图可视化

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

下一个示例需要以下设置

movies-producers.cypher
: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.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 "

© . This site is unofficial and not affiliated with Neo4j, Inc.