Skip to content

Commit c6a9dca

Browse files
authored
[NOID] Fixes #3401: APOC Custom Procedures/Function new procedures working with Cluster (#3943) (#4030)
* [NOID] Fixes #3401: APOC Custom Procedures/Function new procedures working with Cluster (#3943) * Fixes #3401: APOC Custom Procedures/Function new procedures working with Cluster * removed unused imports * changed writeTransaction to executeWrite * [NOID] code formatting
1 parent da4c856 commit c6a9dca

36 files changed

+3777
-232
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
¦xref::overview/apoc.custom/apoc.custom.list.adoc[apoc.custom.list icon:book[]] +
2+
3+
`apoc.custom.list()` - provide a list of custom procedures/function registered
4+
¦label:procedure[]
5+
¦label:apoc-extended[]
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
¦xref::overview/apoc.custom/apoc.custom.list.adoc[apoc.custom.list icon:book[]] +
2+
3+
`apoc.custom.list()` - provide a list of custom procedures/function registered
4+
¦label:procedure[]
5+
¦label:apoc-extended[]
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
¦xref::overview/apoc.custom/apoc.custom.list.adoc[apoc.custom.list icon:book[]] +
2+
3+
`apoc.custom.list()` - provide a list of custom procedures/function registered
4+
¦label:procedure[]
5+
¦label:apoc-extended[]
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
¦xref::overview/apoc.custom/apoc.custom.list.adoc[apoc.custom.list icon:book[]] +
2+
3+
`apoc.custom.list()` - provide a list of custom procedures/function registered
4+
¦label:procedure[]
5+
¦label:apoc-extended[]
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
¦xref::overview/apoc.custom/apoc.custom.list.adoc[apoc.custom.list icon:book[]] +
2+
3+
`apoc.custom.list()` - provide a list of custom procedures/function registered
4+
¦label:procedure[]
5+
¦label:apoc-extended[]
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
¦xref::overview/apoc.custom/apoc.custom.list.adoc[apoc.custom.list icon:book[]] +
2+
3+
`apoc.custom.list()` - provide a list of custom procedures/function registered
4+
¦label:procedure[]
5+
¦label:apoc-extended[]

docs/asciidoc/modules/ROOT/pages/cypher-execution/cypher-based-procedures-functions.adoc

Lines changed: 60 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,44 @@
55

66

77

8-
I wanted for a long time to be able to register Cypher statements as proper procedures and functions, so that they become callable in a standalone way.
8+
include::partial$systemdbonly.note.adoc[]
99

10-
You can achieve that with the `apoc.custom.declareProcedure` and `apoc.custom.declareFunction` procedure calls.
11-
Those register a given Cypher statement, prefixed with the `custom.*` namespace, overriding potentially existing ones, so you can redefine them as needed.
10+
[WARNING]
11+
====
12+
Installing, updating or removing a custom Cypher statement is an eventually consistent operation.
13+
Therefore, they are not immediately added/updated/removed,
14+
but they have a refresh rate handled by the Apoc configuration `apoc.custom.procedures.refresh=<MILLISECONDS>`.
15+
16+
In case of a cluster environment,
17+
the `apoc.custom.procedures.refresh` also replicate the procedures/functions to each cluster member.
18+
====
19+
20+
.Available procedures
21+
[separator=¦,opts=header,cols="5,1m,1m"]
22+
|===
23+
¦Qualified Name¦Type¦Release
24+
include::example$generated-documentation/apoc.custom.dropAll.adoc[]
25+
include::example$generated-documentation/apoc.custom.dropFunction.adoc[]
26+
include::example$generated-documentation/apoc.custom.dropProcedure.adoc[]
27+
include::example$generated-documentation/apoc.custom.installFunction.adoc[]
28+
include::example$generated-documentation/apoc.custom.installProcedure.adoc[]
29+
include::example$generated-documentation/apoc.custom.list.adoc[]
30+
include::example$generated-documentation/apoc.custom.show.adoc[]
31+
|===
32+
33+
34+
== Overview
1235

13-
NOTE: APOC provides also xref::overview/apoc.custom/apoc.custom.asFunction.adoc[apoc.custom.asFunction] and xref::overview/apoc.custom/apoc.custom.asProcedure.adoc[apoc.custom.asProcedure] procedures,
14-
but they have been deprecated in favor of `apoc.custom.declare*`s.
36+
I wanted for a long time to be able to register Cypher statements as proper procedures and functions, so that they become callable in a standalone way.
1537

38+
You can achieve that with the `apoc.custom.installProcedure` and `apoc.custom.installFunction` procedure calls.
39+
Those register a given Cypher statement, prefixed with the `custom.*` namespace, overriding potentially existing ones, so you can redefine them as needed.
1640

17-
The first parameter of the `apoc.custom.declareProcedure` and `apoc.custom.declareFunction` procedures,
41+
The first parameter of the `apoc.custom.installProcedure` and `apoc.custom.installFunction` procedures,
1842
is the signature of the procedure/function you want to create.
19-
This looks similar to the `signature` results returned by the `SHOW PROCEDURES YIELD signature` and `SHOW FUNCTIONS YIELD signature` cypher commands,
20-
that is:
43+
44+
This looks similar to the `signature` results returned by the `SHOW PROCEDURES YIELD signature`, `SHOW FUNCTIONS YIELD signature` cypher commands, or by the `CALL apoc.help('<fun_or_procedure_name>') YIELD signature` procedure, just without the `?`.
45+
That is:
2146
- for a procedure: `nameProcedure(firstParam = defaultValue :: typeParam , secondParam = defaultValue :: typeParam, ....) :: (firstResult :: typeResult, secondResult :: typeResult, ... )`
2247
- for a function: `nameFunction(firstParam = defaultValue :: typeParam , secondParam = defaultValue :: typeParam, ....) :: typeResult`
2348

