Skip to main content
Early access 1.8.0 Estimate the number of times a given text value appears in a column.
approx_count (
    item TEXT,
    agg CountMinSketch
) RETURNS INTEGER

Arguments

NameTypeDefaultRequiredDescription
itemTEXT-The value you want to estimate occurrences of
aggCountMinSketch-A CountMinSketch object created using count_min_sketch

Returns

ColumnTypeDescription
approx_countINTEGERThe estimated number of times item appeared in the sketch

Samples

Given a table of stock data, estimate how many times the symbol AAPL appears:
WITH t AS (
  SELECT toolkit_experimental.count_min_sketch(symbol, 0.01, 0.01) AS symbol_sketch
  FROM crypto_ticks
)
SELECT toolkit_experimental.approx_count('AAPL', symbol_sketch)
FROM t;