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

# ds_theta_combine

> Merges serialized Apache DataSketches Theta sketches across rows into a single unioned compact sketch returned as VARBINARY.

Aggregate function that unions serialized Apache DataSketches Theta sketches
(`VARBINARY`) across rows and returns a single serialized compact sketch.

Input is a column of compact theta sketches from any source: built via
[`ds_theta_accumulate`](/documents/4.2/sql-reference/sql-functions/aggregate-functions/ds_theta_accumulate), produced by the pairwise
scalar set ops [`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), or loaded externally as
`VARBINARY` from Parquet/Iceberg.

The on-wire format is the standard Apache DataSketches C++ compact theta
serialization, so result sketches interoperate with any other Apache
DataSketches implementation that uses the default hash seed.

## Syntax

```Haskell theme={null}
VARBINARY ds_theta_combine(sketch)
```

* `sketch`: a `VARBINARY` column of compact theta sketches.

## Examples

```SQL theme={null}
-- Roll daily sketches up to the year.
SELECT year(day), ds_theta_estimate(ds_theta_combine(daily_sk))
FROM daily_sketches
GROUP BY year(day);
```

## Keywords

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


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