> 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/aggregation/arrayagg.md).

# ARRAYAGG

This section contains reference documentation for the ARRAYAGG function.

Aggregates values from rows into an array. Supports collecting values of type `INT`, `LONG`, `FLOAT`, `DOUBLE`, `BIG_DECIMAL`, `BOOLEAN`, `TIMESTAMP`, `STRING`, `JSON`, `BYTES`, and `UUID`. Use the optional `DISTINCT` keyword to collect only distinct values.

## Signature

> ARRAYAGG(colName)
>
> ARRAYAGG(DISTINCT colName)
>
> ARRAYAGG(colName, 'dataType')
>
> ARRAYAGG(colName, 'dataType', 'DISTINCT')

The `dataType` argument is optional. When it is omitted, Pinot infers it from the type of `colName` (the element type for a multi-value column); a `JSON` column is collected as `STRING`. If the inferred or supplied type is not supported, the query fails in the broker.

When provided, the `dataType` parameter must be one of: `INT`, `LONG`, `FLOAT`, `DOUBLE`, `BIG_DECIMAL`, `BOOLEAN`, `TIMESTAMP`, `STRING`, `JSON`, `BYTES`, or `UUID`. `JSON` values are collected as strings, and `UUID` values are returned in canonical UUID string form.

Distinct values can be collected either with the `DISTINCT` keyword inside the call (`ARRAYAGG(DISTINCT colName)`) or by passing `'DISTINCT'` as the trailing argument of the explicit-type form.

## Usage Examples

These examples are based on the [Batch Quick Start](https://docs.pinot.apache.org/start-here/quick-start.md#batch-processing).

```sql
select ARRAYAGG(yearID, 'INT') AS years
from baseballStats
WHERE playerName = 'Barry Bonds'
```

| years                                                        |
| ------------------------------------------------------------ |
| \[1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, ...] |

The `dataType` argument can be omitted; Pinot infers it from the column type:

```sql
select ARRAYAGG(yearID) AS years
from baseballStats
WHERE playerName = 'Barry Bonds'
```

| years                                                        |
| ------------------------------------------------------------ |
| \[1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, ...] |

```sql
select ARRAYAGG(league, 'STRING', 'DISTINCT') AS leagues
from baseballStats
WHERE playerName = 'Barry Bonds'
```

| leagues   |
| --------- |
| \[NL, AL] |

The `DISTINCT` keyword inside the call collects distinct values without an explicit `dataType`:

```sql
select ARRAYAGG(DISTINCT league) AS leagues
from baseballStats
WHERE playerName = 'Barry Bonds'
```

| leagues   |
| --------- |
| \[NL, AL] |

When the input column is multi-value, Pinot flattens each row's values into the output array before applying the optional distinct step.


---

# 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/functions/aggregation/arrayagg.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.
