Two-step aggregation
This group of functions uses the two-step aggregation pattern. Rather than calculating the final result in one step, you first create an intermediate aggregate by using the aggregate function. Then, use any of the accessors on the intermediate aggregate to calculate a final result. You can also roll up multiple intermediate aggregates with the rollup functions. The two-step aggregation pattern has several advantages:- More efficient because multiple accessors can reuse the same aggregate
- Easier to reason about performance, because aggregation is separate from final computation
- Easier to understand when calculations can be rolled up into larger intervals, especially in window functions and continuous aggregates
- Perform retrospective analysis even when underlying data is dropped, because the intermediate aggregate stores extra information not available in the final result
Samples
One-dimensional statistical analysis
Calculate the average, standard deviation, and skewness of daily temperature readings:Two-dimensional regression analysis
Calculate the correlation coefficient and linear regression slope between two variables:Rolling window calculations
Calculate a 7-day rolling average using the rolling window function:Available functions
One-dimensional statistics
stats_agg() (one variable): analyze statistical properties of a single variable
Two-dimensional statistics and regression
stats_agg() (two variables): analyze statistical properties and linear regression of two variables