apoc.periodic.commit

Details

Syntax

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

Description

Runs the given statement in separate batched transactions.

Input arguments

Name

Type

Description

statement

STRING

The Cypher statement to run.

params

MAP

The parameters for the given Cypher statement. The default is: {}.

Return arguments

Name

Type

Description

updates

INTEGER

The total number of updates.

executions

INTEGER

The total number of executions.

runtime

INTEGER

The total time taken in nanoseconds.

batches

INTEGER

The number of run batches.

failedBatches

INTEGER

The number of failed batches.

batchErrors

MAP

Errors returned from the failed batches.

failedCommits

INTEGER

The number of failed commits.

commitErrors

MAP

Errors returned from the failed commits.

wasTerminated

BOOLEAN

If the job was terminated.

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});
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(*);
Results
exists count(*)

FALSE

10000