use of com.facebook.presto.common.type.SqlVarbinary in project presto by prestodb.
the class TestMergeHyperLogLogAggregation method getExpectedValue.
@Override
public Object getExpectedValue(int start, int length) {
if (length == 0) {
return null;
}
HyperLogLog hll = HyperLogLog.newInstance(NUMBER_OF_BUCKETS);
for (int i = start; i < start + length; i++) {
hll.add(i);
}
hll.makeDense();
return new SqlVarbinary(hll.serialize().getBytes());
}
use of com.facebook.presto.common.type.SqlVarbinary 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.presto.common.type.SqlVarbinary in project presto by prestodb.
the class TestQuantileDigestAggregationFunction method testAggregationReal.
private void testAggregationReal(InternalAggregationFunction function, Page page, double maxError, float... inputs) {
assertAggregation(function, QDIGEST_EQUALITY, "test multiple positions", page, getExpectedValuesFloats(maxError, inputs));
// test scalars
List<Double> rows = Floats.asList(inputs).stream().sorted().map(Float::doubleValue).collect(Collectors.toList());
SqlVarbinary returned = (SqlVarbinary) AggregationTestUtils.aggregation(function, page);
assertPercentileWithinError(QDIGEST, StandardTypes.REAL, returned, maxError, rows, 0.1, 0.5, 0.9, 0.99);
}
use of com.facebook.presto.common.type.SqlVarbinary in project presto by prestodb.
the class TestQuantileDigestAggregationFunction method testAggregationDoubles.
@Override
protected void testAggregationDoubles(InternalAggregationFunction function, Page page, double maxError, double... inputs) {
assertAggregation(function, QDIGEST_EQUALITY, "test multiple positions", page, getExpectedValueDoubles(maxError, inputs));
// test scalars
List<Double> rows = Doubles.asList(inputs).stream().sorted().collect(Collectors.toList());
SqlVarbinary returned = (SqlVarbinary) AggregationTestUtils.aggregation(function, page);
assertPercentileWithinError(QDIGEST, StandardTypes.DOUBLE, returned, maxError, rows, 0.1, 0.5, 0.9, 0.99);
}
use of com.facebook.presto.common.type.SqlVarbinary in project presto by prestodb.
the class TestQuantileDigestFunctions method testScale.
@Test
public void testScale() {
QuantileDigest qdigest = new QuantileDigest(1);
addAll(qdigest, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
// Before scaling.
assertEquals(qdigest.getHistogram(asList(0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L)), asList(new QuantileDigest.Bucket(0, Double.NaN), new QuantileDigest.Bucket(1, 0), new QuantileDigest.Bucket(1, 1), new QuantileDigest.Bucket(1, 2), new QuantileDigest.Bucket(1, 3), new QuantileDigest.Bucket(1, 4), new QuantileDigest.Bucket(1, 5), new QuantileDigest.Bucket(1, 6), new QuantileDigest.Bucket(1, 7), new QuantileDigest.Bucket(1, 8), new QuantileDigest.Bucket(1, 9)));
// Scale up.
SqlVarbinary sqlVarbinary = functionAssertions.selectSingleValue(format("scale_qdigest(CAST(X'%s' AS qdigest(bigint)), 2)", toHexString(qdigest)), QDIGEST_BIGINT, SqlVarbinary.class);
QuantileDigest scaledQdigest = new QuantileDigest(wrappedBuffer(sqlVarbinary.getBytes()));
assertEquals(scaledQdigest.getHistogram(asList(0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L)), asList(new QuantileDigest.Bucket(0, Double.NaN), new QuantileDigest.Bucket(2, 0), new QuantileDigest.Bucket(2, 1), new QuantileDigest.Bucket(2, 2), new QuantileDigest.Bucket(2, 3), new QuantileDigest.Bucket(2, 4), new QuantileDigest.Bucket(2, 5), new QuantileDigest.Bucket(2, 6), new QuantileDigest.Bucket(2, 7), new QuantileDigest.Bucket(2, 8), new QuantileDigest.Bucket(2, 9)));
// Scale down.
sqlVarbinary = functionAssertions.selectSingleValue(format("scale_qdigest(CAST(X'%s' AS qdigest(bigint)), 0.5)", toHexString(qdigest)), QDIGEST_BIGINT, SqlVarbinary.class);
scaledQdigest = new QuantileDigest(wrappedBuffer(sqlVarbinary.getBytes()));
assertEquals(scaledQdigest.getHistogram(asList(0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L)), asList(new QuantileDigest.Bucket(0, Double.NaN), new QuantileDigest.Bucket(0.5, 0), new QuantileDigest.Bucket(0.5, 1), new QuantileDigest.Bucket(0.5, 2), new QuantileDigest.Bucket(0.5, 3), new QuantileDigest.Bucket(0.5, 4), new QuantileDigest.Bucket(0.5, 5), new QuantileDigest.Bucket(0.5, 6), new QuantileDigest.Bucket(0.5, 7), new QuantileDigest.Bucket(0.5, 8), new QuantileDigest.Bucket(0.5, 9)));
}
Aggregations