|| apoc.periodic.commit - APOC 核心文档 - Neo4j 文档

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

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