use of com.facebook.presto.spi.function.Description in project presto by prestodb.
the class TDigestFunctions method scaleTDigestDouble.
@ScalarFunction(value = "scale_tdigest", visibility = EXPERIMENTAL)
@Description("Scale a t-digest according to a new weight")
@SqlType("tdigest(double)")
public static Slice scaleTDigestDouble(@SqlType("tdigest(double)") Slice input, @SqlType(StandardTypes.DOUBLE) double scale) {
checkCondition(scale > 0, INVALID_FUNCTION_ARGUMENT, "Scale factor should be positive.");
TDigest digest = createTDigest(input);
digest.scale(scale);
return digest.serialize();
}
use of com.facebook.presto.spi.function.Description in project presto by prestodb.
the class TDigestFunctions method valuesAtQuantilesDouble.
@ScalarFunction(value = "values_at_quantiles", visibility = EXPERIMENTAL)
@Description("For each input q between [0, 1], find the value whose rank in the sorted sequence of the n values represented by the tdigest is qn.")
@SqlType("array(double)")
public static Block valuesAtQuantilesDouble(@SqlType("tdigest(double)") Slice input, @SqlType("array(double)") Block percentilesArrayBlock) {
TDigest tDigest = createTDigest(input);
BlockBuilder output = DOUBLE.createBlockBuilder(null, percentilesArrayBlock.getPositionCount());
for (int i = 0; i < percentilesArrayBlock.getPositionCount(); i++) {
DOUBLE.writeDouble(output, tDigest.getQuantile(DOUBLE.getDouble(percentilesArrayBlock, i)));
}
return output.build();
}
use of com.facebook.presto.spi.function.Description in project presto by prestodb.
the class MathFunctions method poissonCdf.
@Description("Poisson cdf given the lambda (mean) parameter and value")
@ScalarFunction
@SqlType(StandardTypes.DOUBLE)
public static double poissonCdf(@SqlType(StandardTypes.DOUBLE) double lambda, @SqlType(StandardTypes.INTEGER) long value) {
checkCondition(value >= 0, INVALID_FUNCTION_ARGUMENT, "value must be a non-negative integer");
checkCondition(lambda > 0, INVALID_FUNCTION_ARGUMENT, "lambda must be greater than 0");
PoissonDistribution distribution = new PoissonDistribution(lambda);
return distribution.cumulativeProbability((int) value);
}
use of com.facebook.presto.spi.function.Description in project presto by prestodb.
the class MathFunctions method weibullCdf.
@Description("Weibull cdf given the a, b parameters and value")
@ScalarFunction
@SqlType(StandardTypes.DOUBLE)
public static double weibullCdf(@SqlType(StandardTypes.DOUBLE) double a, @SqlType(StandardTypes.DOUBLE) double b, @SqlType(StandardTypes.DOUBLE) double value) {
checkCondition(a > 0, INVALID_FUNCTION_ARGUMENT, "a must be greater than 0");
checkCondition(b > 0, INVALID_FUNCTION_ARGUMENT, "b must be greater than 0");
WeibullDistribution distribution = new WeibullDistribution(null, a, b, WeibullDistribution.DEFAULT_INVERSE_ABSOLUTE_ACCURACY);
return distribution.cumulativeProbability(value);
}
use of com.facebook.presto.spi.function.Description in project presto by prestodb.
the class MathFunctions method inverseChiSquaredCdf.
@Description("inverse of ChiSquared cdf given df parameter and probability")
@ScalarFunction
@SqlType(StandardTypes.DOUBLE)
public static double inverseChiSquaredCdf(@SqlType(StandardTypes.DOUBLE) double df, @SqlType(StandardTypes.DOUBLE) double p) {
checkCondition(p >= 0 && p <= 1, INVALID_FUNCTION_ARGUMENT, "p must be in the interval [0, 1]");
checkCondition(df > 0, INVALID_FUNCTION_ARGUMENT, "df must be greater than 0");
ChiSquaredDistribution distribution = new ChiSquaredDistribution(null, df, ChiSquaredDistribution.DEFAULT_INVERSE_ABSOLUTE_ACCURACY);
return distribution.inverseCumulativeProbability(p);
}
Aggregations