@@ -49,9 +74,9 @@ The type names are what you would expect and see in outputs of `dbms.procedures`
4974
The default values are parsed as JSON.
5075

5176
.Type Names
52-
The `typeParam` and `typeResult` in the signature parameter are what you would expect to see in outputs of `SHOW PROCEDURES`, `SHOW FUNCTIONS` or `CALL apoc.help('')`, just without the final `?`.
53-
The following values are supported:
54-
* FLOAT, DOUBLE, INT, INTEGER, NUMBER, LONG
77+
The `typeParam` and `typeResult` in the signature parameter can be one of the following values:
78+
79+
* FLOAT, DOUBLE, INT, INTEGER, INTEGER | FLOAT, NUMBER, LONG
5580
* TEXT, STRING
5681
* BOOL, BOOLEAN
5782
* POINT, GEO, GEOMETRY
@@ -66,21 +91,24 @@ The following values are supported:
6691
NOTE: If you override procedures or functions you might need to call `call db.clearQueryCaches()` as lookups to internal id's are kept in compiled query plans.
6792

6893

69-
== Custom Procedures with `apoc.custom.declareProcedure`
94+
The following examples assume that we are on the `neo4j` database,
95+
and we want to create the custom procedures/function in that database.
96+
97+
== Custom Procedures with `apoc.custom.installProcedure`
7098

71-
include::partial$usage/apoc.custom.declareProcedure.adoc[]
99+
include::partial$usage/apoc.custom.installProcedure.adoc[]
72100

73-
== Custom Functions with `apoc.custom.declareFunction`
101+
== Custom Functions with `apoc.custom.installFunction`
74102

75-
include::partial$usage/apoc.custom.declareFunction.adoc[]
103+
include::partial$usage/apoc.custom.installFunction.adoc[]
76104

77105

78106
== List of registered procedures/function with `apoc.custom.list`
79107

80-
The procedure `apoc.custom.list` provide a list of all registered procedures/function via
81-
`apoc.custom.declareProcedure` and `apoc.custom.declareFunction`, `apoc.custom.asProcedure` and `apoc.custom.asFunction`.
108+
The procedure `apoc.custom.list` provide a list of all registered procedures/function via
109+
`apoc.custom.installProcedure` and `apoc.custom.installFunction`
82110

83-
Given the this call:
111+
Given this call:
84112

85113
[source,cypher]
86114
----
@@ -92,21 +120,22 @@ The output will look like the following table:
92120
[%autowidth,opts=header]
93121
|===
94122
| type | name | description | mode | statement | inputs | outputs | forceSingle
95-
| "function" | "answer" | <null> | <null> | "RETURN $input as answer" | [["input","number"]] | "long" | false
96-
| "procedure" | "answer" | "Procedure that answer to the Ultimate Question of Life, the Universe, and Everything" | "read" | "RETURN $input as answer" | [["input","int","42"]] | [["answer","number"]] | <null>
123+
| "function" | "answer" | <null> | <null> | "RETURN $input as answer" | [["input","integer \| float"]] | "long" | false
124+
| "procedure" | "answer" | "Procedure that answer to the Ultimate Question of Life, the Universe, and Everything" | "read" | "RETURN $input as answer" | [["input","int","42"]] | [["answer","integer \| float"]] | <null>
97125
|===
98126

99127

100-
== Remove a procedure `apoc.custom.removeProcedure`
128+
== Remove a procedure `apoc.custom.dropProcedure`
101129

102-
The procedure `apoc.custom.removeProcedure` allows to delete the targeted custom procedure.
130+
The procedure `apoc.custom.dropProcedure` allows to delete the targeted custom procedure, from a specific database (with `neo4j` as a default),
131+
*after a time defined by the configuration `apoc.custom.procedures.refresh`*.
103132

104133

105-
Given the this call:
134+
Given this call:
106135

107136
[source,cypher]
108137
----
109-
CALL apoc.custom.removeProcedure(<name>)
138+
CALL apoc.custom.dropProcedure(<name>, <databaseName>)
110139
----
111140

112141
Fields:
@@ -115,19 +144,21 @@ Fields:
115144
|===
116145
| argument | description
117146
| name | the procedure name
147+
| databaseName | the database name (default: `neo4j`)
118148
|===
119149

120150

121-
== Remove a procedure `apoc.custom.removeFunction`
151+
== Remove a procedure `apoc.custom.dropFunction`
122152

123-
The procedure `apoc.custom.removeFunction` allows to delete the targeted custom function.
153+
The procedure `apoc.custom.dropFunction` allows to delete the targeted custom function, from a specific database (with `neo4j` as a default),
154+
*after a time defined by the configuration `apoc.custom.procedures.refresh`*.
124155

125156

126-
Given the this call:
157+
Given this call:
127158

128159
[source,cypher]
129160
----
130-
CALL apoc.custom.removeFunction(<name>)
161+
CALL apoc.custom.dropFunction(<name>)
131162
----
132163

133164
Fields:
@@ -136,19 +167,10 @@ Fields:
136167
|===
137168
| argument | description
138169
| name | the function name
170+
| databaseName | the database name (default: `neo4j`)
139171
|===
140172

141173

142-
== How to manage procedure/function replication in a Causal Cluster
143-
144-
In order to replicate the procedure/function in a cluster environment you can tune the following parameters:
145-
146-
[%autowidth,opts=header]
147-
|===
148-
| name | type | description
149-
| `apoc.custom.procedures.refresh` | long (default `60000`) | the refresh time that allows replicating the procedure/function
150-
changes to each cluster member
151-
|===
152174

153175
=== Export metadata
154176

0 commit comments

Comments
 (0)