quantile() function

The quantile() function returns records from an input table with _values that fall within a specified quantile or it returns the record with the _value that represents the specified quantile. Which it returns depends on the method used. quantile() supports columns with float values.

*Function type: Aggregate or Selector
**
Output data type:* Float | Record

  1. quantile(
  2. column: "_value",
  3. q: 0.99,
  4. method: "estimate_tdigest",
  5. compression: 1000.0
  6. )

When using the estimate_tdigest or exact_mean methods, it outputs non-null records with values that fall within the specified quantile.

When using the exact_selector method, it outputs the non-null record with the value that represents the specified quantile.

Parameters

column

The column to use to compute the quantile. Defaults to "_value".

*Data type: String*

q

A value between 0 and 1 indicating the desired quantile.

*Data type: Float*

method

Defines the method of computation.

*Data type: String*

The available options are:

estimate_tdigest

An aggregate method that uses a t-digest data structure to compute an accurate quantile estimate on large data sources.

exact_mean

An aggregate method that takes the average of the two points closest to the quantile value.

exact_selector

A selector method that returns the data point for which at least q points are less than.

compression

Indicates how many centroids to use when compressing the dataset. A larger number produces a more accurate result at the cost of increased memory requirements. Defaults to 1000.0.

*Data type: Float*

Examples

Quantile as an aggregate
  1. from(bucket: "example-bucket")
  2. |> range(start: -5m)
  3. |> filter(fn: (r) =>
  4. r._measurement == "cpu" and
  5. r._field == "usage_system")
  6. |> quantile(
  7. q: 0.99,
  8. method: "estimate_tdigest",
  9. compression: 1000.0
  10. )
Quantile as a selector
  1. from(bucket: "example-bucket")
  2. |> range(start: -5m)
  3. |> filter(fn: (r) =>
  4. r._measurement == "cpu" and
  5. r._field == "usage_system")
  6. |> quantile(
  7. q: 0.99,
  8. method: "exact_selector"
  9. )

Related articles