apoc.periodic.commit
语法 |
|
||
描述 |
在单独的批处理事务中运行给定语句。 |
||
输入参数 |
名称 |
类型 |
描述 |
|
|
要运行的 Cypher 语句。 |
|
|
|
给定 Cypher 语句的参数。默认值为: |
|
返回参数 |
名称 |
类型 |
描述 |
|
|
总更新次数。 |
|
|
|
总执行次数。 |
|
|
|
总运行时长(纳秒)。 |
|
|
|
运行批次数量。 |
|
|
|
失败批次数量。 |
|
|
|
失败批次返回的错误。 |
|
|
|
失败提交数量。 |
|
|
|
失败提交返回的错误。 |
|
|
|
任务是否已终止。 |
|
使用示例
本节示例基于以下示例图
WITH ["London", "Manchester", "Cardiff", "Birmingham", "Coventry", "Edinburgh"] AS cities
UNWIND range(1, 10000) AS id
MERGE (p:Person {id: id})
WITH cities, p, toInteger(rand() * size(cities)) AS index
SET p.city = cities[index];
如果我们要将 city 属性转换为节点,可以通过运行以下查询,以 1,000 为一批进行此操作。
CALL apoc.periodic.commit(
"MATCH (person:Person)
WHERE person.city IS NOT NULL
WITH person limit $limit
MERGE (city:City {name:person.city})
MERGE (person)-[:LIVES_IN]->(city)
REMOVE person.city
RETURN count(*)",
{limit:1000});
| updates | executions | runtime | batches | failedBatches | batchErrors | failedCommits | commitErrors | wasTerminated |
|---|---|---|---|---|---|---|---|---|
10000 |
10 |
0 |
11 |
0 |
{} |
0 |
{} |
FALSE |
我们可以通过运行以下查询来检查重构是否已完成。
MATCH (p:Person)
RETURN p.city IS NOT NULL as exists, count(*);
| exists | count(*) |
|---|---|
FALSE |
10000 |