> ## 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

> 返回由序列化的 Apache DataSketches Theta 草图汇总的近似不同值计数。

标量函数。返回由序列化 Apache DataSketches Theta 草图（`VARBINARY`，紧凑格式）汇总的近似不同值计数。逐行输入、逐行输出。

接受任何使用默认哈希种子、以标准 Apache DataSketches C++ 紧凑 theta 格式写入的草图，包括：

* [`ds_theta_accumulate`](/documents/cn/4.2/sql-reference/sql-functions/aggregate-functions/ds_theta_accumulate)（从原始值构建）
* [`ds_theta_combine`](/documents/cn/4.2/sql-reference/sql-functions/aggregate-functions/ds_theta_combine)（跨行合并）
* [`ds_theta_union`](/documents/cn/4.2/sql-reference/sql-functions/scalar-functions/ds_theta_union)、[`ds_theta_intersect`](/documents/cn/4.2/sql-reference/sql-functions/scalar-functions/ds_theta_intersect)、[`ds_theta_a_not_b`](/documents/cn/4.2/sql-reference/sql-functions/scalar-functions/ds_theta_a_not_b)（成对集合运算）
* 从 Parquet、Iceberg 或其他 Apache DataSketches 消费者作为原始 `VARBINARY` 加载的外部草图

输入为 `NULL` 时返回 `NULL`。空草图返回 0。

## 语法

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

* `sketch`: `VARBINARY` 紧凑 theta 草图。

## 示例

```SQL theme={null}
-- 按行估计草图列
SELECT ds_theta_estimate(sk) FROM sketches;

-- 与集合运算组合
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);

-- 跨行合并后估计
SELECT ds_theta_estimate(ds_theta_combine(daily_sk))
FROM daily_sketches;
```

## 关键词

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.