Skip to content


Functions for working with string encodings of histograms from desktop telemetry.

mean (UDF)

Given histogram h, return floor(mean) of the measurements in the bucket. That is, the histogram sum divided by the number of measurements taken.

Source | Edit

string_to_json (UDF)

Convert a histogram string (in JSON or compact format) to a full histogram JSON blob.

Source | Edit

normalize (UDF)

Normalize a histogram. Set sum to 1, and normalize to 1 the histogram bucket counts.

Source | Edit

extract (UDF)

Return a parsed struct from a string-encoded histogram.

We support a variety of compact encodings as well as the classic JSON representation as sent in main pings.

The built-in BigQuery JSON parsing functions are not powerful enough to handle all the logic here, so we resort to some string processing. This function could behave unexpectedly on poorly-formatted histogram JSON, but we expect that payload validation in the data pipeline should ensure that histograms are well formed, which gives us some flexibility.

For more on desktop telemetry histogram structure, see:


The compact encodings were originally proposed in:

-- 1
-- 5

Source | Edit

merge (UDF)

Merge an array of histograms into a single histogram.

  • The histogram values will be summed per-bucket
  • The count will be summed
  • Other fields will take the mode_last

Source | Edit

percentiles (UDF)

Given histogram and list of percentiles,calculate what those percentiles are for the histogram. If the histogram is empty, returns NULL.

Source | Edit

threshold_count (UDF)

Return the number of recorded observations greater than threshold for the histogram. CAUTION: Does not count any buckets that have any values less than the threshold. For example, a bucket with range (1, 10) will not be counted for a threshold of 2. Use threshold that are not bucket boundaries with caution.

Source | Edit