Class AggregateFunction

java.lang.Object
com.google.cloud.firestore.pipeline.expressions.AggregateFunction

@BetaApi public class AggregateFunction extends Object
A class that represents an aggregate function.
  • Method Details

    • rawAggregate

      @BetaApi 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 - The name of the aggregation function.
      expr - The expressions to pass as arguments to the function.
      Returns:
      A new AggregateFunction for the specified function.
    • countAll

      @BetaApi public static AggregateFunction countAll()
      Creates an aggregation that counts the total number of stage inputs.
      Returns:
      A new AggregateFunction representing the countAll aggregation.
    • count

      @BetaApi public static AggregateFunction count(String fieldName)
      Creates an aggregation that counts the number of stage inputs where the input field exists.
      Parameters:
      fieldName - The name of the field to count.
      Returns:
      A new AggregateFunction representing the 'count' aggregation.
    • count

      @BetaApi public static AggregateFunction count(Expression expression)
      Creates an aggregation that counts the number of stage inputs with valid evaluations of the provided expression.
      Parameters:
      expression - The expression to count.
      Returns:
      A new AggregateFunction representing the 'count' aggregation.
    • countDistinct

      @BetaApi public static AggregateFunction countDistinct(String fieldName)
      Creates an aggregation that counts the number of distinct values of a field across multiple stage inputs.
      Parameters:
      fieldName - The name of the field to count the distinct values of.
      Returns:
      A new AggregateFunction representing the count distinct aggregation.
    • countDistinct

      @BetaApi public static AggregateFunction countDistinct(Expression expression)
      Creates an aggregation that counts the number of distinct values of an expression across multiple stage inputs.
      Parameters:
      expression - The expression to count the distinct values of.
      Returns:
      A new AggregateFunction representing the count distinct aggregation.
    • countIf

      @BetaApi public static AggregateFunction countIf(BooleanExpression condition)
      Creates an aggregation that counts the number of stage inputs where the provided boolean expression evaluates to true.
      Parameters:
      condition - The boolean expression to evaluate on each input.
      Returns:
      A new AggregateFunction representing the count aggregation.
    • sum

      @BetaApi public static AggregateFunction sum(String fieldName)
      Creates an aggregation that calculates the sum of a field's values across multiple stage inputs.
      Parameters:
      fieldName - The name of the field containing numeric values to sum up.
      Returns:
      A new AggregateFunction representing the sum aggregation.
    • sum

      @BetaApi public static AggregateFunction sum(Expression expression)
      Creates an aggregation that calculates the sum of values from an expression across multiple stage inputs.
      Parameters:
      expression - The expression to sum up.
      Returns:
      A new AggregateFunction representing the sum aggregation.
    • average

      @BetaApi public static AggregateFunction average(String fieldName)
      Creates an aggregation that calculates the average (mean) of a field's values across multiple stage inputs.
      Parameters:
      fieldName - The name of the field containing numeric values to average.
      Returns:
      A new AggregateFunction representing the average aggregation.
    • average

      @BetaApi public static AggregateFunction average(Expression expression)
      Creates an aggregation that calculates the average (mean) of values from an expression across multiple stage inputs.
      Parameters:
      expression - The expression representing the values to average.
      Returns:
      A new AggregateFunction representing the average aggregation.
    • minimum

      @BetaApi public static AggregateFunction minimum(String fieldName)
      Creates an aggregation that finds the minimum value of a field across multiple stage inputs.
      Parameters:
      fieldName - The name of the field to find the minimum value of.
      Returns:
      A new AggregateFunction representing the minimum aggregation.
    • minimum

      @BetaApi public static AggregateFunction minimum(Expression expression)
      Creates an aggregation that finds the minimum value of an expression across multiple stage inputs.
      Parameters:
      expression - The expression to find the minimum value of.
      Returns:
      A new AggregateFunction representing the minimum aggregation.
    • maximum

      @BetaApi public static AggregateFunction maximum(String fieldName)
      Creates an aggregation that finds the maximum value of a field across multiple stage inputs.
      Parameters:
      fieldName - The name of the field to find the maximum value of.
      Returns:
      A new AggregateFunction representing the maximum aggregation.
    • maximum

      @BetaApi public static AggregateFunction maximum(Expression expression)
      Creates an aggregation that finds the maximum value of an expression across multiple stage inputs.
      Parameters:
      expression - The expression to find the maximum value of.
      Returns:
      A new AggregateFunction representing the maximum aggregation.
    • first

      @BetaApi public static AggregateFunction first(String fieldName)
      Creates an aggregation that finds the first value of a field across multiple stage inputs.
      Parameters:
      fieldName - The name of the field to find the first value of.
      Returns:
      A new AggregateFunction representing the first aggregation.
    • first

      @BetaApi public static AggregateFunction first(Expression expression)
      Creates an aggregation that finds the first value of an expression across multiple stage inputs.
      Parameters:
      expression - The expression to find the first value of.
      Returns:
      A new AggregateFunction representing the first aggregation.
    • last

      @BetaApi public static AggregateFunction last(String fieldName)
      Creates an aggregation that finds the last value of a field across multiple stage inputs.
      Parameters:
      fieldName - The name of the field to find the last value of.
      Returns:
      A new AggregateFunction representing the last aggregation.
    • last

      @BetaApi public static AggregateFunction last(Expression expression)
      Creates an aggregation that finds the last value of an expression across multiple stage inputs.
      Parameters:
      expression - The expression to find the last value of.
      Returns:
      A new AggregateFunction representing the last aggregation.
    • arrayAgg

      @BetaApi 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.

      Parameters:
      fieldName - The name of the field to collect values from.
      Returns:
      A new AggregateFunction representing the array_agg aggregation.
    • arrayAgg

      @BetaApi 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.

      Parameters:
      expression - The expression to collect values from.
      Returns:
      A new AggregateFunction representing the array_agg aggregation.
    • arrayAggDistinct

      @BetaApi 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.

      Parameters:
      fieldName - The name of the field to collect values from.
      Returns:
      A new AggregateFunction representing the array_agg_distinct aggregation.
    • arrayAggDistinct

      @BetaApi 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.

      Parameters:
      expression - The expression to collect values from.
      Returns:
      A new AggregateFunction representing the array_agg_distinct aggregation.
    • as

      @BetaApi public AliasedAggregate as(String alias)
      Assigns an alias to this aggregate.
      Parameters:
      alias - The alias to assign to this aggregate.
      Returns:
      A new AliasedAggregate that wraps this aggregate and associates it with the provided alias.