# Class AggregateFunction (3.43.1)

3.43.1 (latest) 3.41.0 3.38.0 3.37.0 3.36.0 3.35.1 3.33.4 3.32.2 3.31.9 3.30.11 3.28.0 3.27.2 3.26.5 3.25.1 3.24.3 3.22.0 3.21.4 3.20.0 3.17.0 3.16.3 3.15.7 3.14.4 3.13.2 3.12.1 3.11.0 3.10.0 3.9.6 3.8.2 3.7.10 3.6.0 3.5.0 3.4.2 3.3.0 3.2.0 3.1.0 3.0.21

    public class AggregateFunction

A class that represents an aggregate function.

## Inheritance

[java.lang.Object](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html) \> AggregateFunction

## Inherited Members

[Object.clone()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#clone--) [Object.equals(Object)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#equals-java.lang.Object-) [Object.finalize()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#finalize--) [Object.getClass()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#getClass--) [Object.hashCode()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#hashCode--) [Object.notify()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notify--) [Object.notifyAll()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notifyAll--) [Object.toString()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#toString--) [Object.wait()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait--) [Object.wait(long)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-) [Object.wait(long,int)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-int-)

## Static Methods

### arrayAgg(Expression expression)

    public static AggregateFunction arrayAgg(Expression expression)

Creates an aggregation that collects all values of an expression across multiple stage inputs
into an array.

If the expression resolves to an absent value, it is converted to `null`. The order of
elements in the output array is not stable and shouldn't be relied upon.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `expression` | `https://docs.cloud.google.com/java/docs/reference/google-cloud-firestore/latest/com.google.cloud.firestore.pipeline.expressions.Expression` The expression to collect values from. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-firestore/latest/com.google.cloud.firestore.pipeline.expressions.AggregateFunction` | A new [AggregateFunction](https://docs.cloud.google.com/java/docs/reference/google-cloud-firestore/latest/com.google.cloud.firestore.pipeline.expressions.AggregateFunction) representing the array_agg aggregation. |

### arrayAgg(String fieldName)

    public static AggregateFunction arrayAgg(String fieldName)

Creates an aggregation that collects all values of a field across multiple stage inputs into an
array.

If the expression resolves to an absent value, it is converted to `null`. The order of
elements in the output array is not stable and shouldn't be relied upon.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `fieldName` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` The name of the field to collect values from. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-firestore/latest/com.google.cloud.firestore.pipeline.expressions.AggregateFunction` | A new [AggregateFunction](https://docs.cloud.google.com/java/docs/reference/google-cloud-firestore/latest/com.google.cloud.firestore.pipeline.expressions.AggregateFunction) representing the array_agg aggregation. |

### arrayAggDistinct(Expression expression)

    public static AggregateFunction arrayAggDistinct(Expression expression)

Creates an aggregation that collects all distinct values of an expression across multiple stage
inputs into an array.

If the expression resolves to an absent value, it is converted to `null`. The order of
elements in the output array is not stable and shouldn't be relied upon.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `expression` | `https://docs.cloud.google.com/java/docs/reference/google-cloud-firestore/latest/com.google.cloud.firestore.pipeline.expressions.Expression` The expression to collect values from. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-firestore/latest/com.google.cloud.firestore.pipeline.expressions.AggregateFunction` | A new [AggregateFunction](https://docs.cloud.google.com/java/docs/reference/google-cloud-firestore/latest/com.google.cloud.firestore.pipeline.expressions.AggregateFunction) representing the array_agg_distinct aggregation. |

### arrayAggDistinct(String fieldName)

    public static AggregateFunction arrayAggDistinct(String fieldName)

Creates an aggregation that collects all distinct values of a field across multiple stage
inputs into an array.

If the expression resolves to an absent value, it is converted to `null`. The order of
elements in the output array is not stable and shouldn't be relied upon.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `fieldName` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` The name of the field to collect values from. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-firestore/latest/com.google.cloud.firestore.pipeline.expressions.AggregateFunction` | A new [AggregateFunction](https://docs.cloud.google.com/java/docs/reference/google-cloud-firestore/latest/com.google.cloud.firestore.pipeline.expressions.AggregateFunction) representing the array_agg_distinct aggregation. |

### average(Expression expression)

    public static AggregateFunction average(Expression expression)

Creates an aggregation that calculates the average (mean) of values from an expression across
multiple stage inputs.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `expression` | `https://docs.cloud.google.com/java/docs/reference/google-cloud-firestore/latest/com.google.cloud.firestore.pipeline.expressions.Expression` The expression representing the values to average. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-firestore/latest/com.google.cloud.firestore.pipeline.expressions.AggregateFunction` | A new [AggregateFunction](https://docs.cloud.google.com/java/docs/reference/google-cloud-firestore/latest/com.google.cloud.firestore.pipeline.expressions.AggregateFunction) representing the average aggregation. |

### average(String fieldName)

    public static AggregateFunction average(String fieldName)

Creates an aggregation that calculates the average (mean) of a field's values across multiple
stage inputs.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `fieldName` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` The name of the field containing numeric values to average. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-firestore/latest/com.google.cloud.firestore.pipeline.expressions.AggregateFunction` | A new [AggregateFunction](https://docs.cloud.google.com/java/docs/reference/google-cloud-firestore/latest/com.google.cloud.firestore.pipeline.expressions.AggregateFunction) representing the average aggregation. |

### count(Expression expression)

    public static AggregateFunction count(Expression expression)

Creates an aggregation that counts the number of stage inputs with valid evaluations of the
provided `expression`.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `expression` | `https://docs.cloud.google.com/java/docs/reference/google-cloud-firestore/latest/com.google.cloud.firestore.pipeline.expressions.Expression` The expression to count. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-firestore/latest/com.google.cloud.firestore.pipeline.expressions.AggregateFunction` | A new [AggregateFunction](https://docs.cloud.google.com/java/docs/reference/google-cloud-firestore/latest/com.google.cloud.firestore.pipeline.expressions.AggregateFunction) representing the 'count' aggregation. |

### count(String fieldName)

    public static AggregateFunction count(String fieldName)

Creates an aggregation that counts the number of stage inputs where the input field exists.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `fieldName` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` The name of the field to count. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-firestore/latest/com.google.cloud.firestore.pipeline.expressions.AggregateFunction` | A new [AggregateFunction](https://docs.cloud.google.com/java/docs/reference/google-cloud-firestore/latest/com.google.cloud.firestore.pipeline.expressions.AggregateFunction) representing the 'count' aggregation. |

### countAll()

    public static AggregateFunction countAll()

Creates an aggregation that counts the total number of stage inputs.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-firestore/latest/com.google.cloud.firestore.pipeline.expressions.AggregateFunction` | A new [AggregateFunction](https://docs.cloud.google.com/java/docs/reference/google-cloud-firestore/latest/com.google.cloud.firestore.pipeline.expressions.AggregateFunction) representing the countAll aggregation. |

### countDistinct(Expression expression)

    public static AggregateFunction countDistinct(Expression expression)

Creates an aggregation that counts the number of distinct values of an expression across
multiple stage inputs.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `expression` | `https://docs.cloud.google.com/java/docs/reference/google-cloud-firestore/latest/com.google.cloud.firestore.pipeline.expressions.Expression` The expression to count the distinct values of. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-firestore/latest/com.google.cloud.firestore.pipeline.expressions.AggregateFunction` | A new [AggregateFunction](https://docs.cloud.google.com/java/docs/reference/google-cloud-firestore/latest/com.google.cloud.firestore.pipeline.expressions.AggregateFunction) representing the count distinct aggregation. |

### countDistinct(String fieldName)

    public static AggregateFunction countDistinct(String fieldName)

Creates an aggregation that counts the number of distinct values of a field across multiple
stage inputs.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `fieldName` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` The name of the field to count the distinct values of. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-firestore/latest/com.google.cloud.firestore.pipeline.expressions.AggregateFunction` | A new [AggregateFunction](https://docs.cloud.google.com/java/docs/reference/google-cloud-firestore/latest/com.google.cloud.firestore.pipeline.expressions.AggregateFunction) representing the count distinct aggregation. |

### countIf(BooleanExpression condition)

    public static AggregateFunction countIf(BooleanExpression condition)

Creates an aggregation that counts the number of stage inputs where the provided boolean
expression evaluates to true.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `condition` | `https://docs.cloud.google.com/java/docs/reference/google-cloud-firestore/latest/com.google.cloud.firestore.pipeline.expressions.BooleanExpression` The boolean expression to evaluate on each input. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-firestore/latest/com.google.cloud.firestore.pipeline.expressions.AggregateFunction` | A new [AggregateFunction](https://docs.cloud.google.com/java/docs/reference/google-cloud-firestore/latest/com.google.cloud.firestore.pipeline.expressions.AggregateFunction) representing the count aggregation. |

### first(Expression expression)

    public static AggregateFunction first(Expression expression)

Creates an aggregation that finds the first value of an expression across multiple stage
inputs.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `expression` | `https://docs.cloud.google.com/java/docs/reference/google-cloud-firestore/latest/com.google.cloud.firestore.pipeline.expressions.Expression` The expression to find the first value of. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-firestore/latest/com.google.cloud.firestore.pipeline.expressions.AggregateFunction` | A new [AggregateFunction](https://docs.cloud.google.com/java/docs/reference/google-cloud-firestore/latest/com.google.cloud.firestore.pipeline.expressions.AggregateFunction) representing the first aggregation. |

### first(String fieldName)

    public static AggregateFunction first(String fieldName)

Creates an aggregation that finds the first value of a field across multiple stage inputs.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `fieldName` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` The name of the field to find the first value of. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-firestore/latest/com.google.cloud.firestore.pipeline.expressions.AggregateFunction` | A new [AggregateFunction](https://docs.cloud.google.com/java/docs/reference/google-cloud-firestore/latest/com.google.cloud.firestore.pipeline.expressions.AggregateFunction) representing the first aggregation. |

### last(Expression expression)

    public static AggregateFunction last(Expression expression)

Creates an aggregation that finds the last value of an expression across multiple stage inputs.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `expression` | `https://docs.cloud.google.com/java/docs/reference/google-cloud-firestore/latest/com.google.cloud.firestore.pipeline.expressions.Expression` The expression to find the last value of. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-firestore/latest/com.google.cloud.firestore.pipeline.expressions.AggregateFunction` | A new [AggregateFunction](https://docs.cloud.google.com/java/docs/reference/google-cloud-firestore/latest/com.google.cloud.firestore.pipeline.expressions.AggregateFunction) representing the last aggregation. |

### last(String fieldName)

    public static AggregateFunction last(String fieldName)

Creates an aggregation that finds the last value of a field across multiple stage inputs.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `fieldName` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` The name of the field to find the last value of. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-firestore/latest/com.google.cloud.firestore.pipeline.expressions.AggregateFunction` | A new [AggregateFunction](https://docs.cloud.google.com/java/docs/reference/google-cloud-firestore/latest/com.google.cloud.firestore.pipeline.expressions.AggregateFunction) representing the last aggregation. |

### maximum(Expression expression)

    public static AggregateFunction maximum(Expression expression)

Creates an aggregation that finds the maximum value of an expression across multiple stage
inputs.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `expression` | `https://docs.cloud.google.com/java/docs/reference/google-cloud-firestore/latest/com.google.cloud.firestore.pipeline.expressions.Expression` The expression to find the maximum value of. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-firestore/latest/com.google.cloud.firestore.pipeline.expressions.AggregateFunction` | A new [AggregateFunction](https://docs.cloud.google.com/java/docs/reference/google-cloud-firestore/latest/com.google.cloud.firestore.pipeline.expressions.AggregateFunction) representing the maximum aggregation. |

### maximum(String fieldName)

    public static AggregateFunction maximum(String fieldName)

Creates an aggregation that finds the maximum value of a field across multiple stage inputs.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `fieldName` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` The name of the field to find the maximum value of. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-firestore/latest/com.google.cloud.firestore.pipeline.expressions.AggregateFunction` | A new [AggregateFunction](https://docs.cloud.google.com/java/docs/reference/google-cloud-firestore/latest/com.google.cloud.firestore.pipeline.expressions.AggregateFunction) representing the maximum aggregation. |

### minimum(Expression expression)

    public static AggregateFunction minimum(Expression expression)

Creates an aggregation that finds the minimum value of an expression across multiple stage
inputs.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `expression` | `https://docs.cloud.google.com/java/docs/reference/google-cloud-firestore/latest/com.google.cloud.firestore.pipeline.expressions.Expression` The expression to find the minimum value of. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-firestore/latest/com.google.cloud.firestore.pipeline.expressions.AggregateFunction` | A new [AggregateFunction](https://docs.cloud.google.com/java/docs/reference/google-cloud-firestore/latest/com.google.cloud.firestore.pipeline.expressions.AggregateFunction) representing the minimum aggregation. |

### minimum(String fieldName)

    public static AggregateFunction minimum(String fieldName)

Creates an aggregation that finds the minimum value of a field across multiple stage inputs.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `fieldName` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` The name of the field to find the minimum value of. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-firestore/latest/com.google.cloud.firestore.pipeline.expressions.AggregateFunction` | A new [AggregateFunction](https://docs.cloud.google.com/java/docs/reference/google-cloud-firestore/latest/com.google.cloud.firestore.pipeline.expressions.AggregateFunction) representing the minimum aggregation. |

### rawAggregate(String name, Expression\[\] expr)

    public static AggregateFunction rawAggregate(String name, Expression[] expr)

Creates a raw aggregation function.

This method provides a way to call aggregation functions that are supported by the Firestore
backend but that are not available as specific factory methods in this class.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `name` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` The name of the aggregation function. |
| `expr` | `https://docs.cloud.google.com/java/docs/reference/google-cloud-firestore/latest/com.google.cloud.firestore.pipeline.expressions.Expression[]` The expressions to pass as arguments to the function. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-firestore/latest/com.google.cloud.firestore.pipeline.expressions.AggregateFunction` | A new [AggregateFunction](https://docs.cloud.google.com/java/docs/reference/google-cloud-firestore/latest/com.google.cloud.firestore.pipeline.expressions.AggregateFunction) for the specified function. |

### sum(Expression expression)

    public static AggregateFunction sum(Expression expression)

Creates an aggregation that calculates the sum of values from an expression across multiple
stage inputs.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `expression` | `https://docs.cloud.google.com/java/docs/reference/google-cloud-firestore/latest/com.google.cloud.firestore.pipeline.expressions.Expression` The expression to sum up. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-firestore/latest/com.google.cloud.firestore.pipeline.expressions.AggregateFunction` | A new [AggregateFunction](https://docs.cloud.google.com/java/docs/reference/google-cloud-firestore/latest/com.google.cloud.firestore.pipeline.expressions.AggregateFunction) representing the sum aggregation. |

### sum(String fieldName)

    public static AggregateFunction sum(String fieldName)

Creates an aggregation that calculates the sum of a field's values across multiple stage
inputs.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `fieldName` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` The name of the field containing numeric values to sum up. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-firestore/latest/com.google.cloud.firestore.pipeline.expressions.AggregateFunction` | A new [AggregateFunction](https://docs.cloud.google.com/java/docs/reference/google-cloud-firestore/latest/com.google.cloud.firestore.pipeline.expressions.AggregateFunction) representing the sum aggregation. |

## Methods

### as(String alias)

    public AliasedAggregate as(String alias)

Assigns an alias to this aggregate.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `alias` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` The alias to assign to this aggregate. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-firestore/latest/com.google.cloud.firestore.pipeline.expressions.AliasedAggregate` | A new [AliasedAggregate](https://docs.cloud.google.com/java/docs/reference/google-cloud-firestore/latest/com.google.cloud.firestore.pipeline.expressions.AliasedAggregate) that wraps this aggregate and associates it with the provided alias. |