dgraph
dgraph copied to clipboard
Groupby does not support predicate of list type
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.
Hello @honglicheng, Could you mention the Dgraph version and the complete query that you used?
version: 1.1.0
{
q(func: has(kind)) @groupby(kind){
count(uid)
}
}
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"
}
]
}
]
}
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.
