> 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/release-1.3.0/configuration-reference/functions/frequentstringssketch.md).

# FrequentStringsSketch

This section contains reference documentation for the FREQUENTSTRINGSSKETCH function.

`FREQUENTSTRINGSSKETCH` is an estimation data-sketch function which can be used to estimate the frequency of an item. It is based on [Apache Datasketches library](https://datasketches.apache.org/docs/Frequency/FrequentItemsOverview.html) and returns a serialized sketch object which can be merged with other sketches.

## Signature

> FREQUENTSTRINGSSKETCH(column, maxMapSize=256) -> Base64 encoded sketch object

* `column` (required): Name of the column to aggregate on. Needs to be a type which can be cast into 'STRING'.
* `maxMapSize`: This value specifies the maximum physical length of the internal hash map. The maxMapSize must be a power of 2 and the default value is 256.

## Usage Example

```sql
select FREQUENTSTRINGSSKETCH(AirlineID, 16) from airlineStats
```

| frequentstringssketch(AirlineID) |
| -------------------------------- |
| BAEKCAUAAAAOAA...                |

Which can be used, for example in Java as:

```java
byte[] byteArr = Base64.getDecoder().decode(encodedSketch);
ItemsSketch<String> sketch = ItemsSketch.getInstance(Memory.wrap(byteArr), new ArrayOfStringsSerDe());

ItemsSketch.Row[] items = sketch.getFrequentItems(ErrorType.NO_FALSE_NEGATIVES);
for (int i = 0; i < items.length; i++) {
  ItemsSketch.Row item = items[i];
  System.out.printf("Airline: %s, Frequency: %d %n", item.getItem(), item.getEstimate());
}
```

For more examples on the sketch API, refer to the Datasketches [documentation](https://datasketches.apache.org/docs/Frequency/FrequentItemsJavaExample.html).


---

# 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.pinot.apache.org/release-1.3.0/configuration-reference/functions/frequentstringssketch.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
