Skip to content

Commit

Permalink
[NOID] Add apoc.cypher.runFile(s) procedures with READ mode version (#…
Browse files Browse the repository at this point in the history
…3950) (#3980)

* [NOID] Add apoc.cypher.runFile(s) procedures with READ mode version (#3950)

* Add apoc.cypher.runFile(s) procedures with READ mode version

* fixed CI tests

* changes review: renamed runReadFile* to runFile*ReadOnly, added column fileName, updated CypherExtended.collectError method

the collectError method had a message `error in file: fileName`, now is not needed since we have the column `fileName`

* [NOID] fix compile errors and code formatting

* [NOID] fix compile error and code formatting

* [NOID] fix test errors and formatting
  • Loading branch information
vga91 committed Mar 12, 2024
1 parent 1c03583 commit a98bc35
Show file tree
Hide file tree
Showing 23 changed files with 376 additions and 58 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
¦xref::overview/apoc.cypher/apoc.cypher.runFileReadOnly.adoc[apoc.cypher.runFileReadOnly icon:book[]] +

`apoc.cypher.runFileReadOnly(file or url,[{timeout:10,parameters:{}}])` - runs each `READ` statement in the file, all semicolon separated
¦label:procedure[]
¦label:apoc-extended[]
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
¦xref::overview/apoc.cypher/apoc.cypher.runFilesReadOnly.adoc[apoc.cypher.runFilesReadOnly icon:book[]] +

`apoc.cypher.runFilesReadOnly([files or urls],[{timeout:10,parameters:{}}]))` - runs each `READ` statement in the files, all semicolon separated
¦label:procedure[]
¦label:apoc-extended[]
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,21 @@ The available procedures and functions are described in the following table:
[separator=¦,opts=header,cols="5,1m,1m"]
|===
¦Qualified Name¦Type¦Release
include::example$generated-documentation/apoc.cypher.runFileReadOnly.adoc[]
include::example$generated-documentation/apoc.cypher.runFilesReadOnly.adoc[]
include::example$generated-documentation/apoc.cypher.runFile.adoc[]
include::example$generated-documentation/apoc.cypher.runFiles.adoc[]
include::example$generated-documentation/apoc.cypher.runSchemaFile.adoc[]
include::example$generated-documentation/apoc.cypher.runSchemaFiles.adoc[]
|===


[[run-cypher-scripts-read-operations]]
== Read Operations only
* `apoc.cypher.runFileReadOnly(file or url,[\{config}])`
* `apoc.cypher.runFilesReadOnly([files or urls],[\{config})])`


[[run-cypher-scripts-data-operations]]
== Data Operations only

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ apoc.cypher.runFile(file or url,[{statistics:true,timeout:10,parameters:{}}]) -

[source]
----
apoc.cypher.runFile(file :: STRING?, config = {} :: MAP?) :: (row :: INTEGER?, result :: MAP?)
apoc.cypher.runFile(file :: STRING?, config = {} :: MAP?) :: (row :: INTEGER?, result :: MAP?, fileName :: STRING?)
----

== Input parameters
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
= apoc.cypher.runFileReadOnly
:description: This section contains reference documentation for the apoc.cypher.runFileReadOnly procedure.

label:procedure[] label:apoc-extended[]

[.emphasis]
apoc.cypher.runFileReadOnly(file or url,[{statistics:true,timeout:10,parameters:{}}]) - runs each `READ` statement in the file, all semicolon separated - currently no schema operations

== Signature

[source]
----
apoc.cypher.runFileReadOnly(file :: STRING?, config = {} :: MAP?) :: (row :: INTEGER?, result :: MAP?, fileName :: STRING?)
----

== Input parameters
[.procedures, opts=header]
|===
|Name|Type|Default
|file|STRING?|null
|config|MAP?|{}
|===

== Config parameters
include::partial$usage/config/apoc.cypher.runExtended.adoc[]

== Output parameters
[.procedures, opts=header]
|===
|Name|Type
|row|INTEGER?
|result|MAP?
|===

== Reading from a file
include::../../import/includes/enableFileImport.adoc[]

[[usage-apoc.cypher.runFileReadOnly]]
== Usage Examples
include::partial$usage/apoc.cypher.runFileReadOnly.adoc[]

xref::cypher-execution/index.adoc[More documentation of apoc.cypher.runFileReadOnly,role=more information]
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ apoc.cypher.runFiles([files or urls],[{statistics:true,timeout:10,parameters:{}}

[source]
----
apoc.cypher.runFiles(file :: LIST? OF STRING?, config = {} :: MAP?) :: (row :: INTEGER?, result :: MAP?)
apoc.cypher.runFiles(file :: LIST? OF STRING?, config = {} :: MAP?) :: (row :: INTEGER?, result :: MAP?, fileName :: STRING?)
----

== Input parameters
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
= apoc.cypher.runFilesReadOnly
:description: This section contains reference documentation for the apoc.cypher.runFilesReadOnly procedure.

label:procedure[] label:apoc-extended[]

[.emphasis]
apoc.cypher.runFilesReadOnly([files or urls],[{timeout:10,parameters:{}}])) - runs each `READ` statement in the files, all semicolon separated

== Signature

[source]
----
apoc.cypher.runFilesReadOnly(file :: LIST? OF STRING?, config = {} :: MAP?) :: (row :: INTEGER?, result :: MAP?, fileName :: STRING?)
----

== Input parameters
[.procedures, opts=header]
|===
|Name|Type|Default
|file|LIST? OF STRING?|null
|config|MAP?|{}
|===

== Config parameters
include::partial$usage/config/apoc.cypher.runExtended.adoc[]

== Output parameters
[.procedures, opts=header]
|===
|Name|Type
|row|INTEGER?
|result|MAP?
|===

== Reading from a file
include::../../import/includes/enableFileImport.adoc[]

[[usage-apoc.cypher.runFilesReadOnly]]
== Usage Examples
include::partial$usage/apoc.cypher.runFilesReadOnly.adoc[]

xref::cypher-execution/index.adoc[More documentation of apoc.cypher.runFilesReadOnly,role=more information]

Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ apoc.cypher.runSchemaFile(file or url,[{statistics:true,timeout:10}]) - allows o

[source]
----
apoc.cypher.runSchemaFile(file :: STRING?, config = {} :: MAP?) :: (row :: INTEGER?, result :: MAP?)
apoc.cypher.runSchemaFile(file :: STRING?, config = {} :: MAP?) :: (row :: INTEGER?, result :: MAP?, fileName :: STRING?)
----

== Input parameters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ apoc.cypher.runSchemaFiles([files or urls],{statistics:true,timeout:10}) - allow

[source]
----
apoc.cypher.runSchemaFiles(file :: LIST? OF STRING?, config = {} :: MAP?) :: (row :: INTEGER?, result :: MAP?)
apoc.cypher.runSchemaFiles(file :: LIST? OF STRING?, config = {} :: MAP?) :: (row :: INTEGER?, result :: MAP?, fileName :: STRING?)
----

== Input parameters
Expand Down
10 changes: 10 additions & 0 deletions docs/asciidoc/modules/ROOT/pages/overview/apoc.cypher/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@ apoc.cypher.runFile(file or url,[{statistics:true,timeout:10,parameters:{}}]) -
apoc.cypher.runFiles([files or urls],[{statistics:true,timeout:10,parameters:{}}])) - runs each statement in the files, all semicolon separated
|label:procedure[]
|label:apoc-full[]
|xref::overview/apoc.cypher/apoc.cypher.runFileReadOnly.adoc[apoc.cypher.runFileReadOnly icon:book[]]

apoc.cypher.runFileReadOnly(file or url,[{timeout:10,parameters:{}}]) - runs each `READ` statement in the file, all semicolon separated
|label:procedure[]
|label:apoc-full[]
|xref::overview/apoc.cypher/apoc.cypher.runFilesReadOnly.adoc[apoc.cypher.runFilesReadOnly icon:book[]]

apoc.cypher.runFilesReadOnly([files or urls],[{timeout:10,parameters:{}}])) - runs each `READ` statement in the files, all semicolon separated
|label:procedure[]
|label:apoc-full[]
|xref::overview/apoc.cypher/apoc.cypher.runMany.adoc[apoc.cypher.runMany icon:book[]]

apoc.cypher.runMany('cypher;\nstatements;', $params, [{statistics:true,timeout:10}]) - runs each semicolon separated statement and returns summary - currently no schema operations
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -942,6 +942,16 @@ apoc.cypher.runFile(file or url,[{statistics:true,timeout:10,parameters:{}}]) -
apoc.cypher.runFiles([files or urls],[{statistics:true,timeout:10,parameters:{}}])) - runs each statement in the files, all semicolon separated
|label:procedure[]
|label:apoc-full[]
|xref::overview/apoc.cypher/apoc.cypher.runFileReadOnly.adoc[apoc.cypher.runFileReadOnly icon:book[]]

