use of com.facebook.airlift.stats.QuantileDigest in project presto by prestodb.
the class TestMergeQuantileDigestFunction method getSequenceBlocks.
@Override
public Block[] getSequenceBlocks(int start, int length) {
Type type = QDIGEST.createType(ImmutableList.of(TypeParameter.of(DoubleType.DOUBLE)));
BlockBuilder blockBuilder = type.createBlockBuilder(null, length);
for (int i = start; i < start + length; i++) {
QuantileDigest qdigest = new QuantileDigest(0.0);
qdigest.add(i);
type.writeSlice(blockBuilder, qdigest.serialize());
}
return new Block[] { blockBuilder.build() };
}
use of com.facebook.airlift.stats.QuantileDigest in project presto by prestodb.
the class TestQuantileDigestAggregationFunction method getExpectedValueDoubles.
@Override
protected Object getExpectedValueDoubles(double maxError, double... values) {
if (values.length == 0) {
return null;
}
QuantileDigest qdigest = new QuantileDigest(maxError);
Arrays.stream(values).forEach(value -> qdigest.add(doubleToSortableLong(value)));
return new SqlVarbinary(qdigest.serialize().getBytes());
}
use of com.facebook.airlift.stats.QuantileDigest in project presto by prestodb.
the class QuantileDigestFunctions method valuesAtQuantilesReal.
@ScalarFunction("values_at_quantiles")
@Description("For each input q between [0, 1], find the value whose rank in the sorted sequence of the n values represented by the qdigest is qn.")
@SqlType("array(real)")
public static Block valuesAtQuantilesReal(@SqlType("qdigest(real)") Slice input, @SqlType("array(double)") Block percentilesArrayBlock) {
QuantileDigest digest = new QuantileDigest(input);
BlockBuilder output = REAL.createBlockBuilder(null, percentilesArrayBlock.getPositionCount());
for (int i = 0; i < percentilesArrayBlock.getPositionCount(); i++) {
REAL.writeLong(output, floatToRawIntBits(sortableIntToFloat((int) digest.getQuantile(DOUBLE.getDouble(percentilesArrayBlock, i)))));
}
return output.build();
}
use of com.facebook.airlift.stats.QuantileDigest in project presto by prestodb.
the class QuantileDigestFunctions method quantileAtValueBigint.
@ScalarFunction("quantile_at_value")
@Description("Given an input x between min/max values of qdigest, find which quantile is represented by that value")
@SqlType(StandardTypes.DOUBLE)
@SqlNullable
public static Double quantileAtValueBigint(@SqlType("qdigest(bigint)") Slice input, @SqlType(StandardTypes.BIGINT) long value) {
QuantileDigest digest = new QuantileDigest(input);
if (digest.getCount() == 0 || value > digest.getMax() || value < digest.getMin()) {
return null;
}
double bucketCount = digest.getHistogram(ImmutableList.of(value)).get(0).getCount();
return bucketCount / digest.getCount();
}
use of com.facebook.airlift.stats.QuantileDigest in project presto by prestodb.
the class QuantileDigestFunctions method valuesAtQuantilesDouble.
@ScalarFunction("values_at_quantiles")
@Description("For each input q between [0, 1], find the value whose rank in the sorted sequence of the n values represented by the qdigest is qn.")
@SqlType("array(double)")
public static Block valuesAtQuantilesDouble(@SqlType("qdigest(double)") Slice input, @SqlType("array(double)") Block percentilesArrayBlock) {
QuantileDigest digest = new QuantileDigest(input);
BlockBuilder output = DOUBLE.createBlockBuilder(null, percentilesArrayBlock.getPositionCount());
for (int i = 0; i < percentilesArrayBlock.getPositionCount(); i++) {
DOUBLE.writeDouble(output, sortableLongToDouble(digest.getQuantile(DOUBLE.getDouble(percentilesArrayBlock, i))));
}
return output.build();
}
Aggregations