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

你。 提交于 2019-12-12 18:27:46

问题


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?


回答1:


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
          ]
        }
      }
    ]


来源:https://stackoverflow.com/questions/45094967/gremlin-group-by-vertex-property-and-get-sum-other-properties-in-the-same-vertex

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!