Post-aggregation operation with total amounts

Hi!

I am able to obtain this data via Druid:

[

{

"timestamp": "2017-02-05T00:00:00.000Z",

"result": [

  {

    “device”: "Desktop",

    “amount”: 109451

  },

  {

    “device”: "Mobile",

    “amount”: 57957

  },

  {

    “device”: "Tablet",

    “amount”: 22119

  }

]

}

]

``

by using this query:

{
“queryType”:“topN”,
“threshold”:1048576,
“granularity”:“all”,
“dataSource”:“table”,
“dimension”:“device”,
“context”:{
“timeout”:60000
},
“intervals”:[
“2017-02-05T00:00:00.000Z/2017-02-06T00:00:00.000Z”
],
“metric”:{
“type”:“alphaNumeric”
},
“aggregations”:[
{
“type”:“count”,
“name”:“count”
}
]
}

``

and what I want to obtain now is the percentage of each device that is used, so basically it’s each of the “amount” numbers divided by the total (for the first one would be 109451 / 189527, for the second one 57957/189527, etc.).

In order to do this I was checking the post-aggregations in the documentation, but it seems that I can’t do this without having the total number of “amounts” in the first place.

I’m kind of lost on how to do this, so if anyone has any idea on how I can do it, I would really appreciate it.

Thanks!

Druid doesn’t offer these kinds of “grand total” post aggregations right now. The best way to do it is to issue two queries: topN for the breakdown and timeseries for the total, and then compute the percentages on the client side.

Cool, thanks for your help :slight_smile: