Search in sources :

Example 31 with Description

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();
}
Also used : TDigest.createTDigest(com.facebook.presto.tdigest.TDigest.createTDigest) TDigest(com.facebook.presto.tdigest.TDigest) ScalarFunction(com.facebook.presto.spi.function.ScalarFunction) Description(com.facebook.presto.spi.function.Description) SqlType(com.facebook.presto.spi.function.SqlType)

Example 32 with Description

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();
}
Also used : TDigest.createTDigest(com.facebook.presto.tdigest.TDigest.createTDigest) TDigest(com.facebook.presto.tdigest.TDigest) BlockBuilder(com.facebook.presto.common.block.BlockBuilder) ScalarFunction(com.facebook.presto.spi.function.ScalarFunction) Description(com.facebook.presto.spi.function.Description) SqlType(com.facebook.presto.spi.function.SqlType)

Example 33 with Description

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);
}
Also used : PoissonDistribution(org.apache.commons.math3.distribution.PoissonDistribution) DecimalOperators.modulusScalarFunction(com.facebook.presto.type.DecimalOperators.modulusScalarFunction) SqlScalarFunction(com.facebook.presto.metadata.SqlScalarFunction) ScalarFunction(com.facebook.presto.spi.function.ScalarFunction) Description(com.facebook.presto.spi.function.Description) SqlType(com.facebook.presto.spi.function.SqlType)

Example 34 with Description

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);
}
Also used : WeibullDistribution(org.apache.commons.math3.distribution.WeibullDistribution) DecimalOperators.modulusScalarFunction(com.facebook.presto.type.DecimalOperators.modulusScalarFunction) SqlScalarFunction(com.facebook.presto.metadata.SqlScalarFunction) ScalarFunction(com.facebook.presto.spi.function.ScalarFunction) Description(com.facebook.presto.spi.function.Description) SqlType(com.facebook.presto.spi.function.SqlType)

Example 35 with Description

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);
}
Also used : ChiSquaredDistribution(org.apache.commons.math3.distribution.ChiSquaredDistribution) DecimalOperators.modulusScalarFunction(com.facebook.presto.type.DecimalOperators.modulusScalarFunction) SqlScalarFunction(com.facebook.presto.metadata.SqlScalarFunction) ScalarFunction(com.facebook.presto.spi.function.ScalarFunction) Description(com.facebook.presto.spi.function.Description) SqlType(com.facebook.presto.spi.function.SqlType)

Aggregations

Description (com.facebook.presto.spi.function.Description)105 SqlType (com.facebook.presto.spi.function.SqlType)103 ScalarFunction (com.facebook.presto.spi.function.ScalarFunction)101 OGCGeometry (com.esri.core.geometry.ogc.OGCGeometry)41 SqlNullable (com.facebook.presto.spi.function.SqlNullable)37 OGCGeometry.createFromEsriGeometry (com.esri.core.geometry.ogc.OGCGeometry.createFromEsriGeometry)20 GeometryUtils.jsonFromJtsGeometry (com.facebook.presto.geospatial.GeometryUtils.jsonFromJtsGeometry)20 GeometryUtils.wktFromJtsGeometry (com.facebook.presto.geospatial.GeometryUtils.wktFromJtsGeometry)20 Geometry (org.locationtech.jts.geom.Geometry)20 BlockBuilder (com.facebook.presto.common.block.BlockBuilder)19 PrestoException (com.facebook.presto.spi.PrestoException)18 LiteralParameters (com.facebook.presto.spi.function.LiteralParameters)15 Slice (io.airlift.slice.Slice)15 SqlScalarFunction (com.facebook.presto.metadata.SqlScalarFunction)14 Constraint (com.facebook.presto.type.Constraint)14 DecimalOperators.modulusScalarFunction (com.facebook.presto.type.DecimalOperators.modulusScalarFunction)13 Point (com.esri.core.geometry.Point)10 SliceUtf8.lengthOfCodePoint (io.airlift.slice.SliceUtf8.lengthOfCodePoint)7 SliceUtf8.offsetOfCodePoint (io.airlift.slice.SliceUtf8.offsetOfCodePoint)7 Envelope (com.esri.core.geometry.Envelope)6