Unexpected behaviour for TopN query granularity

Hello,

According to documentation (http://druid.io/docs/latest/querying/granularities.html) empty buckets should be discarded from the result. However if run following query:

{
“queryType”: “topN”,
“dataSource”: “data_source”,
“dimension”: “id”,
“threshold” : 100,
“metric”: “total”,
“filter”: {
“type”: “and”,
“fields”: [
---- filters----
]
},
“aggregations”: [
{
“type”: “longSum”,
“name”: “total”,
“fieldName”: “count”
}
],
“granularity”: “hour”,
“intervals”: [
“2016-07-16T00:48:00/2016-07-18T12:50:04”
]
}

``

I am getting result similar to this:

[

Hey Levani,

groupBy and topN behave somewhat differently in this regard. Only groupBy discards empty buckets.

Just wondering: is this causing a problem for you or are you asking out of curiosity?

Hey Gian,

Thank you for the reply. Well, the task that I need to solve is pure TopN problem since I know exactly how many results I want in the top list and I need to do it only on one dimension. Although I can find a workaround with the GroupBy query, it would be nice to be able to use TopN query.

Thank you for your time.

Kind regards,

Levani

Hey Levani,

Is there a reason you can’t use granularity “all” for your topN?

The idea with the granularity is that you get a separate topN list for each granular bucket – they are independent from each other.