提交 5bac55c4 编写于 作者: M Mark Needham

apoc.periodic usage docs

上级 4a8d3ca9
......@@ -47,5 +47,9 @@ apoc.export.cypher.graph(graph :: MAP?, file = :: STRING?, config = {} :: MAP?)
|cleanupStatements|STRING?
|===
[[usage-apoc.export.cypher.graph]]
== Usage Examples
include::partial$usage/apoc.export.cypher.graph.adoc[]
xref::export/cypher.adoc[More documentation of apoc.export.cypher.graph,role=more information]
......@@ -35,3 +35,7 @@ apoc.periodic.cancel(name :: STRING?) :: (name :: STRING?, delay :: INTEGER?, ra
|cancelled|BOOLEAN?
|===
[[usage-apoc.periodic.cancel]]
== Usage Examples
include::partial$usage/apoc.periodic.cancel.adoc[]
......@@ -40,5 +40,9 @@ apoc.periodic.commit(statement :: STRING?, params = {} :: MAP?) :: (updates :: I
|wasTerminated|BOOLEAN?
|===
[[usage-apoc.periodic.commit]]
== Usage Examples
include::partial$usage/apoc.periodic.commit.adoc[]
xref::graph-updates/periodic-execution.adoc#periodic-commit[More documentation of apoc.periodic.commit,role=more information]
......@@ -38,3 +38,7 @@ apoc.periodic.repeat(name :: STRING?, statement :: STRING?, rate :: INTEGER?, co
|cancelled|BOOLEAN?
|===
[[usage-apoc.periodic.repeat]]
== Usage Examples
include::partial$usage/apoc.periodic.repeat.adoc[]
......@@ -36,5 +36,9 @@ apoc.periodic.submit(name :: STRING?, statement :: STRING?) :: (name :: STRING?,
|cancelled|BOOLEAN?
|===
[[usage-apoc.periodic.submit]]
== Usage Examples
include::partial$usage/apoc.periodic.submit.adoc[]
xref::background-operations/periodic-background.adoc[More documentation of apoc.periodic.submit,role=more information]
The examples in this section are based on the following sample graph:
include::partial$createExportGraph.adoc[]
The Neo4j Browser visualization below shows the imported graph:
image::play-movies.png[title="Movies Graph Visualization"]
The `apoc.export.cypher.graph` procedure exports a xref::virtual/index.adoc[virtual graph] to a CSV file or as a stream.
The examples in this section are based on a virtual graph that contains all `PRODUCED` relationships and the nodes either side of that relationship.
We can then export that virtual graph as Cypher statements to `movies-producers.cypher`:
[source,cypher]
----
MATCH path = (:Person)-[produced:PRODUCED]->(:Movie)
WITH collect(path) AS paths
CALL apoc.graph.fromPaths(paths, "producers", {})
YIELD graph AS g
CALL apoc.export.cypher.graph(g, "movies-producers.cypher", {})
YIELD file, nodes, relationships, properties
RETURN file, nodes, relationships, properties;
----
.Results
[opts="header"]
|===
| file | nodes | relationships | properties
| "movies-producers.cypher" | 2 | 1 | 5
|===
.movies-producers.cypher
[source,cypher]
----
:begin
CREATE CONSTRAINT ON (node:`UNIQUE IMPORT LABEL`) ASSERT (node.`UNIQUE IMPORT ID`) IS UNIQUE;
:commit
:begin
UNWIND [{_id:31450, properties:{tagline:"Welcome to the Real World", title:"The Matrix", released:1999}}] AS row
CREATE (n:`UNIQUE IMPORT LABEL`{`UNIQUE IMPORT ID`: row._id}) SET n += row.properties SET n:Movie;
UNWIND [{_id:31457, properties:{born:1952, name:"Joel Silver"}}] AS row
CREATE (n:`UNIQUE IMPORT LABEL`{`UNIQUE IMPORT ID`: row._id}) SET n += row.properties SET n:Person;
:commit
:begin
UNWIND [{start: {_id:31457}, end: {_id:31450}, properties:{}}] AS row
MATCH (start:`UNIQUE IMPORT LABEL`{`UNIQUE IMPORT ID`: row.start._id})
MATCH (end:`UNIQUE IMPORT LABEL`{`UNIQUE IMPORT ID`: row.end._id})
CREATE (start)-[r:PRODUCED]->(end) SET r += row.properties;
:commit
:begin
MATCH (n:`UNIQUE IMPORT LABEL`) WITH n LIMIT 20000 REMOVE n:`UNIQUE IMPORT LABEL` REMOVE n.`UNIQUE IMPORT ID`;
:commit
:begin
DROP CONSTRAINT ON (node:`UNIQUE IMPORT LABEL`) ASSERT (node.`UNIQUE IMPORT ID`) IS UNIQUE;
:commit
----
The following query returns a streams of the virtual graph from static value storage to the `cypherStatements` column:
[source,cypher]
----
MATCH path = (:Person)-[produced:PRODUCED]->(:Movie)
WITH collect(path) AS paths
CALL apoc.graph.fromPaths(paths, "producers", {})
YIELD graph AS g
CALL apoc.export.cypher.graph(g, null, {stream: true})
YIELD file, nodes, relationships, properties, cypherStatements
RETURN file, nodes, relationships, properties, cypherStatements;
----
.Results
[opts="header"]
|===
| file | nodes | relationships | properties | cypherStatements
| NULL | 2 | 1 | 5 |
":begin
CREATE CONSTRAINT ON (node:`UNIQUE IMPORT LABEL`) ASSERT (node.`UNIQUE IMPORT ID`) IS UNIQUE;
:commit
:begin
UNWIND [{_id:31450, properties:{tagline:\"Welcome to the Real World\", title:\"The Matrix\", released:1999}}] AS row
CREATE (n:`UNIQUE IMPORT LABEL`{`UNIQUE IMPORT ID`: row._id}) SET n += row.properties SET n:Movie;
UNWIND [{_id:31457, properties:{born:1952, name:\"Joel Silver\"}}] AS row
CREATE (n:`UNIQUE IMPORT LABEL`{`UNIQUE IMPORT ID`: row._id}) SET n += row.properties SET n:Person;
:commit
:begin
UNWIND [{start: {_id:31457}, end: {_id:31450}, properties:{}}] AS row
MATCH (start:`UNIQUE IMPORT LABEL`{`UNIQUE IMPORT ID`: row.start._id})
MATCH (end:`UNIQUE IMPORT LABEL`{`UNIQUE IMPORT ID`: row.end._id})
CREATE (start)-[r:PRODUCED]->(end) SET r += row.properties;
:commit
:begin
MATCH (n:`UNIQUE IMPORT LABEL`) WITH n LIMIT 20000 REMOVE n:`UNIQUE IMPORT LABEL` REMOVE n.`UNIQUE IMPORT ID`;
:commit
:begin
DROP CONSTRAINT ON (node:`UNIQUE IMPORT LABEL`) ASSERT (node.`UNIQUE IMPORT ID`) IS UNIQUE;
:commit
"
|===
If we want to cancel the job submitted by the example in xref::overview/apoc.periodic/apoc.periodic.repeat.adoc[], we can run the following query:
[source,cypher]
----
CALL apoc.periodic.cancel("create-people");
----
.Results
[opts="header"]
|===
| name | delay | rate | done | cancelled
| "create-people" | 0 | 0 | TRUE | TRUE
|===
\ No newline at end of file
The examples in this section are based on the following sample graph:
[source,cypher]
----
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:
[source,cypher]
----
CALL apoc.periodic.commit(
"MATCH (person:Person)
WHERE exists(person.city)
WITH person limit $limit
MERGE (city:City {name:person.city})
MERGE (person)-[:LIVES_IN]->(city)
REMOVE person.city
RETURN count(*)",
{limit:1000});
----
.Results
[opts="header"]
|===
| 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:
[source,cypher]
----
MATCH (p:Person)
RETURN exists(p.city), count(*);
----
.Results
[opts="header"]
|===
| exists(p.city) | count(*)
| FALSE | 10000
|===
\ No newline at end of file
We can create 10 `Person` nodes every second by running the following query:
[source,cypher]
----
CALL apoc.periodic.repeat(
"create-people",
"UNWIND range(1,10) AS id CREATE (:Person {uuid: apoc.create.uuid()})",
1
);
----
.Results
[opts="header"]
|===
| name | delay | rate | done | cancelled
| "create-people" | 0 | 1 | FALSE | FALSE
|===
We can check how many nodes have been created by running the following query:
[source,cypher]
----
MATCH (:Person)
RETURN count(*) AS count;
----
.Results
[opts="header"]
|===
| count
| 110
|===
If we want to cancel this job, we can use the xref::overview/apoc.periodic/apoc.periodic.cancel.adoc[] procedure.
\ No newline at end of file
[source,cypher]
----
CALL apoc.periodic.submit(
"create-person",
"CREATE (:Person {name: 'Michael Hunger'})"
);
----
.Results
[opts="header"]
|===
| name | delay | rate | done | cancelled
| "create-person" | 0 | 0 | FALSE | FALSE
|===
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册