use of com.facebook.airlift.stats.QuantileDigest in project presto by prestodb.
the class ApproximateLongPercentileAggregations method output.
@OutputFunction(StandardTypes.BIGINT)
public static void output(@AggregationState DigestAndPercentileState state, BlockBuilder out) {
QuantileDigest digest = state.getDigest();
double percentile = state.getPercentile();
if (digest == null || digest.getCount() == 0.0) {
out.appendNull();
} else {
checkState(percentile != -1.0, "Percentile is missing");
checkCondition(0 <= percentile && percentile <= 1, INVALID_FUNCTION_ARGUMENT, "Percentile must be between 0 and 1");
BIGINT.writeLong(out, digest.getQuantile(percentile));
}
}
use of com.facebook.airlift.stats.QuantileDigest in project presto by prestodb.
the class ApproximateRealPercentileAggregations method output.
@OutputFunction(StandardTypes.REAL)
public static void output(@AggregationState DigestAndPercentileState state, BlockBuilder out) {
QuantileDigest digest = state.getDigest();
double percentile = state.getPercentile();
if (digest == null || digest.getCount() == 0.0) {
out.appendNull();
} else {
checkState(percentile != -1.0, "Percentile is missing");
checkCondition(0 <= percentile && percentile <= 1, INVALID_FUNCTION_ARGUMENT, "Percentile must be between 0 and 1");
REAL.writeLong(out, floatToRawIntBits(sortableIntToFloat((int) digest.getQuantile(percentile))));
}
}
use of com.facebook.airlift.stats.QuantileDigest in project presto by prestodb.
the class TestQuantileDigestFunctions method testValueAtQuantileBigint.
@Test
public void testValueAtQuantileBigint() {
QuantileDigest qdigest = new QuantileDigest(1);
addAll(qdigest, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
functionAssertions.assertFunction(format("value_at_quantile(CAST(X'%s' AS qdigest(bigint)), 0.5)", toHexString(qdigest)), BIGINT, 5L);
}
use of com.facebook.airlift.stats.QuantileDigest in project presto by prestodb.
the class TestQuantileDigestFunctions method testScaleNegative.
@Test(expectedExceptions = PrestoException.class, expectedExceptionsMessageRegExp = "Scale factor should be positive\\.")
public void testScaleNegative() {
QuantileDigest qdigest = new QuantileDigest(1);
addAll(qdigest, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
functionAssertions.selectSingleValue(format("scale_qdigest(CAST(X'%s' AS qdigest(bigint)), -1)", toHexString(qdigest)), QDIGEST_BIGINT, SqlVarbinary.class);
}
use of com.facebook.airlift.stats.QuantileDigest in project presto by prestodb.
the class TestQuantileDigestFunctions method testGetValueAtQuantileOverOne.
@Test(expectedExceptions = PrestoException.class, expectedExceptionsMessageRegExp = "Quantile should be within bounds \\[0, 1\\], was: \\d+\\.\\d+")
public void testGetValueAtQuantileOverOne() {
QuantileDigest qdigest = new QuantileDigest(1);
functionAssertions.assertFunction(format("value_at_quantile(CAST(X'%s' AS qdigest(bigint)), 1.5)", toHexString(qdigest)), BIGINT, null);
}
Aggregations