Search in sources :

Example 6 with InputFunction

use of com.facebook.presto.spi.function.InputFunction in project presto by prestodb.

the class ApproximateLongPercentileAggregations method weightedInput.

@InputFunction
public static void weightedInput(@AggregationState DigestAndPercentileState state, @SqlType(StandardTypes.BIGINT) long value, @SqlType(StandardTypes.BIGINT) long weight, @SqlType(StandardTypes.DOUBLE) double percentile, @SqlType(StandardTypes.DOUBLE) double accuracy) {
    checkWeight(weight);
    QuantileDigest digest = state.getDigest();
    if (digest == null) {
        if (accuracy > 0 && accuracy < 1) {
            digest = new QuantileDigest(accuracy);
        } else {
            throw new IllegalArgumentException("Percentile accuracy must be strictly between 0 and 1");
        }
        state.setDigest(digest);
        state.addMemoryUsage(digest.estimatedInMemorySizeInBytes());
    }
    state.addMemoryUsage(-digest.estimatedInMemorySizeInBytes());
    digest.add(value, weight);
    state.addMemoryUsage(digest.estimatedInMemorySizeInBytes());
    // use last percentile
    state.setPercentile(percentile);
}
Also used : QuantileDigest(io.airlift.stats.QuantileDigest) InputFunction(com.facebook.presto.spi.function.InputFunction)

Example 7 with InputFunction

use of com.facebook.presto.spi.function.InputFunction in project presto by prestodb.

the class ApproximateLongPercentileArrayAggregations method input.

@InputFunction
public static void input(@AggregationState DigestAndPercentileArrayState state, @SqlType(StandardTypes.BIGINT) long value, @SqlType("array(double)") Block percentilesArrayBlock) {
    initializePercentilesArray(state, percentilesArrayBlock);
    initializeDigest(state);
    QuantileDigest digest = state.getDigest();
    state.addMemoryUsage(-digest.estimatedInMemorySizeInBytes());
    digest.add(value);
    state.addMemoryUsage(digest.estimatedInMemorySizeInBytes());
}
Also used : QuantileDigest(io.airlift.stats.QuantileDigest) InputFunction(com.facebook.presto.spi.function.InputFunction)

Example 8 with InputFunction

use of com.facebook.presto.spi.function.InputFunction 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());
}
Also used : HyperLogLog(io.airlift.stats.cardinality.HyperLogLog) InputFunction(com.facebook.presto.spi.function.InputFunction)

Example 9 with InputFunction

use of com.facebook.presto.spi.function.InputFunction 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());
}
Also used : HyperLogLog(io.airlift.stats.cardinality.HyperLogLog) InputFunction(com.facebook.presto.spi.function.InputFunction)

Example 10 with InputFunction

use of com.facebook.presto.spi.function.InputFunction in project presto by prestodb.

the class ApproximateLongPercentileAggregations method input.

@InputFunction
public static void input(@AggregationState DigestAndPercentileState state, @SqlType(StandardTypes.BIGINT) long value, @SqlType(StandardTypes.DOUBLE) double percentile) {
    QuantileDigest digest = state.getDigest();
    if (digest == null) {
        digest = new QuantileDigest(0.01);
        state.setDigest(digest);
        state.addMemoryUsage(digest.estimatedInMemorySizeInBytes());
    }
    state.addMemoryUsage(-digest.estimatedInMemorySizeInBytes());
    digest.add(value);
    state.addMemoryUsage(digest.estimatedInMemorySizeInBytes());
    // use last percentile
    state.setPercentile(percentile);
}
Also used : QuantileDigest(io.airlift.stats.QuantileDigest) InputFunction(com.facebook.presto.spi.function.InputFunction)

Aggregations

InputFunction (com.facebook.presto.spi.function.InputFunction)10 HyperLogLog (io.airlift.stats.cardinality.HyperLogLog)6 QuantileDigest (io.airlift.stats.QuantileDigest)4 LiteralParameters (com.facebook.presto.spi.function.LiteralParameters)1