Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gremlin group by vertex property and get sum other properties in the same vertex

We have vertex which will store various jobs and their types and counts as properties. I have to group by the status and their counts. I tried the following query which works for one property(receiveCount)

g.V().hasLabel("Jobs").has("Type",within("A","B","C")).group().by("Type").by(fold().match(__.as("p").unfold().values("receiveCount").sum().as("totalRec")).select("totalRec")).next()

I wanted to give 10 more properties like successCount, FailedCount etc.. Is there a better way to give that?

like image 712
Sads Avatar asked Nov 07 '25 17:11

Sads


1 Answers

You could use cap() step just like:

g.V().has("name","marko").out("knows").groupCount("a").by("name").group("b").by("name").by(values("age").sum()).cap("a","b")

And the result would be:

 "data": [
      {
        "a": {
          "vadas": 1,
          "josh": 1
        },
        "b": {
          "vadas": [
            27.0
          ],
          "josh": [
            32.0
          ]
        }
      }
    ]
like image 156
John Avatar answered Nov 10 '25 16:11

John



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!