SumAgg¶
A SumAgg aggregator value variable (SumAgg<T>) maintains the aggregated result of all inputs, where T represents the data type of the input values. The aggregation behavior depends on the specified data type:
- Numeric types (
INT8,INT16,INT32,INT64,FLOAT,DOUBLE): Calculates the mathematical sum of the input values. - String type (
STRING): Concatenates the input strings in the order they are processed. Note that there is no implicit delimiter (such as a space) added between the concatenated strings; you must explicitly include delimiters if needed.
Declaration syntax¶
- sum_agg_declaration
sum_agg_declaration ::=
'NODE'? 'VALUE' aggregator_value_variable 'SumAgg' '<' ('INT8'|'INT16'|'INT32'|'INT64'|'FLOAT'|'DOUBLE'|'STRING') '>' '=' value_expression
For information about the parameters in the declaration syntax, see Parameters.
Initial value¶
As indicated in the declaration syntax, an initial value is required during declaration.
Input type and supported operations¶
The input type must be T, which is specified during declaration.
Both assignment and aggregation operations are supported.
Return type¶
SumAgg<T> -> T
The return type is the same as the type T specified during declaration.
Examples¶
The following examples are based on the temporary graph #movie_temporary_graph created in CREATE TEMPORARY GRAPH.
Global SumAgg aggregator value variables¶
'''
USE #movie_temporary_graph {
VALUE global_sum_int SumAgg<INT> = 0
VALUE global_sum_double SumAgg<DOUBLE> = 0.0
VALUE global_sum_string SumAgg<STRING> = ""
-- INT type: Accumulate integer values
SET @global_sum_int += 3 // sum: 3 (0 + 3)
SET @global_sum_int += 4 // sum: 7 (3 + 4)
SET @global_sum_int += 5 // sum: 12 (7 + 5)
-- DOUBLE type: Accumulate floating-point values
SET @global_sum_double += 3.14 // sum: 3.14 (0.0 + 3.14)
SET @global_sum_double += 4.56 // sum: 7.7 (3.14 + 4.56)
SET @global_sum_double += 5.3 // sum: 13.0 (7.7 + 5.3)
-- STRING type: Concatenate strings
SET @global_sum_string += "Hello" // sum: "Hello" ("" + "Hello")
SET @global_sum_string += " " // sum: "Hello " ("Hello" + " ")
SET @global_sum_string += "World" // sum: "Hello World" ("Hello " + "World")
RETURN @global_sum_int, @global_sum_double, @global_sum_string
}
'''
Return:
+-----------------+--------------------+--------------------+
| @global_sum_int | @global_sum_double | @global_sum_string |
+-----------------+--------------------+--------------------+
| 12 | 13.0 | Hello World |
+-----------------+--------------------+--------------------+
Node-attached SumAgg aggregator value variables¶
'''
USE #movie_temporary_graph {
NODE VALUE node_sum SumAgg<INT> = 0
MATCH (a@Actor WHERE a.id IN [3,4])
PER NODE (a) {
SET a.@node_sum += 1 // Increment each actor's sum by 1
}
PER NODE (a) {
LOG_INFO("a.name: ",a.name, " a.id: ",a.id, " a.@node_sum: ",a.@node_sum)
}
}
'''
Return:
Log:
2025-08-08T08:29:51.496032 INFO - a.name: Carrie Fisher a.id: 4 a.@node_sum: 1
2025-08-08T08:29:51.496032 INFO - a.name: Harrison Ford a.id: 3 a.@node_sum: 1