use of com.facebook.airlift.stats.QuantileDigest in project presto by prestodb.
the class TestQuantileDigestAggregationFunction method getExpectedValueLongs.
private Object getExpectedValueLongs(double maxError, long... values) {
if (values.length == 0) {
return null;
}
QuantileDigest qdigest = new QuantileDigest(maxError);
Arrays.stream(values).forEach(qdigest::add);
return new SqlVarbinary(qdigest.serialize().getBytes());
}
use of com.facebook.airlift.stats.QuantileDigest in project presto by prestodb.
the class ApproximateLongPercentileArrayAggregations method output.
@OutputFunction("array(bigint)")
public static void output(@AggregationState DigestAndPercentileArrayState state, BlockBuilder out) {
QuantileDigest digest = state.getDigest();
List<Double> percentiles = state.getPercentiles();
if (percentiles == null || digest == null) {
out.appendNull();
return;
}
BlockBuilder blockBuilder = out.beginBlockEntry();
for (int i = 0; i < percentiles.size(); i++) {
Double percentile = percentiles.get(i);
BIGINT.writeLong(blockBuilder, digest.getQuantile(percentile));
}
out.closeEntry();
}
use of com.facebook.airlift.stats.QuantileDigest in project presto by prestodb.
the class ApproximateLongPercentileArrayAggregations method combine.
@CombineFunction
public static void combine(@AggregationState DigestAndPercentileArrayState state, DigestAndPercentileArrayState otherState) {
QuantileDigest otherDigest = otherState.getDigest();
QuantileDigest digest = state.getDigest();
if (digest == null) {
state.setDigest(otherDigest);
state.addMemoryUsage(otherDigest.estimatedInMemorySizeInBytes());
} else {
state.addMemoryUsage(-digest.estimatedInMemorySizeInBytes());
digest.merge(otherDigest);
state.addMemoryUsage(digest.estimatedInMemorySizeInBytes());
}
state.setPercentiles(otherState.getPercentiles());
}
use of com.facebook.airlift.stats.QuantileDigest in project presto by prestodb.
the class ApproximateRealPercentileArrayAggregations method output.
@OutputFunction("array(real)")
public static void output(@AggregationState DigestAndPercentileArrayState state, BlockBuilder out) {
QuantileDigest digest = state.getDigest();
List<Double> percentiles = state.getPercentiles();
if (percentiles == null || digest == null) {
out.appendNull();
return;
}
BlockBuilder blockBuilder = out.beginBlockEntry();
for (int i = 0; i < percentiles.size(); i++) {
Double percentile = percentiles.get(i);
REAL.writeLong(blockBuilder, floatToRawIntBits(sortableIntToFloat((int) digest.getQuantile(percentile))));
}
out.closeEntry();
}
use of com.facebook.airlift.stats.QuantileDigest in project presto by prestodb.
the class ApproximateLongPercentileAggregations method combine.
@CombineFunction
public static void combine(@AggregationState DigestAndPercentileState state, DigestAndPercentileState otherState) {
QuantileDigest input = otherState.getDigest();
QuantileDigest previous = state.getDigest();
if (previous == null) {
state.setDigest(input);
state.addMemoryUsage(input.estimatedInMemorySizeInBytes());
} else {
state.addMemoryUsage(-previous.estimatedInMemorySizeInBytes());
previous.merge(input);
state.addMemoryUsage(previous.estimatedInMemorySizeInBytes());
}
state.setPercentile(otherState.getPercentile());
}
Aggregations