Post-aggregations
Apache Druid supports two query languages: Druid SQL and native queries. This document describes the native language. For information about functions available in SQL, refer to the SQL documentation.
Post-aggregations are specifications of processing that should happen on aggregated values as they come out of Apache 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.
Property | Description | Required |
---|---|---|
type | Must be "arithmetic" . | Yes |
name | Output name of the post-aggregation | Yes |
fn | Supported functions are + , - , * , / , pow and quotient | Yes |
fields | List of post-aggregator specs which define inputs to the fn | Yes |
ordering | If no ordering (or null ) is specified, the default floating point ordering is used. numericFirst ordering always returns finite values first, followed by NaN , and infinite values last. | No |
Note:
/
division always returns0
if dividing by0
, regardless of the numerator.quotient
division behaves like regular floating point division- Arithmetic post-aggregators always use floating point arithmetic.
Example:
{
"type" : "arithmetic",
"name" : "mult",
"fn" : "*",
"fields": [
{"type": "fieldAccess", "fieldName": "someAgg"},
{"type": "fieldAccess", "fieldName": "someOtherAgg"}
]
}
Field accessor post-aggregators
These post-aggregators return the value produced by the specified dimension or aggregator.
Property | Description | Required |
---|---|---|
type | Must be "fieldAccess" or "finalizingFieldAccess" . Use type "fieldAccess" to return the raw aggregation object, or use type "finalizingFieldAccess" to return a finalized value, such as an estimated cardinality. | Yes |
name | Output name of the post-aggregation | Yes if defined as a standalone post-aggregation, but may be omitted if used inline to some other post-aggregator in a fields list |
fieldName | The output name of the dimension or aggregator to reference | Yes |
Example:
{ "type" : "fieldAccess", "name": "someField", "fieldName" : "someAggregator" }
or
{ "type" : "finalizingFieldAccess", "name": "someFinalizedField", "fieldName" : "someAggregator" }