Aggregate functions
Timestream for LiveAnalytics supports the following aggregate functions.
Function | Output data type | Description |
---|---|---|
arbitrary(x) |
[same as input] |
Returns an arbitrary non-null value of x, if one exists.
Example result: |
array_agg(x) |
array<[same as input] |
Returns an array created from the input x elements.
Example result: |
avg(x) |
double |
Returns the average (arithmetic mean) of all input values.
Example result: |
bool_and(boolean) every(boolean) |
boolean |
Returns TRUE if every input value is TRUE, otherwise FALSE.
Example result: |
bool_or(boolean) |
boolean |
Returns TRUE if any input value is TRUE, otherwise FALSE.
Example result: |
count(*) count(x) |
bigint |
count(*) returns the number of input rows. count(x) returns the number of non-null input values.
Example result: |
count_if(x) |
bigint |
Returns the number of TRUE input values.
Example result: |
geometric_mean(x) |
double |
Returns the geometric mean of all input values.
Example result: |
max_by(x, y) |
[same as x] |
Returns the value of x associated with the maximum value of y over all input values.
Example result: |
max_by(x, y, n) |
array<[same as x]> |
Returns n values of x associated with the n largest of all input values of y in descending order of y.
Example result: |
min_by(x, y) |
[same as x] |
Returns the value of x associated with the minimum value of y over all input values.
Example result: |
min_by(x, y, n) |
array<[same as x]> |
Returns n values of x associated with the n smallest of all input values of y in ascending order of y.
Example result: |
max(x) |
[same as input] |
Returns the maximum value of all input values.
Example result: |
max(x, n) |
array<[same as x]> |
Returns n largest values of all input values of x.
Example result: |
min(x) |
[same as input] |
Returns the minimum value of all input values.
Example result: |
min(x, n) |
array<[same as x]> |
Returns n smallest values of all input values of x.
Example result: |
sum(x) |
[same as input] |
Returns the sum of all input values.
Example result: |
bitwise_and_agg(x) |
bigint |
Returns the bitwise AND of all input values in 2s complement representation.
Example result: |
bitwise_or_agg(x) |
bigint |
Returns the bitwise OR of all input values in 2s complement representation.
Example result: |
approx_distinct(x) |
bigint |
Returns the approximate number of distinct input values. This function provides an approximation of count(DISTINCT x). Zero is returned if all input values are null. This function should produce a standard error of 2.3%, which is the standard deviation of the (approximately normal) error distribution over all possible sets. It does not guarantee an upper bound on the error for any specific input set.
Example result: |
approx_distinct(x, e) |
bigint |
Returns the approximate number of distinct input values. This function provides an approximation of count(DISTINCT x). Zero is returned if all input values are null. This function should produce a standard error of no more than e, which is the standard deviation of the (approximately normal) error distribution over all possible sets. It does not guarantee an upper bound on the error for any specific input set. The current implementation of this function requires that e be in the range of [0.0040625, 0.26000].
Example result: |
approx_percentile(x, percentage) |
[same as x] |
Returns the approximate percentile for all input values of x at the given percentage. The value of percentage must be between zero and one and must be constant for all input rows.
Example result: |
approx_percentile(x, percentages) |
array<[same as x]> |
Returns the approximate percentile for all input values of x at each of the specified percentages. Each element of the percentages array must be between zero and one, and the array must be constant for all input rows.
Example result: |
approx_percentile(x, w, percentage) |
[same as x] |
Returns the approximate weighed percentile for all input values of x using the per-item weight w at the percentage p. The weight must be an integer value of at least one. It is effectively a replication count for the value x in the percentile set. The value of p must be between zero and one and must be constant for all input rows.
Example result: |
approx_percentile(x, w, percentages) |
array<[same as x]> |
Returns the approximate weighed percentile for all input values of x using the per-item weight w at each of the given percentages specified in the array. The weight must be an integer value of at least one. It is effectively a replication count for the value x in the percentile set. Each element of the array must be between zero and one, and the array must be constant for all input rows.
Example result: |
approx_percentile(x, w, percentage, accuracy) |
[same as x] |
Returns the approximate weighed percentile for all input values of x using the per-item weight w at the percentage p, with a maximum rank error of accuracy. The weight must be an integer value of at least one. It is effectively a replication count for the value x in the percentile set. The value of p must be between zero and one and must be constant for all input rows. The accuracy must be a value greater than zero and less than one, and it must be constant for all input rows.
Example result: |
corr(y, x) |
double |
Returns correlation coefficient of input values.
Example result: |
covar_pop(y, x) |
double |
Returns the population covariance of input values.
Example result: |
covar_samp(y, x) |
double |
Returns the sample covariance of input values.
Example result: |
regr_intercept(y, x) |
double |
Returns linear regression intercept of input values. y is the dependent value. x is the independent value.
Example result: |
regr_slope(y, x) |
double |
Returns linear regression slope of input values. y is the dependent value. x is the independent value.
Example result: |
skewness(x) |
double |
Returns the skewness of all input values.
Example result: |
stddev_pop(x) |
double |
Returns the population standard deviation of all input values.
Example result: |
stddev_samp(x) stddev(x) |
double |
Returns the sample standard deviation of all input values.
Example result: |
var_pop(x) |
double |
Returns the population variance of all input values.
Example result: |
var_samp(x) variance(x) |
double |
Returns the sample variance of all input values.
Example result: |