Search in sources :

Example 11 with HyperLogLog

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

the class ApproximateCountDistinctAggregation method input.

@InputFunction
@TypeParameter("T")
public static void input(@OperatorDependency(operator = XX_HASH_64, argumentTypes = { "T" }) MethodHandle methodHandle, @AggregationState HyperLogLogState state, @SqlType("T") double value, @SqlType(StandardTypes.DOUBLE) double maxStandardError) {
    HyperLogLog hll = HyperLogLogUtils.getOrCreateHyperLogLog(state, maxStandardError);
    state.addMemoryUsage(-hll.estimatedInMemorySize());
    long hash;
    try {
        hash = (long) methodHandle.invokeExact(value);
    } catch (Throwable t) {
        throw internalError(t);
    }
    hll.addHash(hash);
    state.addMemoryUsage(hll.estimatedInMemorySize());
}
Also used : HyperLogLog(com.facebook.airlift.stats.cardinality.HyperLogLog) TypeParameter(com.facebook.presto.spi.function.TypeParameter) InputFunction(com.facebook.presto.spi.function.InputFunction)

Example 12 with HyperLogLog

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

the class ApproximateCountDistinctAggregation method input.

@InputFunction
@TypeParameter("T")
public static void input(@OperatorDependency(operator = XX_HASH_64, argumentTypes = { "T" }) MethodHandle methodHandle, @AggregationState HyperLogLogState state, @SqlType("T") long value, @SqlType(StandardTypes.DOUBLE) double maxStandardError) {
    HyperLogLog hll = HyperLogLogUtils.getOrCreateHyperLogLog(state, maxStandardError);
    state.addMemoryUsage(-hll.estimatedInMemorySize());
    long hash;
    try {
        hash = (long) methodHandle.invokeExact(value);
    } catch (Throwable t) {
        throw internalError(t);
    }
    hll.addHash(hash);
    state.addMemoryUsage(hll.estimatedInMemorySize());
}
Also used : HyperLogLog(com.facebook.airlift.stats.cardinality.HyperLogLog) TypeParameter(com.facebook.presto.spi.function.TypeParameter) InputFunction(com.facebook.presto.spi.function.InputFunction)

Example 13 with HyperLogLog

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

the class ApproximateCountDistinctAggregation method input.

@InputFunction
@TypeParameter("T")
public static void input(@OperatorDependency(operator = XX_HASH_64, argumentTypes = { "T" }) MethodHandle methodHandle, @AggregationState HyperLogLogState state, @SqlType("T") Slice value, @SqlType(StandardTypes.DOUBLE) double maxStandardError) {
    HyperLogLog hll = HyperLogLogUtils.getOrCreateHyperLogLog(state, maxStandardError);
    state.addMemoryUsage(-hll.estimatedInMemorySize());
    long hash;
    try {
        hash = (long) methodHandle.invokeExact(value);
    } catch (Throwable t) {
        throw internalError(t);
    }
    hll.addHash(hash);
    state.addMemoryUsage(hll.estimatedInMemorySize());
}
Also used : HyperLogLog(com.facebook.airlift.stats.cardinality.HyperLogLog) TypeParameter(com.facebook.presto.spi.function.TypeParameter) InputFunction(com.facebook.presto.spi.function.InputFunction)

Example 14 with HyperLogLog

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

the class HyperLogLogUtils method getOrCreateHyperLogLog.

public static HyperLogLog getOrCreateHyperLogLog(HyperLogLogState state, double maxStandardError) {
    HyperLogLog hll = state.getHyperLogLog();
    if (hll == null) {
        hll = HyperLogLog.newInstance(standardErrorToBuckets(maxStandardError));
        state.setHyperLogLog(hll);
        state.addMemoryUsage(hll.estimatedInMemorySize());
    }
    return hll;
}
Also used : HyperLogLog(com.facebook.airlift.stats.cardinality.HyperLogLog)

Example 15 with HyperLogLog

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

the class HyperLogLogUtils method mergeState.

public static void mergeState(@AggregationState HyperLogLogState state, HyperLogLog input) {
    HyperLogLog previous = state.getHyperLogLog();
    if (previous == null) {
        state.setHyperLogLog(input);
        state.addMemoryUsage(input.estimatedInMemorySize());
    } else {
        state.addMemoryUsage(-previous.estimatedInMemorySize());
        try {
            // Throws if the bucket counts are different.
            // We currently cannot access these counts from HLL so we must
            // catch and rethrow a more useful exception
            previous.mergeWith(input);
        } catch (IllegalArgumentException e) {
            throw new PrestoException(INVALID_FUNCTION_ARGUMENT, e.getMessage(), e);
        }
        state.addMemoryUsage(previous.estimatedInMemorySize());
    }
}
Also used : PrestoException(com.facebook.presto.spi.PrestoException) HyperLogLog(com.facebook.airlift.stats.cardinality.HyperLogLog)

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