Moment Sketches for Approximate Quantiles module

This module provides aggregators for approximate quantile queries using the momentsketch library. The momentsketch provides coarse quantile estimates with less space and aggregation time overheads than traditional sketches, approaching the performance of counts and sums by reconstructing distributions from computed statistics.

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

  1. druid.extensions.loadList=["druid-momentsketch"]

Aggregator

The result of the aggregation is a momentsketch that is the union of all sketches either built from raw data or read from the segments.

The momentSketch aggregator operates over raw data while the momentSketchMerge aggregator should be used when aggregating precomputed sketches.

  1. {
  2. "type" : <aggregator_type>,
  3. "name" : <output_name>,
  4. "fieldName" : <input_name>,
  5. "k" : <int>,
  6. "compress" : <boolean>
  7. }
propertydescriptionrequired?
typeType of aggregator desired. Either “momentSketch” or “momentSketchMerge”yes
nameA String for the output (result) name of the calculation.yes
fieldNameA String for the name of the input field (can contain sketches or raw numeric values).yes
kParameter that determines the accuracy and size of the sketch. Higher k means higher accuracy but more space to store sketches. Usable range is generally [3,15]no, defaults to 13.
compressFlag for whether the aggregator compresses numeric values using arcsinh. Can improve robustness to skewed and long-tailed distributions, but reduces accuracy slightly on more uniform distributions.no, defaults to true

Post Aggregators

Users can query for a set of quantiles using the momentSketchSolveQuantiles post-aggregator on the sketches created by the momentSketch or momentSketchMerge aggregators.

  1. {
  2. "type" : "momentSketchSolveQuantiles",
  3. "name" : <output_name>,
  4. "field" : <reference to moment sketch>,
  5. "fractions" : <array of doubles in [0,1]>
  6. }

Users can also query for the min/max of a distribution:

  1. {
  2. "type" : "momentSketchMin" | "momentSketchMax",
  3. "name" : <output_name>,
  4. "field" : <reference to moment sketch>,
  5. }

Example

As an example of a query with sketches pre-aggregated at ingestion time, one could set up the following aggregator at ingest:

  1. {
  2. "type": "momentSketch",
  3. "name": "sketch",
  4. "fieldName": "value",
  5. "k": 10,
  6. "compress": true,
  7. }

and make queries using the following aggregator + post-aggregator:

  1. {
  2. "aggregations": [{
  3. "type": "momentSketchMerge",
  4. "name": "sketch",
  5. "fieldName": "sketch",
  6. "k": 10,
  7. "compress": true
  8. }],
  9. "postAggregations": [
  10. {
  11. "type": "momentSketchSolveQuantiles",
  12. "name": "quantiles",
  13. "fractions": [0.1, 0.5, 0.9],
  14. "field": {
  15. "type": "fieldAccess",
  16. "fieldName": "sketch"
  17. }
  18. },
  19. {
  20. "type": "momentSketchMin",
  21. "name": "min",
  22. "field": {
  23. "type": "fieldAccess",
  24. "fieldName": "sketch"
  25. }
  26. }]
  27. }