2013-09-16 17:49:36 -04:00
---
2013-09-26 19:22:28 -04:00
layout: doc_page
2013-09-16 17:49:36 -04:00
---
2013-09-13 18:20:39 -04:00
Post-aggregations are specifications of processing that should happen on aggregated values as they come out of Druid. If you include a post aggregation as part of a query, make sure to include all aggregators the post-aggregator requires.
There are several post-aggregators available.
### Arithmetic post-aggregator
The arithmetic post-aggregator applies the provided function to the given fields from left to right. The fields can be aggregators or other post aggregators.
Supported functions are `+` , `-` , `*` , and `/`
The grammar for an arithmetic post aggregation is:
2013-09-27 20:08:34 -04:00
```json
postAggregation : {
"type" : "arithmetic",
"name" : < output_name > ,
"fn" : < arithmetic_function > ,
"fields": [< post_aggregator > , < post_aggregator > , ...]
}
```
2013-09-13 18:20:39 -04:00
### Field accessor post-aggregator
2013-09-27 20:08:34 -04:00
This returns the value produced by the specified [aggregator ](Aggregations.html ).
2013-09-13 18:20:39 -04:00
2013-09-27 20:08:34 -04:00
`fieldName` refers to the output name of the aggregator given in the [aggregations ](Aggregations.html ) portion of the query.
2013-09-13 18:20:39 -04:00
2013-09-27 20:08:34 -04:00
```json
{ "type" : "fieldAccess", "fieldName" : < aggregator_name > }
```
2013-09-13 18:20:39 -04:00
### Constant post-aggregator
The constant post-aggregator always returns the specified value.
2013-09-27 20:08:34 -04:00
```json
{ "type" : "constant", "name" : < output_name > , "value" : < numerical_value > }
```
2013-09-13 18:20:39 -04:00
### Example Usage
2013-09-27 20:08:34 -04:00
In this example, let’ s calculate a simple percentage using post aggregators. Let’ s imagine our data set has a metric called "total".
2013-09-13 18:20:39 -04:00
The format of the query JSON is as follows:
2013-09-27 20:08:34 -04:00
```json
{
...
"aggregations" : [
{ "type" : "count", "name" : "rows" },
{ "type" : "doubleSum", "name" : "tot", "fieldName" : "total" }
],
"postAggregations" : {
"type" : "arithmetic",
"name" : "average",
"fn" : "*",
"fields" : [
{ "type" : "arithmetic",
"name" : "div",
"fn" : "/",
"fields" : [
{ "type" : "fieldAccess", "name" : "tot", "fieldName" : "tot" },
{ "type" : "fieldAccess", "name" : "rows", "fieldName" : "rows" }
]
},
{ "type" : "constant", "name": "const", "value" : 100 }
]
}
...
}
```