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

> Reference material for APACHE_DATASKETCHES_HLL_ESTIMATE

# APACHE_DATASKETCHES_HLL_ESTIMATE

A scalar function.
Extracts a cardinality estimate of a
single [Apache DataSketches HLL sketches](https://datasketches.apache.org/docs/HLL/HllSketches.html) that was previously built
using the aggregate
function [APACHE\_DATASKETCHES\_HLL\_BUILD](/reference-sql/functions-reference/datasketches/apache-datasketches-hll-build).

The `APACHE_DATASKETCHES_HLL_ESTIMATE` function is used to estimate the cardinality (number of unique elements) of a dataset represented by an HLL (HyperLogLog) sketch. This is particularly useful for large datasets where exact counting is computationally expensive.

## Syntax

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
APACHE_DATASKETCHES_HLL_ESTIMATE
(<expression>)
```

## Parameters

| Parameter      | Description                                                                                                                                                                                                                                                            | Supported input types |
| :------------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :-------------------- |
| `<expression>` | An [Apache DataSketches HLL sketches](https://datasketches.apache.org/docs/HLL/HllSketches.html) in a valid format, e.g. the output of the [APACHE\_DATASKETCHES\_HLL\_BUILD](/reference-sql/functions-reference/datasketches/apache-datasketches-hll-build) function. | `BYTEA`               |

## Return Type

`BIGINT`

## Error Handling

If the input expression is not a valid [Apache DataSketches HLL sketches](https://datasketches.apache.org/docs/HLL/HllSketches.html), the function will raise an error.
Ensure that the input is correctly formatted and generated by the [APACHE\_DATASKETCHES\_HLL\_BUILD](/reference-sql/functions-reference/datasketches/apache-datasketches-hll-build) function.

## Example

Following the [example](/reference-sql/functions-reference/datasketches/apache-datasketches-hll-build#example)
in [APACHE\_DATASKETCHES\_HLL\_BUILD](/reference-sql/functions-reference/datasketches/apache-datasketches-hll-build):

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
SELECT APACHE_DATASKETCHES_HLL_ESTIMATE(a) AS estimate
FROM sketch_of_data_to_count
ORDER BY 1;
```

| estimate (BIGINT) |
| :---------------- |
| 3333526           |
| 5001149           |

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
SELECT APACHE_DATASKETCHES_HLL_ESTIMATE(APACHE_DATASKETCHES_HLL_MERGE(a)) AS estimate
FROM sketch_of_data_to_count;
```

| hll\_estimate (BIGINT) |
| :--------------------- |
| 6673219                |
