How to summarize property values in Gremlin?

134 views Asked by At

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.

1

There are 1 answers

2
Faber On BEST ANSWER

Simple groovy:

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