Error - Dgraph groupby query while returning zero results

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},]}}

Hey @yebaros

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

@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.

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.

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

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

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

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.

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.

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