简体   繁体   中英

sum of all properties of node in gremlin

Considering three nodes in a graph with 3 properties want to calculate the sum of each property for all the nodes using the gremlin query.

g.addV('node').property('property1',1).property('property2',2).property('property3',3).next()
g.addV('node').property('property1',4).property('property2',5).property('property3',6).next()
g.addV('node').property('property1',7).property('property2',8).property('property3',9).next()

Output: The required output is the sum of respective properties for all nodes using the gremlin query. property1: 12, property2: 15, property3: 18

g.V().hasLabel('node').
  properties('property1', 'property2', 'property3').
  group().by(key).
    by(value().sum())

Here's a live example: https://gremlify.com/t0jy5i6hkh8/2

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM