Search in sources :

Example 26 with QuantileDigest

use of com.facebook.airlift.stats.QuantileDigest in project presto by prestodb.

the class TestQuantileDigestFunctions method testGetValueAtQuantileBelowZero.

@Test(expectedExceptions = PrestoException.class, expectedExceptionsMessageRegExp = "Quantile should be within bounds \\[0, 1\\], was: -\\d+\\.\\d+")
public void testGetValueAtQuantileBelowZero() {
    QuantileDigest qdigest = new QuantileDigest(1);
    functionAssertions.assertFunction(format("value_at_quantile(CAST(X'%s' AS qdigest(bigint)), -0.2)", toHexString(qdigest)), BIGINT, null);
}
Also used : QuantileDigest(com.facebook.airlift.stats.QuantileDigest) Test(org.testng.annotations.Test)

Example 27 with QuantileDigest

use of com.facebook.airlift.stats.QuantileDigest in project presto by prestodb.

the class TestQuantileDigestFunctions method testQuantileAtValueBigintWithEmptyDigest.

@Test
public void testQuantileAtValueBigintWithEmptyDigest() {
    QuantileDigest qdigest = new QuantileDigest(1);
    functionAssertions.assertFunction(format("quantile_at_value(CAST(X'%s' AS qdigest(bigint)), 5)", toHexString(qdigest)), DOUBLE, null);
}
Also used : QuantileDigest(com.facebook.airlift.stats.QuantileDigest) Test(org.testng.annotations.Test)

Example 28 with QuantileDigest

use of com.facebook.airlift.stats.QuantileDigest in project presto by prestodb.

the class TestQuantileDigestFunctions method testQuantileAtValueBigint.

@Test
public void testQuantileAtValueBigint() {
    QuantileDigest qdigest = new QuantileDigest(1);
    addAll(qdigest, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
    functionAssertions.assertFunction(format("quantile_at_value(CAST(X'%s' AS qdigest(bigint)), 20)", toHexString(qdigest)), DOUBLE, null);
    functionAssertions.assertFunction(format("quantile_at_value(CAST(X'%s' AS qdigest(bigint)), 6)", toHexString(qdigest)), DOUBLE, 0.6);
    functionAssertions.assertFunction(format("quantile_at_value(CAST(X'%s' AS qdigest(bigint)), -1)", toHexString(qdigest)), DOUBLE, null);
}
Also used : QuantileDigest(com.facebook.airlift.stats.QuantileDigest) Test(org.testng.annotations.Test)

Example 29 with QuantileDigest

use of com.facebook.airlift.stats.QuantileDigest in project presto by prestodb.

the class QuantileDigestFunctions method scaleQuantileDigest.

private static Slice scaleQuantileDigest(Slice input, double scale) {
    checkCondition(scale > 0, INVALID_FUNCTION_ARGUMENT, "Scale factor should be positive.");
    QuantileDigest digest = new QuantileDigest(input);
    digest.scale(scale);
    return digest.serialize();
}
Also used : QuantileDigest(com.facebook.airlift.stats.QuantileDigest)

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