> ## Documentation Index
> Fetch the complete documentation index at: /documents/llms.txt
> Use this file to discover all available pages before exploring further.

# ds_theta_estimate

> Returns the approximate distinct count summarized by a serialized Apache DataSketches Theta sketch.

Scalar function that returns the approximate distinct count summarized by a
serialized Apache DataSketches Theta sketch (`VARBINARY`, compact form). One
output row per input row.

Accepts any sketch written in the standard Apache DataSketches C++ compact theta
format with the default hash seed, including sketches produced by:

* [`ds_theta_accumulate`](/documents/4.2/sql-reference/sql-functions/aggregate-functions/ds_theta_accumulate) (build from raw values)
* [`ds_theta_combine`](/documents/4.2/sql-reference/sql-functions/aggregate-functions/ds_theta_combine) (union across rows)
* [`ds_theta_union`](/documents/4.2/sql-reference/sql-functions/scalar-functions/ds_theta_union), [`ds_theta_intersect`](/documents/4.2/sql-reference/sql-functions/scalar-functions/ds_theta_intersect),
  [`ds_theta_a_not_b`](/documents/4.2/sql-reference/sql-functions/scalar-functions/ds_theta_a_not_b) (pairwise set ops)
* Externally produced sketches loaded as raw `VARBINARY` from Parquet, Iceberg,
  or another Apache DataSketches consumer

Returns `NULL` for `NULL` input. Returns 0 for an empty sketch.

## Syntax

```Haskell theme={null}
DOUBLE ds_theta_estimate(sketch)
```

* `sketch`: `VARBINARY` compact theta sketch.

## Examples

```SQL theme={null}
-- Per-row estimate of a sketch column
SELECT ds_theta_estimate(sk) FROM sketches;

-- Compose with set ops
SELECT ds_theta_estimate(ds_theta_union(a.sk, b.sk)) AS u,
       ds_theta_estimate(ds_theta_intersect(a.sk, b.sk)) AS i
FROM cohort_a a JOIN cohort_b b USING (day);

-- Estimate of a daily-rolled union
SELECT ds_theta_estimate(ds_theta_combine(daily_sk))
FROM daily_sketches;
```

## Keywords

DS\_THETA\_ESTIMATE, DS\_THETA\_ACCUMULATE, DS\_THETA\_COMBINE, DS\_THETA\_COUNT\_DISTINCT


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.