apoc.cypher.runFileReadOnly(file or url,[{timeout:10,parameters:{}}]) - runs each `READ` statement in the file, all semicolon separated
|label:procedure[]
|label:apoc-full[]
|xref::overview/apoc.cypher/apoc.cypher.runFilesReadOnly.adoc[apoc.cypher.runFilesReadOnly icon:book[]]

apoc.cypher.runFilesReadOnly([files or urls],[{timeout:10,parameters:{}}])) - runs each `READ` statement in the files, all semicolon separated
|label:procedure[]
|label:apoc-full[]
|xref::overview/apoc.cypher/apoc.cypher.runMany.adoc[apoc.cypher.runMany icon:book[]]

apoc.cypher.runMany('cypher;\nstatements;', $params, [{statistics:true,timeout:10}]) - runs each semicolon separated statement and returns summary - currently no schema operations
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ This file is generated by DocsTest, so don't change it!
*** xref::overview/apoc.cypher/apoc.cypher.run.adoc[]
*** xref::overview/apoc.cypher/apoc.cypher.runFile.adoc[]
*** xref::overview/apoc.cypher/apoc.cypher.runFiles.adoc[]
*** xref::overview/apoc.cypher/apoc.cypher.runFileReadOnly.adoc[]
*** xref::overview/apoc.cypher/apoc.cypher.runFilesReadOnly.adoc[]
*** xref::overview/apoc.cypher/apoc.cypher.runMany.adoc[]
*** xref::overview/apoc.cypher/apoc.cypher.runManyReadOnly.adoc[]
*** xref::overview/apoc.cypher/apoc.cypher.runSchema.adoc[]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ CALL apoc.cypher.runFile("create_delete.cypher");
.Results
[opts="header", cols="1,5"]
|===
| row | result
| -1 | {constraintsRemoved: 0, indexesRemoved: 0, nodesCreated: 1, rows: 0, propertiesSet: 1, labelsRemoved: 0, relationshipsDeleted: 0, constraintsAdded: 0, nodesDeleted: 0, indexesAdded: 0, labelsAdded: 1, relationshipsCreated: 0, time: 0}
| -1 | {constraintsRemoved: 0, indexesRemoved: 0, nodesCreated: 0, rows: 0, propertiesSet: 0, labelsRemoved: 0, relationshipsDeleted: 0, constraintsAdded: 0, nodesDeleted: 1, indexesAdded: 0, labelsAdded: 0, relationshipsCreated: 0, time: 0}
| row | fileName | result
| -1 | create_delete.cypher | {constraintsRemoved: 0, indexesRemoved: 0, nodesCreated: 1, rows: 0, propertiesSet: 1, labelsRemoved: 0, relationshipsDeleted: 0, constraintsAdded: 0, nodesDeleted: 0, indexesAdded: 0, labelsAdded: 1, relationshipsCreated: 0, time: 0}
| -1 | create_delete.cypher | {constraintsRemoved: 0, indexesRemoved: 0, nodesCreated: 0, rows: 0, propertiesSet: 0, labelsRemoved: 0, relationshipsDeleted: 0, constraintsAdded: 0, nodesDeleted: 1, indexesAdded: 0, labelsAdded: 0, relationshipsCreated: 0, time: 0}
|===

