Skip to content


AggregateExpression is an unevaluable expression that acts as a container (wrapper) for an AggregateFunction.

Creating Instance

AggregateExpression takes the following to be created:

AggregateExpression is created using apply utility.

Aggregate Filter Expression

AggregateExpression can be given an Expression for an aggregate filter.

The filter is assumed undefined by default when AggregateExpression is created.

A filter is used in Partial and Complete modes only (cf. AggUtils).

AggregationIterator initializes predicates with AggregateExpressions with filters when requested to generateProcessRow.


AggregateExpression is given an AggregateMode when created.


No prefix (in toString)

Used when:


No prefix (in toString)


  • Partial aggregation
  • partial_ prefix (in toString)


Creating AggregateExpression

  aggregateFunction: AggregateFunction,
  mode: AggregateMode,
  isDistinct: Boolean,
  filter: Option[Expression] = None): AggregateExpression

apply creates an AggregateExpression with an auto-generated ExprId.

apply is used when:

Human-Friendly Textual Representation

toString: String

toString returns the following text:

[prefix][name]([args]) FILTER (WHERE [predicate])

toString converts the mode to a prefix.

mode prefix
Partial partial_
PartialMerge merge_
Final or Complete (empty)

toString requests the AggregateFunction for the toAggString (with the isDistinct flag).

In the end, toString adds FILTER (WHERE [predicate]) based on the optional filter expression.