Document expression post-aggregators (#11896)

* Document expression post-aggregators

* Update docs/querying/post-aggregations.md

Co-authored-by: Frank Chen <frankchen@apache.org>

Co-authored-by: Frank Chen <frankchen@apache.org>
This commit is contained in:
jacobtolar 2022-04-18 21:36:19 -05:00 committed by GitHub
parent 2677d279e2
commit 0edc22179c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -42,6 +42,7 @@ Supported functions are `+`, `-`, `*`, `/`, and `quotient`.
* `/` division always returns `0` if dividing by`0`, regardless of the numerator.
* `quotient` division behaves like regular floating point division
* Arithmetic post-aggregators always use floating point arithmetic.
Arithmetic post-aggregators may also specify an `ordering`, which defines the order
of resulting values when sorting results (this can be useful for topN queries for instance):
@ -89,6 +90,20 @@ The constant post-aggregator always returns the specified value.
{ "type" : "constant", "name" : <output_name>, "value" : <numerical_value> }
```
### Expression post-aggregator
The expression post-aggregator is defined using a Druid [expression](../misc/math-expr.md).
```json
{
"type": "expression",
"name": <output_name>,
"expression": <post-aggregation expression>,
"ordering" : <null (default), or "numericFirst">
}
```
### Greatest / Least post-aggregators
`doubleGreatest` and `longGreatest` computes the maximum of all fields and Double.NEGATIVE_INFINITY.
@ -221,3 +236,21 @@ The format of the query JSON is as follows:
...
}
```
The same could be computed using an expression post-aggregator:
```json
{
...
"aggregations" : [
{ "type" : "doubleSum", "name" : "tot", "fieldName" : "total" },
{ "type" : "doubleSum", "name" : "part", "fieldName" : "part" }
],
"postAggregations" : [{
"type" : "expression",
"name" : "part_percentage",
"expression" : "100 * (part / tot)"
}]
...
}
```