Search in sources :

Example 26 with TDigest

use of com.facebook.presto.tdigest.TDigest in project presto by prestodb.

the class TestTDigestFunctions method testScaleNegative.

@Test(expectedExceptions = PrestoException.class, expectedExceptionsMessageRegExp = "Scale factor should be positive\\.")
public void testScaleNegative() {
    TDigest tDigest = createTDigest(STANDARD_COMPRESSION_FACTOR);
    addAll(tDigest, 0.0d, 1.0d, 2.0d, 3.0d, 4.0d, 5.0d, 6.0d, 7.0d, 8.0d, 9.0d);
    functionAssertions.selectSingleValue(format("scale_tdigest(CAST(X'%s' AS tdigest(double)), -1)", new SqlVarbinary(tDigest.serialize().getBytes()).toString().replaceAll("\\s+", " ")), TDIGEST_DOUBLE, SqlVarbinary.class);
}
Also used : TDigest(com.facebook.presto.tdigest.TDigest) TDigest.createTDigest(com.facebook.presto.tdigest.TDigest.createTDigest) SqlVarbinary(com.facebook.presto.common.type.SqlVarbinary) Test(org.testng.annotations.Test)

Example 27 with TDigest

use of com.facebook.presto.tdigest.TDigest in project presto by prestodb.

the class TestTDigestAggregationFunction method getExpectedValueDoubles.

@Override
protected Object getExpectedValueDoubles(double compression, double... values) {
    if (values.length == 0) {
        return null;
    }
    TDigest tDigest = createTDigest(compression);
    Arrays.stream(values).forEach(tDigest::add);
    return new SqlVarbinary(tDigest.serialize().getBytes());
}
Also used : TDigest.createTDigest(com.facebook.presto.tdigest.TDigest.createTDigest) TDigest(com.facebook.presto.tdigest.TDigest) SqlVarbinary(com.facebook.presto.common.type.SqlVarbinary)

Aggregations

TDigest (com.facebook.presto.tdigest.TDigest)27 TDigest.createTDigest (com.facebook.presto.tdigest.TDigest.createTDigest)27 Test (org.testng.annotations.Test)21 ArrayList (java.util.ArrayList)18 NormalDistribution (org.apache.commons.math3.distribution.NormalDistribution)8 SqlVarbinary (com.facebook.presto.common.type.SqlVarbinary)6 BlockBuilder (com.facebook.presto.common.block.BlockBuilder)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 Block (com.facebook.presto.common.block.Block)1 ArrayType (com.facebook.presto.common.type.ArrayType)1 DoubleType (com.facebook.presto.common.type.DoubleType)1 Type (com.facebook.presto.common.type.Type)1 Centroid (com.facebook.presto.tdigest.Centroid)1 BinomialDistribution (org.apache.commons.math3.distribution.BinomialDistribution)1 GeometricDistribution (org.apache.commons.math3.distribution.GeometricDistribution)1 PoissonDistribution (org.apache.commons.math3.distribution.PoissonDistribution)1