ARRAY_HISTOGRAM

All functions > ARRAY > ARRAY_HISTOGRAM

Returns a frequency histogram of values in an array as an array of value-count pairs.

Syntax

ARRAY_HISTOGRAM(array: ARRAY<T>) → ARRAY<ROW(value: T, count: BIGINT)>
sql

Type Parameters:

  • T: Numeric type (BIGINT, DOUBLE, etc.)

Arguments

ParameterTypeRequiredDescription
arrayARRAY<T>YesThe array to create histogram from

Returns

ARRAY<ROW(value: T, count: BIGINT)> - Array of value-count pairs sorted by value

Notes

  • Counts frequency of each distinct value in the array
  • Returns array of ROW structures with value and count fields
  • Results are sorted by value in ascending order
  • NULL values are counted separately
  • Empty arrays return empty result
  • Useful for analyzing value distributions
Last update at: 2025/10/13 10:23:46