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)
}
}
So just ran into this very confusing little gem. Is there any talk about changing the @groupby here in 2021 land? Seems like an invalid result for operation on lists, would rather have seen an error than a seemingly random (though consistent) result.
Can we get some grouping that uses all the elements of a list? My use case is how many of each type are in my system. Basically q(func: has(ns.type)) @groupby(ns.type) { count(uid) } - but currently the result is whatever is “first” in the list of types is the key of the group, even if that node has a type that is also the key of another group.
Just to share - we had to stay away from @groupby for this reason and we had to make a query to get the types, then construct a query like this to get the counts for each type: