---
title: hll_sketch_estimate function
description: Learn the syntax of the hll\_sketch\_estimate function of the SQL language in Databricks SQL and Databricks Runtime.
canonical_url: https://docs.databricks.com/aws/en/sql/language-manual/functions/hll_sketch_estimate
---

# `hll_sketch_estimate` function

**Applies to:** ![check marked yes](https://docs.databricks.com/aws/en/images/icons/check.png) Databricks SQL ![check marked yes](https://docs.databricks.com/aws/en/images/icons/check.png) Databricks Runtime 13.3 LTS and above

This function utilizes the [HyperLogLog](https://en.wikipedia.org/wiki/HyperLogLog) algorithm to count a probabilistic approximation of the number of unique values in a given column,
consuming a binary representation known as a sketch buffer previously generated by the [hll\_sketch\_agg](https://docs.databricks.com/aws/en/sql/language-manual/functions/hll_sketch_agg.md) function and returning the result as a big integer.

The [hll\_union](https://docs.databricks.com/aws/en/sql/language-manual/functions/hll_union.md) and [hll\_union\_agg](https://docs.databricks.com/aws/en/sql/language-manual/functions/hll_union_agg.md) functions can also combine sketches together by consuming and merging these buffers as inputs.

The implementation uses the [Apache Datasketches library](https://datasketches.apache.org). Please see [HLL](https://datasketches.apache.org/docs/HLL/HllJavaExample.html) for more information.

## Syntax

```
hll_sketch_estimate ( expr )
```

## Arguments

* `expr`: A `BINARY` expression holding a sketch generated by [hll\_sketch\_agg](https://docs.databricks.com/aws/en/sql/language-manual/functions/hll_sketch_agg.md).

## Returns

A `BIGINT` value that is the approximate distinct count represented by the input sketch.

## Examples

```sql
> SELECT hll_sketch_estimate(hll_sketch_agg(col, 12))
    FROM VALUES (1), (1), (2), (2), (3) tab(col);
  3

> SELECT hll_sketch_estimate(hll_sketch_agg(col))
    FROM VALUES (1), (1), (2), (2), (3) tab(col);
  3
```

## Related

* [`hll_sketch_agg` aggregate function](https://docs.databricks.com/aws/en/sql/language-manual/functions/hll_sketch_agg.md)
* [`hll_union` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/hll_union.md)
* [`hll_union_agg` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/hll_union_agg.md)
* [Window functions](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-window-functions.md)
