use of io.airlift.stats.cardinality.HyperLogLog in project presto by prestodb.
the class ApproximateCountDistinctAggregations method inputBinary.
@InputFunction
public static void inputBinary(@AggregationState HyperLogLogState state, @SqlType(StandardTypes.VARBINARY) Slice value, @SqlType(StandardTypes.DOUBLE) double maxStandardError) {
HyperLogLog hll = getOrCreateHyperLogLog(state, maxStandardError);
state.addMemoryUsage(-hll.estimatedInMemorySize());
hll.add(value);
state.addMemoryUsage(hll.estimatedInMemorySize());
}
use of io.airlift.stats.cardinality.HyperLogLog in project presto by prestodb.
the class ApproximateCountDistinctAggregations method getOrCreateHyperLogLog.
private 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;
}
use of io.airlift.stats.cardinality.HyperLogLog in project presto by prestodb.
the class ApproximateCountDistinctAggregations 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());
}
}
use of io.airlift.stats.cardinality.HyperLogLog in project presto by prestodb.
the class ApproximateCountDistinctAggregations method input.
@InputFunction
public static void input(@AggregationState HyperLogLogState state, @SqlType(StandardTypes.BIGINT) long value, @SqlType(StandardTypes.DOUBLE) double maxStandardError) {
HyperLogLog hll = getOrCreateHyperLogLog(state, maxStandardError);
state.addMemoryUsage(-hll.estimatedInMemorySize());
hll.add(value);
state.addMemoryUsage(hll.estimatedInMemorySize());
}
Aggregations