5.5 KiB
layout | title |
---|---|
doc_page | T-Digest Quantiles Sketch module |
T-Digest Quantiles Sketch module
This module provides Apache Druid (incubating) approximate sketch aggregators based on T-Digest. T-Digest (https://github.com/tdunning/t-digest) is a popular datastructure for accurate on-line accumulation of rank-based statistics such as quantiles and trimmed means. The datastructure is also designed for parallel programming use cases like distributed aggregations or map reduce jobs by making combining two intermediate t-digests easy and efficient.
There are three flavors of T-Digest sketch aggregator available in Apache Druid (incubating):
- buildTDigestSketch - used for building T-Digest sketches from raw numeric values. It generally makes sense to use this aggregator when ingesting raw data into Druid. One can also use this aggregator during query time too to generate sketches, just that one would be building these sketches on every query execution instead of building them once during ingestion.
- mergeTDigestSketch - used for merging pre-built T-Digest sketches. This aggregator is generally used during query time to combine sketches generated by buildTDigestSketch aggregator.
- quantilesFromTDigestSketch - used for generating quantiles from T-Digest sketches. This aggregator is generally used during query time to generate quantiles from sketches built using the above two sketch generating aggregators.
To use this aggregator, make sure you include the extension in your config file:
druid.extensions.loadList=["druid-tdigestsketch"]
Aggregator
The result of the aggregation is a T-Digest sketch that is built ingesting numeric values from the raw data.
{
"type" : "buildTDigestSketch",
"name" : <output_name>,
"fieldName" : <metric_name>,
"compression": <parameter that controls size and accuracy>
}
Example:
{
"type": "buildTDigestSketch",
"name": "sketch",
"fieldName": "session_duration",
"compression": 200
}
property | description | required? |
---|---|---|
type | This String should always be "buildTDigestSketch" | yes |
name | A String for the output (result) name of the calculation. | yes |
fieldName | A String for the name of the input field containing raw numeric values. | yes |
compression | Parameter that determines the accuracy and size of the sketch. Higher compression means higher accuracy but more space to store sketches. | no, defaults to 100 |
The result of the aggregation is a T-Digest sketch that is built by merging pre-built T-Digest sketches.
{
"type" : "mergeTDigestSketch",
"name" : <output_name>,
"fieldName" : <metric_name>,
"compression": <parameter that controls size and accuracy>
}
property | description | required? |
---|---|---|
type | This String should always be "mergeTDigestSketch" | yes |
name | A String for the output (result) name of the calculation. | yes |
fieldName | A String for the name of the input field containing raw numeric values. | yes |
compression | Parameter that determines the accuracy and size of the sketch. Higher compression means higher accuracy but more space to store sketches. | no, defaults to 100 |
Example:
{
"queryType": "groupBy",
"dataSource": "test_datasource",
"granularity": "ALL",
"dimensions": [],
"aggregations": [{
"type": "mergeTDigestSketch",
"name": "merged_sketch",
"fieldName": "ingested_sketch",
"compression": 200
}],
"intervals": ["2016-01-01T00:00:00.000Z/2016-01-31T00:00:00.000Z"]
}
Post Aggregators
Quantiles
This returns an array of quantiles corresponding to a given array of fractions.
{
"type" : "quantilesFromTDigestSketch",
"name": <output name>,
"field" : <post aggregator that refers to a TDigestSketch (fieldAccess or another post aggregator)>,
"fractions" : <array of fractions>
}
property | description | required? |
---|---|---|
type | This String should always be "quantilesFromTDigestSketch" | yes |
name | A String for the output (result) name of the calculation. | yes |
fieldName | A String for the name of the input field containing raw numeric values. | yes |
fractions | Non-empty array of fractions between 0 and 1 | yes |
Example:
{
"queryType": "groupBy",
"dataSource": "test_datasource",
"granularity": "ALL",
"dimensions": [],
"aggregations": [{
"type": "mergeTDigestSketch",
"name": "merged_sketch",
"fieldName": "ingested_sketch",
"compression": 200
}],
"postAggregations": [{
"type": "quantilesFromTDigestSketch",
"name": "quantiles",
"fractions": [0, 0.5, 1],
"field": {
"type": "fieldAccess",
"fieldName": "merged_sketch"
}
}],
"intervals": ["2016-01-01T00:00:00.000Z/2016-01-31T00:00:00.000Z"]
}