If we don't want to see statistics for each Cypher statement, we can set `statistics: false`:
Expand All @@ -35,5 +35,5 @@ CALL apoc.cypher.runFile("create_delete.cypher", {statistics: false});
.Results
[opts="header", cols="1,5"]
|===
| row | result
| row | fileName | result
|===
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
Given this dataset:

[source, cypher]
----
CREATE (:ReturnQuery {id:1}), (:ReturnQuery {id:2}), (:ReturnQuery {id:3});
CREATE (n:Other {id: 4});
----

and this file, located in `.$NEO4J_HOME/import`:

.match.cypher
[source, cypher]
----
MATCH (n:ReturnQuery) RETURN n;
MATCH (n:Other) RETURN n;
----

we can run the Cypher commands in `match.cypher`, by running the following query:

[source,cypher]
----
CALL apoc.cypher.runFileReadOnly("match.cypher");
----

.Results
[opts="header", cols="1,5"]
|===
| row | fileName | result
| 0 | match.cypher | {"n":{"identity":1,"labels":["ReturnQuery"],"properties":{"id":1},"elementId":"..."}}
| 1 | match.cypher | {"n":{"identity":2,"labels":["ReturnQuery"],"properties":{"id":2},"elementId":"..."}}
| 2 | match.cypher | {"n":{"identity":3,"labels":["ReturnQuery"],"properties":{"id":3},"elementId":"..."}}
| 0 | match.cypher | {"n":{"identity":4,"labels":["Other"],"properties":{"id":4},"elementId":"..."}}
|===
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ CALL apoc.cypher.runFiles(["create.cypher", "update.cypher"]);
.Results
[opts="header", cols="1,5"]
|===
| row | result
| -1 | {constraintsRemoved: 0, indexesRemoved: 0, nodesCreated: 1, rows: 0, propertiesSet: 1, labelsRemoved: 0, relationshipsDeleted: 0, constraintsAdded: 0, nodesDeleted: 0, indexesAdded: 0, labelsAdded: 1, relationshipsCreated: 0, time: 0}
| -1 | {constraintsRemoved: 0, indexesRemoved: 0, nodesCreated: 0, rows: 0, propertiesSet: 1, labelsRemoved: 0, relationshipsDeleted: 0, constraintsAdded: 0, nodesDeleted: 0, indexesAdded: 0, labelsAdded: 0, relationshipsCreated: 0, time: 0}
| row | fileName | result
| -1 | create.cypher | {constraintsRemoved: 0, indexesRemoved: 0, nodesCreated: 1, rows: 0, propertiesSet: 1, labelsRemoved: 0, relationshipsDeleted: 0, constraintsAdded: 0, nodesDeleted: 0, indexesAdded: 0, labelsAdded: 1, relationshipsCreated: 0, time: 0}
| -1 | update.cypher | {constraintsRemoved: 0, indexesRemoved: 0, nodesCreated: 0, rows: 0, propertiesSet: 1, labelsRemoved: 0, relationshipsDeleted: 0, constraintsAdded: 0, nodesDeleted: 0, indexesAdded: 0, labelsAdded: 0, relationshipsCreated: 0, time: 0}
|===

