Skip to content

Commit 2efdcd5

Browse files
committed
Add doc section on Pregel schema
1 parent f7e6e55 commit 2efdcd5

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

doc/asciidoc/algorithms/algorithms-pregel-api.adoc

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ Pregel node values are composite values.
6969
The `schema` describes the layout of that composite value.
7070
Each element of the schema can represent either a primitive long or double value as well as arrays of those.
7171
The element is uniquely identified by a key, which is used to access the value during the computation.
72+
Details on schema declaration can be found in the <<algorithms-pregel-api-schema, dedicated section>>.
7273

7374
The `init` method is called in the beginning of the first superstep of the Pregel computation and allows initializing node values.
7475
The interface defines an abstract `compute` method, which is called for each node in every superstep.
@@ -94,6 +95,57 @@ Check the <<algorithms-pregel-api-reducer, dedicated section>> for more details.
9495
The `applyRelationshipWeight` method can be used to modify the message based on a relationship property.
9596
If the input graph has no relationship properties, i.e. is unweighted, the method is skipped.
9697

98+
99+
[[algorithms-pregel-api-schema]]
100+
=== Pregel schema
101+
102+
In Pregel, each node is associated with a value which can be accessed from within the `compute` method.
103+
The value is typically used to represent intermediate computation state and eventually the computation result.
104+
To represent complex state, the node value is a composite type which consists of one or more named values.
105+
From the perspective of the `compute` function, each of these values can be accessed by its name.
106+
107+
When implementing a `PregelComputation`, one must override the `schema()` method.
108+
The following example shows the simplest possible example:
109+
110+
```
111+
PregelSchema schema() {
112+
return PregelSchema.Builder().add("foobar", ValueType.LONG).build();
113+
}
114+
```
115+
116+
The node value consists of a single value named `foobar` which is of type `long`.
117+
A node value can be of any GDS-supported type, i.e. `long`, `double`, `long[]`, `double[]` and `float[]`.
118+
119+
We can add an arbitrary number of values to the schema:
120+
121+
```
122+
PregelSchema schema() {
123+
return PregelSchema.Builder()
124+
.add("foobar", ValueType.LONG)
125+
.add("baz", ValueType.DOUBLE)
126+
.build();
127+
}
128+
```
129+
130+
Note, that each property consumes additional memory when executing the algorithm, which typically amounts to the number of nodes multiplied by the size of a single value (e.g. 64 Bit for a `long` or `double`).
131+
132+
The `add` method on the builder takes a third argument: `Visibility`.
133+
There are two possible values: `PUBLIC` (default) and `PRIVATE`.
134+
The visibility is considered during <<algorithms-pregel-api-procedure, procedure code generation>> to indicate if the value is part of the Pregel result or not.
135+
Any value that has visibility `PUBLIC` will be part of the computation result and included in the result of the procedure, e.g., streamed to the caller, mutated to the in-memory graph or written to the database.
136+
137+
The following shows a schema where one value is used as result and a second value is only used during computation:
138+
139+
```
140+
PregelSchema schema() {
141+
return PregelSchema.Builder()
142+
.add("result", ValueType.LONG, Visiblity.PUBLIC)
143+
.add("tempValue", ValueType.DOUBLE, Visiblity.PRIVATE)
144+
.build();
145+
}
146+
```
147+
148+
97149
[[algorithms-pregel-api-java-context]]
98150
=== Init context and compute context
99151

@@ -421,6 +473,10 @@ For the above Code snippet, we generate four procedures:
421473
* `custom.pregel.proc.write`
422474
* `custom.pregel.proc.write.estimate`
423475

476+
Note that by default, all values specified in the `PregelSchema` are included in the procedure results.
477+
To change that behaviour, we can change the visibility for individual parts of the schema.
478+
For more details, please refer to the <<algorithms-pregel-api-schema, dedicated documentation section>>.
479+
424480

425481
[[algorithms-pregel-api-plugin]]
426482
=== Building and installing a Neo4j plugin

0 commit comments

Comments
 (0)