Running Cypher fragments

We can use Cypher as a safe, graph-aware, partially compiled scripting language within APOC.

Procedure Overview

The supported procedures are described in the table below:

Qualified Name Type Release

apoc.cypher.parallel

- executes fragments in parallel through a list defined in paramMap with a key keyList

Procedure

Apoc Extended

apoc.cypher.parallel2

- executes fragments in parallel batches through a list defined in paramMap with a key keyList

Procedure

Apoc Extended

apoc.cypher.mapParallel

apoc.cypher.mapParallel(fragment, params, list-to-parallelize) yield value - executes fragment in parallel batches with the list segments being assigned to _

Procedure

Apoc Extended

apoc.cypher.mapParallel2

apoc.cypher.mapParallel2(fragment, params, list-to-parallelize) yield value - executes fragment in parallel batches with the list segments being assigned to _

Procedure

Apoc Extended

Example: Fast Node-Counts by Label

We can quickly compute the number of nodes for a specific label using the count function, but only if that’s the only single thing in the query. For example:

MATCH (:Person) RETURN count(*);

We can also combine several with UNION ALL:

Works
MATCH (:Person) RETURN count(*)
UNION ALL
MATCH (:Movie) RETURN count(*);

But we can’t do the same thing using the WITH clause:

Doesn’t work
MATCH (:Person)
WITH count(*) as people
MATCH (:Movie) RETURN people, count(*) as movies;

This query will work out the count by iterating over all nodes, which is a very slow operation