Search in sources :

Example 6 with HyperLogLog

use of io.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(io.airlift.stats.cardinality.HyperLogLog) ScalarOperator(com.facebook.presto.spi.function.ScalarOperator) SqlType(com.facebook.presto.spi.function.SqlType)

Example 7 with HyperLogLog

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

the class TestMergeHyperLogLogAggregation method getSequenceBlocks.

@Override
public Block[] getSequenceBlocks(int start, int length) {
    BlockBuilder blockBuilder = HYPER_LOG_LOG.createBlockBuilder(new BlockBuilderStatus(), length);
    for (int i = start; i < start + length; i++) {
        HyperLogLog hll = HyperLogLog.newInstance(NUMBER_OF_BUCKETS);
        hll.add(i);
        HYPER_LOG_LOG.writeSlice(blockBuilder, hll.serialize());
    }
    return new Block[] { blockBuilder.build() };
}
Also used : Block(com.facebook.presto.spi.block.Block) HyperLogLog(io.airlift.stats.cardinality.HyperLogLog) BlockBuilder(com.facebook.presto.spi.block.BlockBuilder) BlockBuilderStatus(com.facebook.presto.spi.block.BlockBuilderStatus)

Example 8 with HyperLogLog

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

the class MergeHyperLogLogAggregation method merge.

private static void merge(@AggregationState HyperLogLogState state, HyperLogLog input) {
    HyperLogLog previous = state.getHyperLogLog();
    if (previous == null) {
        state.setHyperLogLog(input);
        state.addMemoryUsage(input.estimatedInMemorySize());
    } else {
        state.addMemoryUsage(-previous.estimatedInMemorySize());
        previous.mergeWith(input);
        state.addMemoryUsage(previous.estimatedInMemorySize());
    }
}
Also used : HyperLogLog(io.airlift.stats.cardinality.HyperLogLog)

Example 9 with HyperLogLog

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

the class ApproximateSetAggregation method getOrCreateHyperLogLog.

private static HyperLogLog getOrCreateHyperLogLog(@AggregationState HyperLogLogState state) {
    HyperLogLog hll = state.getHyperLogLog();
    if (hll == null) {
        hll = newHyperLogLog();
        state.setHyperLogLog(hll);
        state.addMemoryUsage(hll.estimatedInMemorySize());
    }
    return hll;
}
Also used : HyperLogLog(io.airlift.stats.cardinality.HyperLogLog)

Example 10 with HyperLogLog

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

the class ApproximateSetAggregation method combineState.

@CombineFunction
public static void combineState(@AggregationState HyperLogLogState state, @AggregationState HyperLogLogState otherState) {
    HyperLogLog input = otherState.getHyperLogLog();
    HyperLogLog previous = state.getHyperLogLog();
    if (previous == null) {
        state.setHyperLogLog(input);
        state.addMemoryUsage(input.estimatedInMemorySize());
    } else {
        state.addMemoryUsage(-previous.estimatedInMemorySize());
        previous.mergeWith(input);
        state.addMemoryUsage(previous.estimatedInMemorySize());
    }
}
Also used : HyperLogLog(io.airlift.stats.cardinality.HyperLogLog) CombineFunction(com.facebook.presto.spi.function.CombineFunction)

Aggregations

HyperLogLog (io.airlift.stats.cardinality.HyperLogLog)14 InputFunction (com.facebook.presto.spi.function.InputFunction)6 CombineFunction (com.facebook.presto.spi.function.CombineFunction)2 SqlType (com.facebook.presto.spi.function.SqlType)2 Block (com.facebook.presto.spi.block.Block)1 BlockBuilder (com.facebook.presto.spi.block.BlockBuilder)1 BlockBuilderStatus (com.facebook.presto.spi.block.BlockBuilderStatus)1 LiteralParameters (com.facebook.presto.spi.function.LiteralParameters)1 ScalarFunction (com.facebook.presto.spi.function.ScalarFunction)1 ScalarOperator (com.facebook.presto.spi.function.ScalarOperator)1