Aggregates Aggregate Table macro

histogram()

Returns a LIST of STRUCTs with the fields bucket and count.

Arguments & returns

3 overloads

histogram(arg)

Aggregate
Overload link arg Returns
#01 ANY MAP

histogram(arg, col1)

Aggregate
Overload link argcol1 Returns
#02 ANYANY[] MAP

histogram(source, col_name, bin_count, technique)

Table macro
Overload link sourcecol_namebin_counttechnique Returns
#03 unknownunknownunknownunknown TABLE

Example

histogram example
SQL
Haybarn WASM 1.5.5-rc3 · In your browser

Engine example with sample data · Run to view results.

Definition

SELECT
  CASE
    WHEN (is_histogram_other_bin (bin)) THEN ('(other values)')
    WHEN (
      (
        (
          (
            NOT (
              can_cast_implicitly (bin, CAST(NULL AS BIGINT))
              OR can_cast_implicitly (bin, CAST(NULL AS "DOUBLE"))
              OR can_cast_implicitly (bin, CAST(NULL AS TIMESTAMP))
            )
          )
          AND (technique = 'auto')
        )
        OR (technique = 'sample')
      )
    ) THEN (CAST(bin AS VARCHAR))
    WHEN ((row_number() OVER () = 1)) THEN (concat('x <= ', CAST(bin AS VARCHAR)))
    ELSE concat(
      lag (CAST(bin AS VARCHAR)) OVER (),
      ' < x <= ',
      CAST(bin AS VARCHAR)
    )
  END AS bin,
  count,
  bar (count, 0, max(count) OVER ()) AS bar
FROM
  histogram_values (
    "source",
    col_name,
    bin_count := bin_count,
    technique := technique
  )