dgraph icon indicating copy to clipboard operation
dgraph copied to clipboard

Groupby does not support predicate of list type

Open honglicheng opened this issue 5 years ago • 4 comments

kind: [string]

_:A <kind> "dog" .
_:A <kind> "animal" .
_:B <kind> "cat" .
_:B <kind> "animal" .
@groupby(kind){
    count(uid)
}

i want to get :

{kind: "dog", count: 1}, {kind: "cat", count: 1}, {kind: "animal", count: 2}

but only get:

{kind: "dog", count: 1}, {kind: "cat", count: 1}

it seems that only the first item in the list can be grouped.

honglicheng avatar Oct 15 '19 09:10 honglicheng

Hello @honglicheng, Could you mention the Dgraph version and the complete query that you used?

prashant-shahi avatar Oct 15 '19 12:10 prashant-shahi

version: 1.1.0

{
    q(func: has(kind)) @groupby(kind){
        count(uid)
    }
}

honglicheng avatar Oct 15 '19 17:10 honglicheng

Hi there, Internally we have a discussion about improving the "group by" function. This case would be something "different" tho (but not so much). But thinking about this issue, I come to a conclusion that if we improve the "group by" function this query should look like:

{
 var(func: has(kind)) @groupby(kind) {
    T as count(uid)
  }

foreach(func: foreach(in: T, title: kind)) {
  name
  age
  total : val(T)
}

}

Desirable Result

{
  "data": {
    "q": [
      {
        "dog": [
              {
                "total": 1
              },
              {
                "uid": "0x1",
                "name": "Bingo",
                "age": "3"
              }
      ]
      },
      {
        "animal": [
              {
                "total": 2
              },
              {
                "uid": "0x1",
                "name": "Bingo",
                "age": "3"
              },
              {
                "uid": "0x3",
                "name": "Angry Purr",
                "age": "1"
              }
      ]
      },
      {
        "cat": [
              {
                "total": 1
              },
              {
                "uid": "0x3",
                "name": "Angry Purr",
                "age": "1"
              }
      ]
      }
    ]
  }

MichelDiz avatar Oct 16 '19 22:10 MichelDiz

Github issues have been deprecated. This issue has been moved to discuss. You can follow the conversation there and also subscribe to updates by changing your notification preferences.

drawing

minhaj-shakeel avatar Jul 16 '20 13:07 minhaj-shakeel