> ## Documentation Index
> Fetch the complete documentation index at: https://private-7c7dfe99-fix-nav-issues.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

> uniqTheta 函数文档

# uniqTheta 函数

uniqTheta 函数可对两个 uniqThetaSketch 对象执行集合运算，例如 ∪ / ∩ / × (并集/交集/差集) ，并返回一个包含结果的新 uniqThetaSketch 对象。

uniqThetaSketch 对象由带有 `-State` 的聚合函数 uniqTheta 构造而成。

UniqThetaSketch 是一种用于存储近似值集合的数据结构。
更多信息，请参见：[Theta Sketch Framework](https://datasketches.apache.org/docs/Theta/ThetaSketches.html#theta-sketch-framework)。

<div id="uniqthetaunion">
  ## uniqThetaUnion
</div>

对两个 uniqThetaSketch 对象执行并集计算 (集合运算 ∪) ，结果是一个新的 uniqThetaSketch。

```sql theme={null}
uniqThetaUnion(uniqThetaSketch,uniqThetaSketch)
```

**参数**

* `uniqThetaSketch` – uniqThetaSketch 对象。

**示例**

```sql theme={null}
SELECT finalizeAggregation(uniqThetaUnion(a, b)) AS a_union_b, finalizeAggregation(a) AS a_cardinality, finalizeAggregation(b) AS b_cardinality
FROM
(SELECT arrayReduce('uniqThetaState',[1,2]) AS a, arrayReduce('uniqThetaState',[2,3,4]) AS b );
```

```text theme={null}
┌─a_union_b─┬─a_cardinality─┬─b_cardinality─┐
│         4 │             2 │             3 │
└───────────┴───────────────┴───────────────┘
```

<div id="uniqthetaintersect">
  ## uniqThetaIntersect
</div>

对两个 uniqThetaSketch 对象执行 intersect 计算 (集合运算 ∩) ，结果会得到一个新的 uniqThetaSketch。

```sql theme={null}
uniqThetaIntersect(uniqThetaSketch,uniqThetaSketch)
```

**参数**

* `uniqThetaSketch` – `uniqThetaSketch` 对象。

**示例**

```sql theme={null}
SELECT finalizeAggregation(uniqThetaIntersect(a, b)) AS a_intersect_b, finalizeAggregation(a) AS a_cardinality, finalizeAggregation(b) AS b_cardinality
FROM
(SELECT arrayReduce('uniqThetaState',[1,2]) AS a, arrayReduce('uniqThetaState',[2,3,4]) AS b );
```

```text theme={null}
┌─a_intersect_b─┬─a_cardinality─┬─b_cardinality─┐
│             1 │             2 │             3 │
└───────────────┴───────────────┴───────────────┘
```

<div id="uniqthetanot">
  ## uniqThetaNot
</div>

对两个 uniqThetaSketch 对象执行 a\_not\_b 计算 (集合运算 ×) ，结果会得到一个新的 uniqThetaSketch。

```sql theme={null}
uniqThetaNot(uniqThetaSketch,uniqThetaSketch)
```

**参数**

* `uniqThetaSketch` – uniqThetaSketch 对象。

**示例**

```sql theme={null}
SELECT finalizeAggregation(uniqThetaNot(a, b)) AS a_not_b, finalizeAggregation(a) AS a_cardinality, finalizeAggregation(b) AS b_cardinality
FROM
(SELECT arrayReduce('uniqThetaState',[2,3,4]) AS a, arrayReduce('uniqThetaState',[1,2]) AS b );
```

```text theme={null}
┌─a_not_b─┬─a_cardinality─┬─b_cardinality─┐
│       2 │             3 │             2 │
└─────────┴───────────────┴───────────────┘
```

**另请参阅**

* [uniqThetaSketch](/zh/reference/functions/aggregate-functions/uniqthetasketch)

{/*AUTOGENERATED_START*/}
