ClickHouse/docs/en/sql-reference/aggregate-functions/reference/quantileddsketch.md
Srikanth Chekuri c23c7e0b6f
feat: add DDSketch quantile (#56342)
* feat: add DDSketch quantile

* Fix StyleCheck

* Move quantileddsketch.md under right dir

* Update stateless test number and add stateful test

* Throw exception when relative accuracy is too low

* Update test number

* Fix undefined behaviour for empty store

* Fix quantileGK test

* Update test numbers

* Update src/AggregateFunctions/

* Throw exception on out of range values

* Update relative accuracy docs and add encoding details

* Address review comments and suggestions

* Remove unused function

* Address alexey review comments

* Remove unused function isFloat64FieldType

* Throw error on invalid relative accuracy

* Simplify mapping

* Address remaining review comments

* Add effective memory usage suggestions

* Fix Stylecheck

* Fix fast test

* Incorporate bins capacity suggestion

* Fix fuzzer

* Remove inheritance in Mapping, Store and DDSketch

* Add checks for bin resizing

* Add note about the binary compatible implementation
2024-01-17 19:51:32 -08:00

2.3 KiB

slug sidebar_position title
/en/sql-reference/aggregate-functions/reference/quantileddsketch 211 quantileDDSketch

Computes an approximate quantile of a sample with relative-error guarantees. It works by building a DDSketch.

Syntax

quantileDDsketch[relative_accuracy, (level)](expr)

Arguments

Parameters

  • relative_accuracy — Relative accuracy of the quantile. Possible values are in the range from 0 to 1. Float. The size of the sketch depends on the range of the data and the relative accuracy. The larger the range and the smaller the relative accuracy, the larger the sketch. The rough memory size of the of the sketch is log(max_value/min_value)/relative_accuracy. The recommended value is 0.001 or higher.

  • level — Level of quantile. Optional. Possible values are in the range from 0 to 1. Default value: 0.5. Float.

Returned value

  • Approximate quantile of the specified level.

Type: Float64.

Example

Input table has an integer and a float columns:

┌─a─┬─────b─┐
│ 1 │ 1.001 │
│ 2 │ 1.002 │
│ 3 │ 1.003 │
│ 4 │ 1.004 │
└───┴───────┘

Query to calculate 0.75-quantile (third quartile):

SELECT quantileDDSketch(0.01, 0.75)(a), quantileDDSketch(0.01, 0.75)(b) FROM example_table;

Result:

┌─quantileDDSketch(0.01, 0.75)(a)─┬─quantileDDSketch(0.01, 0.75)(b)─┐
│               2.974233423476717 │                            1.01 │
└─────────────────────────────────┴─────────────────────────────────┘

See Also