- Categories:
Aggregate functions (Percentile Estimation) , Window function syntax and usage
APPROX_PERCENTILE_ACCUMULATE¶
Returns the internal representation of the t-Digest state (as a JSON object) at the end of aggregation. (For more information about t-Digest, see: Estimating Percentile Values.)
The function APPROX_PERCENTILE discards this internal, intermediate state when the final percentile estimate is returned. However, in certain advanced use cases, such as estimating incremental percentile during bulk loading, you may wish to keep the intermediate state, in which case you would use APPROX_PERCENTILE_ACCUMULATE instead of APPROX_PERCENTILE.
APPROX_PERCENTILE_ACCUMULATE does not return a percentile value. Instead, it returns the algorithm state itself. The intermediate state can later be:
Combined (i.e. merged) with other intermediate states from separate but related batches of data.
Processed by other functions that operate directly on the intermediate state, for example, APPROX_PERCENTILE_ESTIMATE. (For an example, see the Examples section below.)
Exported to external tools.
Syntax¶
Arguments¶
exprA valid expression, such as a column name, that evaluates to a numeric value.
Usage notes¶
Percentile works only on numeric values, so
exprshould produce values that are numbers or can be cast to numbers.
Decimal-float (DECFLOAT) values aren’t supported.
Example¶
Store the t-Digest state of the testtable.c1 column in a table and then use the state to compute percentiles:
Here is a more extensive example that shows the usage of all three related functions: APPROX_PERCENTILE_ACCUMULATE, APPROX_PERCENTILE_ESTIMATE, and APPROX_PERCENTILE_COMBINE.
Create a simple table and data:
Create a table that contains the “state” that represents the current
approximate percentile information for the table named test_table1:
Use that state information to display the current estimate of the median value (0.5 means that we want the value at the 50th percentile):
Now create a second table and add data. (In a more realistic situation, the user could have loaded more data into the first table and divided the data into non-overlapping sets based on the time that the data was loaded.)
Get the “state” information for just the new data.
Combine the “state” information for the two batches of rows:
Get the approximate median value of the combined set of rows: