# Error - Dgraph groupby query while returning zero results

**URL:** <https://discuss.dgraph.io/t/error-dgraph-groupby-query-while-returning-zero-results/1950>\
**Category:** Users\
**Created:** [November 11, 2017, 6:28pm UTC](https://discuss.dgraph.io/t/error-dgraph-groupby-query-while-returning-zero-results/1950 "2017-11-11T18:28:17Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![yebaros](https://avatars.discourse-cdn.com/v4/letter/y/90ced4/32.png) [@yebaros](https://discuss.dgraph.io/u/yebaros)\
**Post date:** [November 11, 2017, 6:28pm UTC](https://discuss.dgraph.io/t/error-dgraph-groupby-query-while-returning-zero-results/1950/1 "2017-11-11T18:28:18Z")

</div>

Group by query when returns an incomplete Json structure causing an parse error due to an extra comma at the end of aggregation

Query -

{  
var (func: eq(description,“test content”)) {  
DP as followed\_by  
}  
}

{  
DP\_Breakdown (func :uid(DP)) @groupby(description){  
count()  
count(_uid_)  
}  
}

Response -

{“extensions”: {“server\_latency”:{“json”:“8ms”,“parsing”:“0s”,“processing”:“0s”,“total”:“8ms”}},“data”: {“DP\_Breakdown”:[{“count”:0},]}}

---

<div class="post-metadata">

**Author:** ![pawan](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/pawan/32/1946_2.png) [@pawan](https://discuss.dgraph.io/u/pawan)\
**Post date:** [November 12, 2017, 10:57pm UTC](https://discuss.dgraph.io/t/error-dgraph-groupby-query-while-returning-zero-results/1950/2 "2017-11-12T22:57:54Z")

</div>

Hey @yebaros

This looks like a bug. @janardhan is looking at it and we will fix it soon.

---

<div class="post-metadata">

**Author:** ![janardhan](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/janardhan/32/759_2.png) [@janardhan](https://discuss.dgraph.io/u/janardhan)\
**Post date:** [November 13, 2017, 5:08am UTC](https://discuss.dgraph.io/t/error-dgraph-groupby-query-while-returning-zero-results/1950/3 "2017-11-13T05:08:08Z")

</div>

@yebaros: count() is not allowed inside group by, count(uid) should be used instead. I have pushed a fix to master so that user will see relevant error message.

---

<div class="post-metadata">

**Author:** ![yebaros](https://avatars.discourse-cdn.com/v4/letter/y/90ced4/32.png) [@yebaros](https://discuss.dgraph.io/u/yebaros)\
**Post date:** [November 13, 2017, 7:05am UTC](https://discuss.dgraph.io/t/error-dgraph-groupby-query-while-returning-zero-results/1950/4 "2017-11-13T07:05:36Z")

</div>

The count() actually helps in giving an top level aggregate of all nodes used in the group by operation. And count(_uid_) was returning count of each individual group.

It helped us retrieve results in one query instead of 2. Instead of removing the functionality , just correctng the json stucture helps so that only count is returned in a valid json.

---

<div class="post-metadata">

**Author:** ![yebaros](https://avatars.discourse-cdn.com/v4/letter/y/90ced4/32.png) [@yebaros](https://discuss.dgraph.io/u/yebaros)\
**Post date:** [November 13, 2017, 7:15am UTC](https://discuss.dgraph.io/t/error-dgraph-groupby-query-while-returning-zero-results/1950/5 "2017-11-13T07:15:51Z")

</div>

We are currently using dgraph to pull outlier graph reports on multiple graphs built over mre than 4 million transactions.

This feature actually helped us keeping our query count at avg of 40-50 which would now bump up to 80-100.

Instead of showing an error appreciate if this can be retained. Happy to discuss the usecase in detail

---

<div class="post-metadata">

**Author:** ![janardhan](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/janardhan/32/759_2.png) [@janardhan](https://discuss.dgraph.io/u/janardhan)\
**Post date:** [November 13, 2017, 7:47am UTC](https://discuss.dgraph.io/t/error-dgraph-groupby-query-while-returning-zero-results/1950/6 "2017-11-13T07:47:17Z")

</div>

The following query(single query) achieves the same thing you want. Both this and the query you wrote does the same thing internally.

```auto
var (func: eq(description,“test content”)) {
  DP as followed_by
}

DP_Breakdown (func :uid(DP)) @groupby(description){
  count(uid)
}

DP_Breakdown2(func :uid(DP)) {
  count(uid)
}
}

```

count() works on top level, everything within groupby block works on a group and not on top level. We changed it to have a consistent query language syntax.

Please let us know your feedback. @yebaros

---

<div class="post-metadata">

**Author:** ![yebaros](https://avatars.discourse-cdn.com/v4/letter/y/90ced4/32.png) [@yebaros](https://discuss.dgraph.io/u/yebaros)\
**Post date:** [November 13, 2017, 8:28am UTC](https://discuss.dgraph.io/t/error-dgraph-groupby-query-while-returning-zero-results/1950/7 "2017-11-13T08:28:06Z")

</div>

Yes i understand that but effectively its a different query.

Please can you confirm in the original query where count and count uid was used how many read is required to arrive at output and similarly when it is used in separate queries would it end up parsing all of the records twice.

Syntactically please can we discuss if there are any pitfalls in maintaining this format of syntax as a feature.

---

<div class="post-metadata">

**Author:** ![mrjn](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/mrjn/32/775_2.png) [@mrjn](https://discuss.dgraph.io/u/mrjn)\
**Post date:** [November 13, 2017, 8:39am UTC](https://discuss.dgraph.io/t/error-dgraph-groupby-query-while-returning-zero-results/1950/8 "2017-11-13T08:39:27Z")

</div>

The query mentioned by @janardhan shouldn’t be any slower. Note that `DP` has already been calculated. So, all we’re doing in Breakdown2 is to count the length of this DP variable, which is very cheap.

The issue with maintaining a `count()` along with `count(uid)` is complexity. It would be confusing to a user, when to use one and when to use another – we try to keep things as simple as possible in the language.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex007/uploads/dgraph/original/2X/2/2b38fdece2abe5814f2e51bee69d1e67fc304b0a.png) [@system](https://discuss.dgraph.io/u/system)\
**Post date:** [December 13, 2017, 8:39am UTC](https://discuss.dgraph.io/t/error-dgraph-groupby-query-while-returning-zero-results/1950/9 "2017-12-13T08:39:30Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
