apoc.periodic.commit

Procedure

apoc.periodic.commit(statement STRING, params MAP<STRING, ANY>) - runs the given statement in separate batched transactions.

Signature

apoc.periodic.commit(statement :: STRING, params = {} :: MAP) :: (updates :: INTEGER, executions :: INTEGER, runtime :: INTEGER, batches :: INTEGER, failedBatches :: INTEGER, batchErrors :: MAP, failedCommits :: INTEGER, commitErrors :: MAP, wasTerminated :: BOOLEAN)

Input parameters

Name Type Default

statement

STRING

null

params

MAP

{}

Output parameters

Name Type

updates

INTEGER

executions

INTEGER

runtime

INTEGER

batches

INTEGER

failedBatches

INTEGER

batchErrors

MAP

failedCommits

INTEGER

commitErrors

MAP

wasTerminated

BOOLEAN

Usage Examples

The examples in this section are based on the following sample graph:

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];

If we want to convert the city property to a node, we can do this in batches of 1,000, by running the following query:

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});
Table 1. Results
updates executions runtime batches failedBatches batchErrors failedCommits commitErrors wasTerminated

10000

10

0

11

0

{}

0

{}

FALSE

We can check that the refactoring has been done by running the following query:

MATCH (p:Person)
RETURN p.city IS NOT NULL as exists, count(*);
Table 2. Results
exists count(*)

FALSE

10000