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

> Documentation for uniqTheta Functions

# uniqTheta Functions

uniqTheta functions work for two uniqThetaSketch objects to do set operation calculations such as  ∪ / ∩ / × (union/intersect/not), it is to return a new uniqThetaSketch object contain the result.

A uniqThetaSketch object is to be constructed by aggregation function uniqTheta with -State.

UniqThetaSketch is a data structure storage of approximate values set.
For more information, see: [Theta Sketch Framework](https://datasketches.apache.org/docs/Theta/ThetaSketches.html#theta-sketch-framework).

<h2 id="uniqthetaunion">
  uniqThetaUnion
</h2>

Two uniqThetaSketch objects to do union calculation(set operation ∪), the result is a new uniqThetaSketch.

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

**Arguments**

* `uniqThetaSketch` – uniqThetaSketch object.

**Example**

```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 │
└───────────┴───────────────┴───────────────┘
```

<h2 id="uniqthetaintersect">
  uniqThetaIntersect
</h2>

Two uniqThetaSketch objects to do intersect calculation(set operation ∩), the result is a new uniqThetaSketch.

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

**Arguments**

* `uniqThetaSketch` – uniqThetaSketch object.

**Example**

```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 │
└───────────────┴───────────────┴───────────────┘
```

<h2 id="uniqthetanot">
  uniqThetaNot
</h2>

Two uniqThetaSketch objects to do a\_not\_b calculation(set operation ×), the result is a new uniqThetaSketch.

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

**Arguments**

* `uniqThetaSketch` – uniqThetaSketch object.

**Example**

```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 │
└─────────┴───────────────┴───────────────┘
```

**See Also**

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

{/*AUTOGENERATED_START*/}
