stats_agg functions.
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
Calculate statistical properties
Create a statistical aggregate to summarize daily statistical data about the variableval1. Use the statistical
aggregate to calculate average, standard deviation, and skewness of the variable:
Available functions
Aggregate
stats_agg(): aggregate data into an intermediate statistical aggregate form for further calculation
Accessors
average(): calculate the average from a statistical aggregatestddev(): calculate the standard deviation from a statistical aggregatevariance(): calculate the variance from a statistical aggregateskewness(): calculate the skewness from a statistical aggregatekurtosis(): calculate the kurtosis from a statistical aggregatesum(): calculate the sum from a statistical aggregatenum_vals(): get the number of values contained in a statistical aggregate
Rollup
rollup(): combine multiple one-dimensional statistical aggregates
Mutator
rolling(): create a rolling window aggregate for use in window functions