apoc.export.graphml.query过程
|
此过程不建议在多线程中运行,因此并行运行时(Parallel runtime)不支持该过程。有关更多信息,请参阅 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 | 节点 | relationships | 属性 | 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="https://w3org.cn/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 | 节点 | relationships | 属性 | data |
|---|---|---|---|---|
NULL |
3 |
2 |
7 |
|