@NotThreadSafe public class QuantileDigest extends Object
Implements http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.132.7343, a data structure for approximating quantiles by trading off error with memory requirements.
The size of the digest is adjusted dynamically to achieve the error bound and requires O(log2(U) / maxError) space, where U is the number of bits needed to represent the domain of the values added to the digest. The error is defined as the discrepancy between the real rank of the value returned in a quantile query and the rank corresponding to the queried quantile.
Thus, for a query for quantile q that returns value v, the error is |rank(v) - q * N| / N, where N is the number of elements added to the digest and rank(v) is the real rank of v
This class also supports exponential decay. The implementation is based on the ideas laid out in http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.159.3978
| Modifier and Type | Class and Description |
|---|---|
static class |
QuantileDigest.Bucket |
| Constructor and Description |
|---|
QuantileDigest(double maxError)
Create a QuantileDigest with a maximum error guarantee of "maxError" and no decay.
|
QuantileDigest(double maxError,
double alpha)
Create a QuantileDigest with a maximum error guarantee of "maxError" and exponential decay
with factor "alpha".
|
QuantileDigest(QuantileDigest other) |
QuantileDigest(io.airlift.slice.Slice serialized) |
| Modifier and Type | Method and Description |
|---|---|
void |
add(long value) |
void |
add(long value,
long count)
Adds a value to this digest.
|
int |
estimatedInMemorySizeInBytes() |
int |
estimatedSerializedSizeInBytes() |
double |
getAlpha() |
double |
getConfidenceFactor()
Computes the maximum error of the current digest
|
double |
getCount()
Number (decayed) of elements added to this quantile digest
|
List<QuantileDigest.Bucket> |
getHistogram(List<Long> bucketUpperBounds) |
long |
getMax() |
double |
getMaxError() |
long |
getMin() |
long |
getQuantile(double quantile)
Gets the value at the specified quantile +/- maxError.
|
long |
getQuantileLowerBound(double quantile) |
List<Long> |
getQuantiles(List<Double> quantiles) |
List<Long> |
getQuantilesLowerBound(List<Double> quantiles)
Get a lower bound on the quantiles for the given proportions.
|
List<Long> |
getQuantilesUpperBound(List<Double> quantiles)
Get an upper bound on the quantiles for the given proportions.
|
long |
getQuantileUpperBound(double quantile) |
void |
merge(QuantileDigest other) |
io.airlift.slice.Slice |
serialize() |
String |
toGraphviz() |
public QuantileDigest(double maxError)
Create a QuantileDigest with a maximum error guarantee of "maxError" and no decay.
maxError - the max error tolerancepublic QuantileDigest(double maxError,
double alpha)
Create a QuantileDigest with a maximum error guarantee of "maxError" and exponential decay with factor "alpha".
maxError - the max error tolerancealpha - the exponential decay factorpublic QuantileDigest(QuantileDigest other)
public QuantileDigest(io.airlift.slice.Slice serialized)
public double getMaxError()
public double getAlpha()
public void add(long value)
public void add(long value,
long count)
>= 0public void merge(QuantileDigest other)
public List<Long> getQuantilesLowerBound(List<Double> quantiles)
The input list of quantile proportions must be sorted in increasing order, and each value must be in the range [0, 1]
public List<Long> getQuantilesUpperBound(List<Double> quantiles)
The input list of quantile proportions must be sorted in increasing order, and each value must be in the range [0, 1]
public long getQuantile(double quantile)
public long getQuantileLowerBound(double quantile)
public long getQuantileUpperBound(double quantile)
public double getCount()
public List<QuantileDigest.Bucket> getHistogram(List<Long> bucketUpperBounds)
public long getMin()
public long getMax()
public int estimatedInMemorySizeInBytes()
public int estimatedSerializedSizeInBytes()
public io.airlift.slice.Slice serialize()
public double getConfidenceFactor()
public String toGraphviz()
Copyright © 2010-2017 Airlift. All Rights Reserved.