简体   繁体   English

gremlin 中节点所有属性的总和

[英]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.考虑到具有 3 个属性的图中的三个节点想要使用 gremlin 查询计算所有节点的每个属性的总和。

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.输出:所需的输出是使用 gremlin 查询的所有节点的各个属性的总和。 property1: 12, property2: 15, property3: 18属性1:12,属性2:15,属性3: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这是一个活生生的例子: https : //gremlify.com/t0jy5i6hkh8/2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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