apoc.export.graphml.query
|
此过程不被认为是多线程安全运行的。因此,并行运行时不支持此过程。欲了解更多信息,请参阅 Cypher 手册 → 并行运行时。 |
语法 |
|
||
描述 |
将 Cypher 语句中给定的 |
||
输入参数 |
名称 |
类型 |
描述 |
|
|
用于收集导出数据的查询。 |
|
|
|
数据将导出到的文件名称。 |
|
|
|
|
|
返回参数 |
名称 |
类型 |
描述 |
|
|
数据导出的文件名称。 |
|
|
|
导出数据的摘要。 |
|
|
|
文件导出的格式。 |
|
|
|
导出的节点数量。 |
|
|
|
导出的关系数量。 |
|
|
|
导出的属性数量。 |
|
|
|
导出持续时间。 |
|
|
|
返回的行数。 |
|
|
|
导出运行时批处理的大小。 |
|
|
|
导出运行时批处理的次数。 |
|
|
|
导出是否成功运行。 |
|
|
|
导出返回的数据。 |
|
配置参数
此过程支持以下配置参数
| 参数 | 类型 | 默认值 | 描述 |
|---|---|---|---|
stream |
BOOLEAN |
false |
在查询结果中返回数据,而不是将其存储到文件中。 |
compression |
|
'NONE' |
允许获取二进制数据,可不压缩(值: |
timeoutSeconds |
INTEGER |
100 |
查询在超时前应运行的最长时间(秒)。 |
charset |
STRING |
'UTF_8' |
当前使用 JDK 中扩展 java.nio.Charset 的字符名称。例如: |
useTypes |
BOOLEAN |
false |
将类型添加到文件头。 |
format |
STRING |
'cypher-shell' |
导出格式。 |
source |
MAP |
false |
与 |
target |
MAP |
100 |
与 |
caption |
LIST<STRING> |
['name', 'title', 'label', 'id'] |
允许获取二进制数据,可不压缩(值: |
nodesOfRelationships |
BOOLEAN |
false |
在找到的节点之间添加缺失的关系。 |
使用示例
本节示例基于以下示例图
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.graphml.query 过程将 Cypher 查询结果导出到 CSV 文件或作为流输出。
以下查询将所有 DIRECTED 关系以及该关系两侧带有 Person 和 Movie 标签的节点导出到文件 movies-directed.graphml
WITH "MATCH path = (person:Person)-[directed:DIRECTED]->(movie)
RETURN person, directed, movie" AS query
CALL apoc.export.graphml.query(query, "movies-directed.graphml", {})
YIELD file, source, format, nodes, relationships, properties, time, rows, batchSize, batches, done, data
RETURN file, source, format, nodes, relationships, properties, time, rows, batchSize, batches, done, data;
| file | source | format | nodes | relationships | properties | time | rows | batchSize | batches | done | data |
|---|---|---|---|---|---|---|---|---|---|---|---|
"movies-directed.graphml" |
"statement: nodes(3), rels(2)" |
"graphml" |
3 |
2 |
7 |
2 |
5 |
-1 |
0 |
TRUE |
NULL |
以下显示 movies-directed.csv 的内容
<?xml version="1.0" encoding="UTF-8"?>
<graphml xmlns="http://graphml.graphdrawing.org/xmlns" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd">
<key id="born" for="node" attr.name="born"/>
<key id="name" for="node" attr.name="name"/>
<key id="tagline" for="node" attr.name="tagline"/>
<key id="label" for="node" attr.name="label"/>
<key id="title" for="node" attr.name="title"/>
<key id="released" for="node" attr.name="released"/>
<key id="label" for="edge" attr.name="label"/>
<graph id="G" edgedefault="directed">
<node id="n188" labels=":Movie"><data key="labels">:Movie</data><data key="title">The Matrix</data><data key="tagline">Welcome to the Real World</data><data key="released">1999</data></node>
<node id="n193" labels=":Person"><data key="labels">:Person</data><data key="born">1967</data><data key="name">Lilly Wachowski</data></node>
<node id="n194" labels=":Person"><data key="labels">:Person</data><data key="born">1965</data><data key="name">Lana Wachowski</data></node>
<edge id="e271" source="n193" target="n188" label="DIRECTED"><data key="label">DIRECTED</data></edge>
<edge id="e272" source="n194" target="n188" label="DIRECTED"><data key="label">DIRECTED</data></edge>
</graph>
</graphml>
以下查询返回所有 DIRECTED 关系以及该关系两侧带有 Person 和 Movie 标签的节点的流
WITH "MATCH path = (person:Person)-[directed:DIRECTED]->(movie)
RETURN person, directed, movie" AS query
CALL apoc.export.graphml.query(query, null, {stream: true})
YIELD file, nodes, relationships, properties, data
RETURN file, nodes, relationships, properties, data;
| file | nodes | relationships | properties | data |
|---|---|---|---|---|
NULL |
3 |
2 |
7 |
|