We can see the contents of the database, by running the following query:
Expand Down Expand Up @@ -53,5 +53,5 @@ CALL apoc.cypher.runFiles(["create.cypher", "update.cypher"], {statistics: false
.Results
[opts="header", cols="1,5"]
|===
| row | result
| row | fileName | result
|===
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
Given this dataset:

[source, cypher]
----
CREATE (:ReturnQuery {id:1}), (:ReturnQuery {id:2}), (:ReturnQuery {id:3});
CREATE (n:Other {id: 4});
CREATE (n:SecondFile {id: 5});
----


and the following files, located in `.$NEO4J_HOME/import`:

.match_first.cypher
[source, cypher]
----
MATCH (n:ReturnQuery) RETURN n;
MATCH (n:Other) RETURN n;
----

.match_second.cypher
[source, cypher]
----
MATCH (n:SecondFile) RETURN n
----

we can run the Cypher commands in `create.cypher` and `update.cypher`, by running the following query:

[source,cypher]
----
CALL apoc.cypher.runFilesReadOnly(["match_first.cypher", "match_second.cypher"]);
----

.Results
[opts="header", cols="1,1,5"]
|===
| row | fileName | result
| 0 | .match_first.cypher | {"n":{"identity":1,"labels":["ReturnQuery"],"properties":{"id":1},"elementId":"..."}}
| 1 | .match_first.cypher | {"n":{"identity":2,"labels":["ReturnQuery"],"properties":{"id":2},"elementId":"..."}}
| 2 | .match_first.cypher | {"n":{"identity":3,"labels":["ReturnQuery"],"properties":{"id":3},"elementId":"..."}}
| 0 | .match_first.cypher | {"n":{"identity":4,"labels":["Other"],"properties":{"id":4},"elementId":"..."}}
| 0 | .match_second.cypher| {"n":{"identity":5,"labels":["SecondFile"],"properties":{"id":5},"elementId":"..."}}
|===

Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ CALL apoc.cypher.runSchemaFile("schema.cypher", {statistics: false});
.Results
[opts="header", cols="1,5"]
|===
| row | result
| row | fileName | result
|===
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ CALL apoc.cypher.runSchemaFiles(["createConstraint.cypher", "dropConstraint.cyph
.Results
[opts="header", cols="1,5"]
|===
| row | result
| -1 | {constraintsRemoved: 0, indexesRemoved: 0, nodesCreated: 0, rows: 0, propertiesSet: 0, labelsRemoved: 0, relationshipsDeleted: 0, constraintsAdded: 1, nodesDeleted: 0, indexesAdded: 0, labelsAdded: 0, relationshipsCreated: 0, time: 0}
| -1 | {constraintsRemoved: 1, indexesRemoved: 0, nodesCreated: 0, rows: 0, propertiesSet: 0, labelsRemoved: 0, relationshipsDeleted: 0, constraintsAdded: 0, nodesDeleted: 0, indexesAdded: 0, labelsAdded: 0, relationshipsCreated: 0, time: 0}
| row | fileName | result
| -1 | createConstraint.cypher | {constraintsRemoved: 0, indexesRemoved: 0, nodesCreated: 0, rows: 0, propertiesSet: 0, labelsRemoved: 0, relationshipsDeleted: 0, constraintsAdded: 1, nodesDeleted: 0, indexesAdded: 0, labelsAdded: 0, relationshipsCreated: 0, time: 0}
| -1 | dropConstraint.cypher | {constraintsRemoved: 1, indexesRemoved: 0, nodesCreated: 0, rows: 0, propertiesSet: 0, labelsRemoved: 0, relationshipsDeleted: 0, constraintsAdded: 0, nodesDeleted: 0, indexesAdded: 0, labelsAdded: 0, relationshipsCreated: 0, time: 0}
|===

If we don't want to see statistics for each Cypher statement, we can set `statistics: false`:
Expand All @@ -37,5 +37,5 @@ CALL apoc.cypher.runSchemaFiles(["createConstraint.cypher", "dropConstraint.cyph
.Results
[opts="header", cols="1,5"]
|===
| row | result
| row | fileName | result
|===

0 comments on commit a98bc35

Please sign in to comment.