Search in sources :

Example 1 with HyperLogLog

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

the class TestReadWrite method nextHyperLogLog.

private static Slice nextHyperLogLog(Random random) {
    HyperLogLog hll = HyperLogLog.newInstance(HYPER_LOG_LOG_BUCKETS);
    int size = random.nextInt(MAX_HYPER_LOG_LOG_ELEMENTS);
    for (int i = 0; i < size; i++) {
        hll.add(random.nextLong());
    }
    return hll.serialize();
}
Also used : HyperLogLog(com.facebook.airlift.stats.cardinality.HyperLogLog)

Example 2 with HyperLogLog

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

the class CreateHll method createHll.

@ScalarFunction
@SqlType(StandardTypes.HYPER_LOG_LOG)
public static Slice createHll(@SqlType(StandardTypes.BIGINT) long value) {
    HyperLogLog hll = HyperLogLog.newInstance(standardErrorToBuckets(DEFAULT_STANDARD_ERROR));
    hll.add(value);
    return hll.serialize();
}
Also used : HyperLogLog(com.facebook.airlift.stats.cardinality.HyperLogLog) ScalarFunction(com.facebook.presto.spi.function.ScalarFunction) SqlType(com.facebook.presto.spi.function.SqlType)

Example 3 with HyperLogLog

use of com.facebook.airlift.stats.cardinality.HyperLogLog 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());
}
Also used : SqlVarbinary(com.facebook.presto.common.type.SqlVarbinary) HyperLogLog(com.facebook.airlift.stats.cardinality.HyperLogLog)

Example 4 with HyperLogLog

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

the class TestMergeHyperLogLogAggregation method getSequenceBlocks.

// use dense for expected and actual to assure same serialized bytes
@Override
public Block[] getSequenceBlocks(int start, int length) {
    BlockBuilder blockBuilder = HYPER_LOG_LOG.createBlockBuilder(null, length);
    for (int i = start; i < start + length; i++) {
        HyperLogLog hll = HyperLogLog.newInstance(NUMBER_OF_BUCKETS);
        hll.add(i);
        hll.makeDense();
        HYPER_LOG_LOG.writeSlice(blockBuilder, hll.serialize());
    }
    return new Block[] { blockBuilder.build() };
}
Also used : Block(com.facebook.presto.common.block.Block) HyperLogLog(com.facebook.airlift.stats.cardinality.HyperLogLog) BlockBuilder(com.facebook.presto.common.block.BlockBuilder)

Example 5 with HyperLogLog

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

the class KHyperLogLog method serialize.

public Slice serialize() {
    try (SliceOutput output = new DynamicSliceOutput(estimatedSerializedSize())) {
        List<Slice> hllSlices = new ArrayList<>();
        IntList hllSizes = new IntArrayList();
        int totalHllSize = 0;
        for (HyperLogLog hll : minhash.values()) {
            Slice serializedHll = hll.serialize();
            hllSlices.add(serializedHll);
            totalHllSize += serializedHll.length();
            hllSizes.add(serializedHll.length());
        }
        Slice hashesSlice = wrappedLongArray(minhash.keySet().toLongArray());
        Slice hllSizesSlice = wrappedIntArray(hllSizes.toIntArray());
        output.appendByte(VERSION_BYTE);
        output.appendInt(maxSize);
        output.appendInt(hllBuckets);
        output.appendInt(minhash.size());
        output.appendInt(totalHllSize);
        output.appendBytes(hllSizesSlice);
        output.appendBytes(hashesSlice);
        for (Slice hllSlice : hllSlices) {
            output.appendBytes(hllSlice);
        }
        return output.slice();
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
Also used : SliceOutput(io.airlift.slice.SliceOutput) DynamicSliceOutput(io.airlift.slice.DynamicSliceOutput) Slice(io.airlift.slice.Slice) ArrayList(java.util.ArrayList) IntArrayList(it.unimi.dsi.fastutil.ints.IntArrayList) DynamicSliceOutput(io.airlift.slice.DynamicSliceOutput) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) IntArrayList(it.unimi.dsi.fastutil.ints.IntArrayList) HyperLogLog(com.facebook.airlift.stats.cardinality.HyperLogLog) IntList(it.unimi.dsi.fastutil.ints.IntList)

Aggregations

HyperLogLog (com.facebook.airlift.stats.cardinality.HyperLogLog)25 InputFunction (com.facebook.presto.spi.function.InputFunction)6 Slice (io.airlift.slice.Slice)6 SqlType (com.facebook.presto.spi.function.SqlType)4 ScalarFunction (com.facebook.presto.spi.function.ScalarFunction)3 TypeParameter (com.facebook.presto.spi.function.TypeParameter)3 ImmutableList (com.google.common.collect.ImmutableList)3 SliceInput (io.airlift.slice.SliceInput)2 Block (com.facebook.presto.common.block.Block)1 BlockBuilder (com.facebook.presto.common.block.BlockBuilder)1 SqlVarbinary (com.facebook.presto.common.type.SqlVarbinary)1 PrestoException (com.facebook.presto.spi.PrestoException)1 Description (com.facebook.presto.spi.function.Description)1 LiteralParameters (com.facebook.presto.spi.function.LiteralParameters)1 ScalarOperator (com.facebook.presto.spi.function.ScalarOperator)1 SqlNullable (com.facebook.presto.spi.function.SqlNullable)1 DynamicSliceOutput (io.airlift.slice.DynamicSliceOutput)1 SliceOutput (io.airlift.slice.SliceOutput)1 IntArrayList (it.unimi.dsi.fastutil.ints.IntArrayList)1 IntList (it.unimi.dsi.fastutil.ints.IntList)1