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

1

4

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?

Intuitive answered 14/7, 2017 at 5:0 Comment(0)
W
5

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
          ]
        }
      }
    ]
Westernize answered 14/7, 2017 at 21:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.