Description
TheState combinator
can be applied to the avg
function to produce an intermediate state of AggregateFunction(avg, T) type where
T is the specified type for the average.
Example usage
In this example, we’ll look at how we can use theAggregateFunction type,
together with the avgState function to aggregate website traffic data.
First create the source table for website traffic data:
avg can’t use the SimpleAggregateFunction type as it requires a complex
state (a sum and a count). We therefore use the AggregateFunction type:
page_performance:
avg_response_time column is of type AggregateFunction(avg, UInt32)
and stores intermediate state information. Also notice that the row data for the
avg_response_time isn’t useful to us and we see strange text characters such
as �, n, F, }. This is the terminals attempt to display binary data as text.
The reason for this is that AggregateFunction types store their state in a
binary format that’s optimized for efficient storage and computation, not for
human readability. This binary state contains all the information needed to
calculate the average.
To make use of it, use the Merge combinator: