agiledevpro
agiledevpro

Reputation: 133

How to summarize property values in Gremlin?

I'm quite new to Gremlin and have now spent hours trying to figure out how to calculate the values for a given property in all my vertices.

This

g.V('containerName','MyContainer').outE.inV.'(0)Probability'

gives me:

 {"results":[" 3"," 3"," 3"," 3"," 3"," 3"," 3"," 3"," 3"],"success":true,"version":"2.4.0","queryTime":15.894908}

So what I'm trying to figure out is:

  1. How can I convert the strings in the list to integer? I've tried...

    g.V('containerName','CvsRisk').outE.inV.'(0)Probability'.toInteger()
    

    ..., but it does not work.

  2. How to summarize all the values in the list, thus 3+3+...+3, not using count.

Upvotes: 0

Views: 120

Answers (1)

Faber
Faber

Reputation: 1552

Simple groovy:

l = [" 3"," 3"," 3"," 3"," 3"," 3"," 3"," 3"," 3"]
s = 0; l.each{s+=it.toInteger()}
s
==>27

Upvotes: 1

Related Questions