This module provides Apache Druid approximate sketch aggregators based on T-Digest. T-Digest (https://github.com/tdunning/t-digest) is a popular data structure for accurate on-line accumulation of rank-based statistics such as quantiles and trimmed means. The data structure 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 aggregator.

To use this aggregator, make sure you include the extension in your config file:

  1. 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.

  1. {
  2. "type" : "tDigestSketch",
  3. "name" : <output_name>,
  4. "fieldName" : <metric_name>,
  5. "compression": <parameter that controls size and accuracy>
  6. }

Example:

  1. {
  2. "type": "tDigestSketch",
  3. "name": "sketch",
  4. "fieldName": "session_duration",
  5. "compression": 200
  6. }
  1. {
  2. "type": "tDigestSketch",
  3. "name": "combined_sketch",
  4. "fieldName": <input-column>,
  5. "compression": 200
  6. }
propertydescriptionrequired?
typeThis String should always be “tDigestSketch”yes
nameA String for the output (result) name of the calculation.yes
fieldNameA String for the name of the input field containing raw numeric values or pre-generated T-Digest sketches.yes
compressionParameter 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.

  1. {
  2. "type" : "quantilesFromTDigestSketch",
  3. "name": <output name>,
  4. "field" : <post aggregator that refers to a TDigestSketch (fieldAccess or another post aggregator)>,
  5. "fractions" : <array of fractions>
  6. }
propertydescriptionrequired?
typeThis String should always be “quantilesFromTDigestSketch”yes
nameA String for the output (result) name of the calculation.yes
fieldA field reference pointing to the field aggregated/combined T-Digest sketch.yes
fractionsNon-empty array of fractions between 0 and 1yes

Example:

  1. {
  2. "queryType": "groupBy",
  3. "dataSource": "test_datasource",
  4. "granularity": "ALL",
  5. "dimensions": [],
  6. "aggregations": [{
  7. "type": "tDigestSketch",
  8. "name": "merged_sketch",
  9. "fieldName": "ingested_sketch",
  10. "compression": 200
  11. }],
  12. "postAggregations": [{
  13. "type": "quantilesFromTDigestSketch",
  14. "name": "quantiles",
  15. "fractions": [0, 0.5, 1],
  16. "field": {
  17. "type": "fieldAccess",
  18. "fieldName": "merged_sketch"
  19. }
  20. }],
  21. "intervals": ["2016-01-01T00:00:00.000Z/2016-01-31T00:00:00.000Z"]
  22. }

Similar to quantilesFromTDigestSketch except it takes in a single fraction for computing quantile.

  1. {
  2. "type" : "quantileFromTDigestSketch",
  3. "name": <output name>,
  4. "field" : <post aggregator that refers to a TDigestSketch (fieldAccess or another post aggregator)>,
  5. "fraction" : <value>
  6. }
propertydescriptionrequired?
typeThis String should always be “quantileFromTDigestSketch”yes
nameA String for the output (result) name of the calculation.yes
fieldA field reference pointing to the field aggregated/combined T-Digest sketch.yes
fractionDecimal value between 0 and 1yes