apoc.periodic.commit

详细信息

语法

apoc.periodic.commit(statement [, params ]) :: (updates, executions, runtime, batches, failedBatches, batchErrors, failedCommits, commitErrors, wasTerminated)

描述

在单独的批处理事务中运行给定的语句。

输入参数

名称

类型

描述

statement

STRING

要执行的 Cypher 语句。

params

MAP

给定 Cypher 语句的参数。默认值为:{}

返回参数

名称

类型

描述

updates

INTEGER(整数)

更新的总数。

executions

INTEGER(整数)

执行的总数。

runtime

INTEGER(整数)

总耗时(纳秒)。

batches

INTEGER(整数)

运行的批次数。

failedBatches

INTEGER(整数)

失败的批次数。

batchErrors

MAP

从失败的批次中返回的错误。

failedCommits

INTEGER(整数)

提交失败的次数。

commitErrors

MAP

从提交失败中返回的错误。

wasTerminated

布尔值 (BOOLEAN)

作业是否被终止。

用法示例

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

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