Skip to content
Developer Edition runs on one host and does not require a product license file. Need multi-host deployment or performance testing at scale? Explore Enterprise Edition

MaxAgg

A MaxAgg aggregator value variable (MaxAgg<T>) maintains the maximum value among all inputs, where T represents the data type of the input values. To maintain the minimum value, see MinAgg.

Declaration syntax

max_agg_declaration
NODE VALUE aggregator_value_variable MaxAgg < INT8 INT16 INT32 INT64 FLOAT DOUBLE STRING > = value_expression

max_agg_declaration ::=
'NODE'? 'VALUE' aggregator_value_variable 'MaxAgg' '<' ('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

MaxAgg<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 MaxAgg aggregator value variables

'''
USE #movie_temporary_graph {
  VALUE global_max_int MaxAgg<INT> = 0
  VALUE global_max_double MaxAgg<DOUBLE> = 0.0
  VALUE global_max_string MaxAgg<STRING> = ""

  // INT type: Get the maximum integer value
  SET @global_max_int += 3     // max: 3 (0 < 3, keeps 3)
  SET @global_max_int += 7     // max: 7 (3 < 7, keeps 7)
  SET @global_max_int += 5     // max: 7 (5 < 7, keeps 7)

  // DOUBLE type: Get the maximum floating-point value
  SET @global_max_double += 3.14     // max: 3.14 (0.0 < 3.14, keeps 3.14)
  SET @global_max_double += 7.89     // max: 7.89 (3.14 < 7.89, keeps 7.89)
  SET @global_max_double += 5.5      // max: 7.89 (5.5 < 7.89, keeps 7.89)

  // STRING type: Get the lexicographically largest string by byte comparison
  SET @global_max_string += "apple"     // max: "apple" ("" < "apple", keeps "apple")
  SET @global_max_string += "banana"    // max: "banana" ("apple" < "banana", keeps "banana")
  SET @global_max_string += "cherry"    // max: "cherry" ("banana" < "cherry", keeps "cherry")

  RETURN @global_max_int, @global_max_double, @global_max_string
}
'''

Return:

+-----------------+--------------------+--------------------+
| @global_max_int | @global_max_double | @global_max_string |
+-----------------+--------------------+--------------------+
| 7               | 7.89               | cherry             |
+-----------------+--------------------+--------------------+

Node-attached MaxAgg aggregator value variables

'''
USE #movie_temporary_graph {
  NODE VALUE node_max MaxAgg<DOUBLE> = 0
  MATCH (a@User WHERE a.id IN [1,3,4])-[w@Watch]->(b@Movie)
  PER PATH {
    // For each user, track the highest rating on Watch edges
    SET a.@node_max += w.rate
  }
  PER NODE (a) {
    LOG_INFO("a.id: ", a.id, " a.@node_max: ", a.@node_max)
  }
}
'''

Return:

Log:
2025-08-12T09:02:57.493825 INFO  - a.id: 1 a.@node_max: 5
2025-08-12T09:02:57.493825 INFO  - a.id: 3 a.@node_max: 4.5
2025-08-12T09:02:57.493825 INFO  - a.id: 4 a.@node_max: 5