hello everyone
I have the same error
Vars can be assigned only when grouped by UID attribute while executing this query
{
var(func: has(evt_uniq_visitor)) @groupby(evt_uniq_visitor){
data as count(uid)
}
res(func:uid(data)){
evt_uniq_visitor
}
}
but I remove res function work very well also I tested the same query in another database it works I don’t know why doesn’t work here and what this error mean
1 Like
Valdanito
(Valdanito)
March 14, 2022, 11:26am
2
Is it like this?
{
xx(func: has(evt_uniq_visitor)) @groupby(evt_uniq_visitor){
count(uid)
}
}
This is correct because you do not use var
.
evt_uniq_visitor
is an attribute of a vertex, not an edge, so var
cannot be used when grouping by it.
This is a limitation of dql, no way.
1 Like
but I execute the same query in another database it works for me
also, I wanna get data for each evt_uniq_visitor that’s why I want to get them in var
BenW
(Ben W)
October 4, 2022, 7:25am
4
MichelDiz
(Michel Diz)
December 21, 2022, 12:23am
5
I have created a cherry-pick for this - it may come in a next release.
dgraph-io:main
← dgraph-io:micheldiz/cherry-pick#7746
opened 12:18AM - 21 Dec 22 UTC
### PS. This PR depends A LOT in the Roaring Bitmaps. ref: https://github.com/… dgraph-io/dgraph/commit/1134839dec4c6c6d0ae2eb6b8db76f8b33129a24
This PR extends support for var inside the @groupby query on a scalar predicate at root.
for example the given query now doesn't result to error:-
```
var(func: ... ) @groupby(age) {
c as count(uid)
}
```
Now the uid variable `c` contains map of uid to count of uids with the same age.
Suppose for the data :-
```{
"uid": "0x1",
"age": 38
},
{
"uid": "0x17",
"age": 15
},
{
"uid": "0x18",
"age": 15
},
{
"uid": "0x19",
"age": 17
}
```
The following groupby query:-
```
var(func: uid(1, 23, 24, 25)) @groupby(age) {
c as count(uid)
}
me(func: uid(c)) {
uid
val(c)
}
```
returns the result:-
```
"data": {
"me": [
{
"uid": "0x1",
"val(c)": 1
},
{
"uid": "0x17",
"val(c)": 2
},
{
"uid": "0x18",
"val(c)": 2
},
{
"uid": "0x19",
"val(c)": 1
}
]
}
```
The behaviour will be the same if there are multiple predicates and some of them are uid predicates.
However, it is only supported at root currently. Hence the given query will still return error:-
```
var(func: .....) {
friend @groupby(age) {
a as count(uid)
}
}
```
2 Likes
MichelDiz
(Michel Diz)
December 21, 2022, 12:31am
6
Update. A big problem. This feature depends in the Roaring Bitmaps support. That means it will take longer. Unless we edit the code of the cherry-pick if we choose to not support Roaring Bitmaps.
2 Likes