Search in sources :

Example 6 with HyperLogLog

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

the class KHyperLogLog method newInstance.

public static KHyperLogLog newInstance(Slice serialized) {
    requireNonNull(serialized, "serialized is null");
    SliceInput input = serialized.getInput();
    checkArgument(input.readByte() == VERSION_BYTE, "Unexpected version");
    Long2ObjectRBTreeMap<HyperLogLog> minhash = new Long2ObjectRBTreeMap<>();
    int maxSize = input.readInt();
    int hllBuckets = input.readInt();
    int minhashSize = input.readInt();
    int totalHllSize = input.readInt();
    int[] hllSizes = new int[minhashSize];
    long[] keys = new long[minhashSize];
    input.readBytes(wrappedIntArray(hllSizes));
    input.readBytes(wrappedLongArray(keys));
    Slice allSerializedHlls = input.readSlice(totalHllSize);
    int hllLength;
    int index = 0;
    for (int i = 0; i < minhashSize; i++) {
        Slice serializedHll;
        hllLength = hllSizes[i];
        serializedHll = allSerializedHlls.slice(index, hllLength);
        index += hllLength;
        minhash.put(keys[i], HyperLogLog.newInstance(serializedHll));
    }
    return new KHyperLogLog(maxSize, hllBuckets, minhash);
}
Also used : Long2ObjectRBTreeMap(it.unimi.dsi.fastutil.longs.Long2ObjectRBTreeMap) Slice(io.airlift.slice.Slice) SliceInput(io.airlift.slice.SliceInput) HyperLogLog(com.facebook.airlift.stats.cardinality.HyperLogLog)

Example 7 with HyperLogLog

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

the class KHyperLogLog method mergeWith.

public KHyperLogLog mergeWith(KHyperLogLog other) {
    LongIterator iterator = other.minhash.keySet().iterator();
    while (iterator.hasNext()) {
        long key = iterator.nextLong();
        HyperLogLog thisHll = minhash.get(key);
        HyperLogLog otherHll = other.minhash.get(key);
        if (minhash.containsKey(key)) {
            decreaseTotalHllSize(thisHll);
            thisHll.mergeWith(otherHll);
            increaseTotalHllSize(thisHll);
        } else {
            minhash.put(key, otherHll);
            increaseTotalHllSize(otherHll);
        }
    }
    removeOverflowEntries();
    return this;
}
Also used : LongIterator(it.unimi.dsi.fastutil.longs.LongIterator) HyperLogLog(com.facebook.airlift.stats.cardinality.HyperLogLog)

Example 8 with HyperLogLog

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

the class HyperLogLogOperators method castToP4Hll.

@ScalarOperator(CAST)
@SqlType(StandardTypes.P4_HYPER_LOG_LOG)
public static Slice castToP4Hll(@SqlType(StandardTypes.HYPER_LOG_LOG) Slice slice) {
    HyperLogLog hll = HyperLogLog.newInstance(slice);
    hll.makeDense();
    return hll.serialize();
}
Also used : HyperLogLog(com.facebook.airlift.stats.cardinality.HyperLogLog) ScalarOperator(com.facebook.presto.spi.function.ScalarOperator) SqlType(com.facebook.presto.spi.function.SqlType)

Example 9 with HyperLogLog

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

the class MergeHyperLogLogAggregation method input.

@InputFunction
public static void input(@AggregationState HyperLogLogState state, @SqlType(StandardTypes.HYPER_LOG_LOG) Slice value) {
    HyperLogLog input = HyperLogLog.newInstance(value);
    HyperLogLogUtils.mergeState(state, input);
}
Also used : HyperLogLog(com.facebook.airlift.stats.cardinality.HyperLogLog) InputFunction(com.facebook.presto.spi.function.InputFunction)

Example 10 with HyperLogLog

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

the class ApproximateSetAggregation method input.

@InputFunction
public static void input(@AggregationState HyperLogLogState state, @SqlType(StandardTypes.BIGINT) long value, @SqlType(StandardTypes.DOUBLE) double maxStandardError) {
    HyperLogLog hll = HyperLogLogUtils.getOrCreateHyperLogLog(state, maxStandardError);
    state.addMemoryUsage(-hll.estimatedInMemorySize());
    hll.add(value);
    state.addMemoryUsage(hll.estimatedInMemorySize());
}
Also used : HyperLogLog(com.facebook.airlift.stats.cardinality.HyperLogLog) InputFunction(com.facebook.presto.spi.function.InputFunction)

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