Search in sources :

Example 21 with QuantileDigest

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));
    }
}
Also used : QuantileDigest(com.facebook.airlift.stats.QuantileDigest) OutputFunction(com.facebook.presto.spi.function.OutputFunction)

Example 22 with QuantileDigest

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))));
    }
}
Also used : QuantileDigest(com.facebook.airlift.stats.QuantileDigest) OutputFunction(com.facebook.presto.spi.function.OutputFunction)

Example 23 with QuantileDigest

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);
}
Also used : QuantileDigest(com.facebook.airlift.stats.QuantileDigest) Test(org.testng.annotations.Test)

Example 24 with QuantileDigest

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);
}
Also used : QuantileDigest(com.facebook.airlift.stats.QuantileDigest) Test(org.testng.annotations.Test)

Example 25 with QuantileDigest

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);
}
Also used : QuantileDigest(com.facebook.airlift.stats.QuantileDigest) Test(org.testng.annotations.Test)

Aggregations

QuantileDigest (com.facebook.airlift.stats.QuantileDigest)29 Test (org.testng.annotations.Test)8 BlockBuilder (com.facebook.presto.common.block.BlockBuilder)7 OutputFunction (com.facebook.presto.spi.function.OutputFunction)6 SqlVarbinary (com.facebook.presto.common.type.SqlVarbinary)4 Description (com.facebook.presto.spi.function.Description)4 ScalarFunction (com.facebook.presto.spi.function.ScalarFunction)4 SqlType (com.facebook.presto.spi.function.SqlType)4 CombineFunction (com.facebook.presto.spi.function.CombineFunction)2 SliceInput (io.airlift.slice.SliceInput)2 Block (com.facebook.presto.common.block.Block)1 DoubleType (com.facebook.presto.common.type.DoubleType)1 Type (com.facebook.presto.common.type.Type)1 FloatingPointBitsConverterUtil.sortableLongToDouble (com.facebook.presto.operator.aggregation.FloatingPointBitsConverterUtil.sortableLongToDouble)1 SqlNullable (com.facebook.presto.spi.function.SqlNullable)1 ImmutableList (com.google.common.collect.ImmutableList)1