--- id: tdigestsketch-quantiles title: "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. The tDigestSketch aggregator is capable of generating sketches from raw numeric values as well as aggregating/combining pre-generated T-Digest sketches generated using the tDigestSketch aggregator itself. While one can generate sketches on the fly during the query time itself, it generally is more performant to generate sketches during ingestion time itself and then combining them during query time. The module also provides a postAggregator, quantilesFromTDigestSketch, that can be used to compute approximate quantiles from T-Digest sketches generated by the tDigestSketch aggreator. To use this aggregator, make sure you [include](../../development/extensions.md#loading-extensions) 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 or from combining pre-generated T-Digest sketches. ```json { "type" : "tDigestSketch", "name" : , "fieldName" : , "compression": } ``` Example: ```json { "type": "tDigestSketch", "name": "sketch", "fieldName": "session_duration", "compression": 200 } ``` ```json { "type": "tDigestSketch", "name": "combined_sketch", "fieldName": , "compression": 200 } ``` |property|description|required?| |--------|-----------|---------| |type|This String should always be "tDigestSketch"|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 or pre-generated T-Digest sketches.|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| ### Post Aggregators #### Quantiles This returns an array of quantiles corresponding to a given array of fractions. ```json { "type" : "quantilesFromTDigestSketch", "name": , "field" : , "fractions" : } ``` |property|description|required?| |--------|-----------|---------| |type|This String should always be "quantilesFromTDigestSketch"|yes| |name|A String for the output (result) name of the calculation.|yes| |field|A field reference pointing to the field aggregated/combined T-Digest sketch.|yes| |fractions|Non-empty array of fractions between 0 and 1|yes| Example: ```json { "queryType": "groupBy", "dataSource": "test_datasource", "granularity": "ALL", "dimensions": [], "aggregations": [{ "type": "tDigestSketch", "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"] } ``` Similar to quantilesFromTDigestSketch except it takes in a single fraction for computing quantile. ```json { "type" : "quantileFromTDigestSketch", "name": , "field" : , "fraction" : } ``` |property|description|required?| |--------|-----------|---------| |type|This String should always be "quantileFromTDigestSketch"|yes| |name|A String for the output (result) name of the calculation.|yes| |field|A field reference pointing to the field aggregated/combined T-Digest sketch.|yes| |fraction|Decimal value between 0 and 1|yes|