AggregateFunction

Aggregate functions have an implementation-defined intermediate state that can be serialized to an AggregateFunction(...) data type and stored in a table, usually, by means of a materialized view. The common way to produce an aggregate function state is by calling the aggregate function with the -State suffix. To get the final result of aggregation in the future, you must use the same aggregate function with the -Merge suffix.

AggregateFunction(name, types_of_arguments...): parametric data type.

Parameters

  • Name of the aggregate function. If the function is parametric, specify its parameters too.
  • Types of the aggregate function arguments.

Data Selection

When selecting data from AggregatingMergeTree table, use GROUP BY clause and the same aggregate functions as when inserting data, but using -Merge suffix.

An aggregate function with -Merge suffix takes a set of states, combines them, and returns the result of complete data aggregation.

For example, the following two queries return the same result:

SELECT uniq(UserID) FROM table

SELECT uniqMerge(state) FROM (SELECT uniqState(UserID) AS state FROM table GROUP BY RegionID)
Was this page helpful?
Updated