You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: modules/tutorials/pages/accumulators-tutorial.adoc
+4-4Lines changed: 4 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,7 +10,7 @@ This short tutorial aims to shorten the learning curve of accumulator. Supposedl
10
10
== *What is an Accumulator?*
11
11
12
12
.The left box is a GSQL query with different accumulators being accumulated to. The right box shows the accumulator variables' final results.
13
-
image::https://lh3.googleusercontent.com/TZfcbUMlXsHvCYVO_ex9QqjlK823ybyrX7aQhv38j35fghJVpsJEtdFBjcjMj1x2pHfHbNUraTgbySriMRttCuNv359iOwnRHDVcRgPyAj9tQLappYXe6ManjmRS27eunYMc2rjG[Screenshots of the console showing accumulators and their results.]
13
+
image::accumulator-examples.png[Screenshots of the console showing accumulators and their results.]
14
14
15
15
An accumulator is a state variable in GSQL. Its state is mutable throughout the life cycle of a query. It has an initial value, and users can keep accumulating (using its "+=" built-in operator) new values into it. Each accumulator variable has a type. The type decides what semantics the declared accumulator will use to interpret the "+=" operation.
16
16
@@ -33,13 +33,13 @@ Global accumulator belongs to the entire query. Anywhere in a query, a statement
33
33
* *@* prefix is used for declaring local accumulator variable. It must be used with a vertex alias in a query block. E.g. `v.@cnt += 1,` where v is a vertex alias specified in a FROM clause of a SELECT-FROM-WHERE query block.
34
34
35
35
.A Social graph with 7 Person vertices and 7 Friendship edges connecting them.
Consider a toy social graph modeled by a person vertex type and a person-to-person friendship edge type shown in Figure 2. Below we write a query, which accepts a person, and does a 1-hop traversal from the input person to its neighbors. We use the @@global_edge_cnt accumulator to accumulate the total number of edges we traverse. And we use @vertex_cnt to write to the input person's each friend vertex an integer 1.
image::https://lh4.googleusercontent.com/P8rs2ukMPxoFJKk1x74FNkEa38PTg-KNcC9uJ_BN4ZRcYh5nhDTcjYD4_ajvgBe047-hLRaUbHfMXdEnn2nLzFQXGkRHRBbVb4lY399yZ_7If25HKtCAO0Hymn35Zm5fxdux_YtV[Figure 3. The top box shows a query that given a person, accumulate the edge count into @@global_edge_cnt. The bottom box shows that for each friend of the input person, we accumulate 1 into its @vertex_cnt.]
42
+
image::query-output-neighbors.png[Figure 3. The top box shows a query that given a person, accumulate the edge count into @@global_edge_cnt. The bottom box shows that for each friend of the input person, we accumulate 1 into its @vertex_cnt.]
43
43
44
44
As Figure 2 shows, Dan has 4 direct friends -- Tom, Kevin, Jenny, and Nancy, each of which holds a local accumulator @vertex_cnt. And the @@global_edge_cnt has value 4, reflecting the fact that for each edge, we have accumulated 1 into it.
0 commit comments