# Sketch Functions

Pinot supports several sketch-based algorithms for approximate distinct counting and summarization. These functions trade a small amount of accuracy for significant memory and performance savings at scale.

For exact distinct counting, see [DISTINCTCOUNT](/functions/aggregation/distinctcount.md).

## CPC Sketch

The [Compressed Probability Counting (CPC) Sketch](https://datasketches.apache.org/docs/CPC/CPC.html) enables extremely space-efficient cardinality estimation — about 40% less space than an HLL sketch of comparable accuracy.

| Function                                                                    | Description                                         |
| --------------------------------------------------------------------------- | --------------------------------------------------- |
| [DISTINCTCOUNTCPCSKETCH](/functions/sketch/distinctcountcpcsketch.md)       | Returns approximate distinct count using CPC sketch |
| [DISTINCTCOUNTRAWCPCSKETCH](/functions/sketch/distinctcountrawcpcsketch.md) | Returns raw CPC sketch as hex string                |

## HyperLogLog Plus

HyperLogLogPlus (HLL++) provides approximate distinct counts with configurable precision (`p`, `sp` parameters).

| Function                                                                                         | Description                                          |
| ------------------------------------------------------------------------------------------------ | ---------------------------------------------------- |
| [DISTINCTCOUNTHLLPLUS](/functions/sketch/distinctcounthllplus.md)                                | Approximate distinct count using HLL++               |
| [DISTINCTCOUNTSMARTHLLPLUS](/functions/sketch/distinctcounthllplus.md#distinctcountsmarthllplus) | Starts exact and converts to HLL++ after a threshold |
| [DISTINCTCOUNTHLLPLUSMV](/functions/sketch/distinctcounthllplusmv.md)                            | HLL++ for multi-value columns                        |
| [DISTINCTCOUNTRAWHLLPLUS](/functions/sketch/distinctcountrawhllplus.md)                          | Returns serialized HLL++ sketch                      |
| [DISTINCTCOUNTRAWHLLPLUSMV](/functions/sketch/distinctcountrawhllplusmv.md)                      | Serialized HLL++ sketch for multi-value columns      |

## UltraLogLog

The [UltraLogLog Sketch](https://arxiv.org/abs/2308.16862) from Dynatrace requires less space than HyperLogLog and provides a simpler, faster estimator. Implemented via [Hash4j](https://github.com/dynatrace-oss/hash4j/tree/main).

| Function                                                        | Description                                         |
| --------------------------------------------------------------- | --------------------------------------------------- |
| [DISTINCTCOUNTULL](/functions/sketch/distinctcountull.md)       | Approximate distinct count using ULL (default p=12) |
| [DISTINCTCOUNTRAWULL](/functions/sketch/distinctcountrawull.md) | Returns serialized ULL sketch                       |

## Tuple Sketch

The [Tuple Sketch](https://datasketches.apache.org/docs/Tuple/TupleOverview.html) extends the Theta Sketch with additional summary values per entry, ideal for summarizing attributes like impressions or clicks.

| Function                                                                                            | Description                      |
| --------------------------------------------------------------------------------------------------- | -------------------------------- |
| [DISTINCTCOUNTTUPLESKETCH](/functions/sketch/distinctcounttuplesketch.md)                           | Distinct count from tuple sketch |
| [DISTINCTCOUNTRAWINTEGERSUMTUPLESKETCH](/functions/sketch/distinctcountrawintegersumtuplesketch.md) | Raw tuple sketch as hex          |
| [AVGVALUEINTEGERSUMTUPLESKETCH](/functions/sketch/avgvalueintegersumtuplesketch.md)                 | Average of summary values        |
| [SUMVALUESINTEGERSUMTUPLESKETCH](/functions/sketch/sumvaluesintegersumtuplesketch.md)               | Sum of summary values            |

## Frequency Sketches

| Function                                                            | Description                             |
| ------------------------------------------------------------------- | --------------------------------------- |
| [FREQUENTLONGSSKETCH](/functions/sketch/frequentlongssketch.md)     | Frequent items sketch for long values   |
| [FREQUENTSTRINGSSKETCH](/functions/sketch/frequentstringssketch.md) | Frequent items sketch for string values |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.pinot.apache.org/functions/sketch.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
