> For the complete documentation index, see [llms.txt](https://docs.pinot.apache.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.pinot.apache.org/functions/sketch/distinctcountcpcsketch.md).

# DISTINCTCOUNTCPCSKETCH

The [Compressed Probability Counting(CPC) Sketch](https://datasketches.apache.org/docs/CPC/CPC.html) enables extremely space-efficient cardinality estimation. The stored CPC sketch can consume about 40% less space than an HLL sketch of comparable accuracy. Pinot can aggregate multiple existing CPC sketches together to get a total distinct count or estimated directly from raw values.

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

## Signature

> distinctCountCpcSketch(**\<cpcSketchColumn>, \<cpcSketchParams>**) -> Long

* `cpcSketchColumn` (required): Name of the column to aggregate on.
* `cpcSketchParams` (required): Semicolon-separated parameter string for constructing the intermediate CPC sketches.
  * The supported parameters are:
  * `nominalEntries`: The nominal entries used to create the sketch. (Default 4096)
  * `accumulatorThreshold`: How many sketches should be kept in memory before merging. (Default 2)

## Usage Examples

These examples are based on the [Batch Quick Start](/start-here/quick-start.md#batch-processing).

```sql
select distinctCountCpcSketch(teamID) AS value
from baseballStats 
```

| value |
| ----- |
| 150   |

```sql
select distinctCountCpcSketch(teamID, 'nominalEntries=256;accumulatorThreshold=10') AS value
from baseballStats 
```

| value |
| ----- |
| 150   |

We can also extract estimates when combining CPC sketches together via `cpcSketchUnion` for more complex use cases:

```sql
select
  getCpcSketchEstimate(
    cpcSketchUnion(
	    distinctCountRawCpcSketch(teamID) FILTER (WHERE yearID = 2004),
	    distinctCountRawCpcSketch(teamID) FILTER (WHERE league = 'NL')
    )
  ) AS value
from baseballStats
```

| value |
| ----- |
| 58    |

This function can also be used with the multi-stage engine (MSE).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
