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();
}
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() };
}
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());
}
}
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;
}
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());
}
}
Aggregations