use of io.prestosql.spi.function.Description in project hetu-core by openlookeng.
the class GeoFunctions method stStartPoint.
@SqlNullable
@Description("Returns the first point of a LINESTRING geometry as a Point")
@ScalarFunction("ST_StartPoint")
@SqlType(GEOMETRY_TYPE_NAME)
public static Slice stStartPoint(@SqlType(GEOMETRY_TYPE_NAME) Slice input) {
OGCGeometry geometry = deserialize(input);
validateType("ST_StartPoint", geometry, EnumSet.of(LINE_STRING));
if (geometry.isEmpty()) {
return null;
}
MultiPath lines = (MultiPath) geometry.getEsriGeometry();
SpatialReference reference = geometry.getEsriSpatialReference();
return serialize(createFromEsriGeometry(lines.getPoint(0), reference));
}
use of io.prestosql.spi.function.Description in project hetu-core by openlookeng.
the class MathFunctions method betaCdf.
@Description("Beta cdf given the a, b parameters and value")
@ScalarFunction
@SqlType(StandardTypes.DOUBLE)
public static double betaCdf(@SqlType(StandardTypes.DOUBLE) double a, @SqlType(StandardTypes.DOUBLE) double b, @SqlType(StandardTypes.DOUBLE) double value) {
checkCondition(value >= 0 && value <= 1, INVALID_FUNCTION_ARGUMENT, "value must be 0 >= v >= 1");
checkCondition(a > 0 && b > 0, INVALID_FUNCTION_ARGUMENT, "a, b must be > 0");
BetaDistribution distribution = new BetaDistribution(null, a, b, BetaDistribution.DEFAULT_INVERSE_ABSOLUTE_ACCURACY);
return distribution.cumulativeProbability(value);
}
use of io.prestosql.spi.function.Description in project hetu-core by openlookeng.
the class MathFunctions method inverseBetaCdf.
@Description("inverse of Beta cdf given a, b parameters and probability")
@ScalarFunction
@SqlType(StandardTypes.DOUBLE)
public static double inverseBetaCdf(@SqlType(StandardTypes.DOUBLE) double a, @SqlType(StandardTypes.DOUBLE) double b, @SqlType(StandardTypes.DOUBLE) double p) {
checkCondition(p >= 0 && p <= 1, INVALID_FUNCTION_ARGUMENT, "p must be 0 >= p >= 1");
checkCondition(a > 0 && b > 0, INVALID_FUNCTION_ARGUMENT, "a, b must be > 0");
BetaDistribution distribution = new BetaDistribution(null, a, b, BetaDistribution.DEFAULT_INVERSE_ABSOLUTE_ACCURACY);
return distribution.inverseCumulativeProbability(p);
}
use of io.prestosql.spi.function.Description in project hetu-core by openlookeng.
the class MathFunctions method widthBucket.
@Description("The bucket number of a value given an array of bins")
@ScalarFunction("width_bucket")
@SqlType(StandardTypes.BIGINT)
public static long widthBucket(@SqlType(StandardTypes.DOUBLE) double operand, @SqlType("array(double)") Block bins) {
int numberOfBins = bins.getPositionCount();
checkCondition(numberOfBins > 0, INVALID_FUNCTION_ARGUMENT, "Bins cannot be an empty array");
checkCondition(!isNaN(operand), INVALID_FUNCTION_ARGUMENT, "Operand cannot be NaN");
int lower = 0;
int upper = numberOfBins;
int index;
double bin;
while (lower < upper) {
if (DOUBLE.getDouble(bins, lower) > DOUBLE.getDouble(bins, upper - 1)) {
throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "Bin values are not sorted in ascending order");
}
index = (lower + upper) / 2;
bin = DOUBLE.getDouble(bins, index);
if (!isFinite(bin)) {
throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "Bin value must be finite, got " + bin);
}
if (operand < bin) {
upper = index;
} else {
lower = index + 1;
}
}
return lower;
}
use of io.prestosql.spi.function.Description in project hetu-core by openlookeng.
the class QuantileDigestFunctions method valuesAtQuantilesBigint.
@ScalarFunction("values_at_quantiles")
@Description("For each input q between [0, 1], find the value whose rank in the sorted sequence of the n values represented by the qdigest is qn.")
@SqlType("array(bigint)")
public static Block valuesAtQuantilesBigint(@SqlType("qdigest(bigint)") Slice input, @SqlType("array(double)") Block percentilesArrayBlock) {
QuantileDigest digest = new QuantileDigest(input);
BlockBuilder output = BIGINT.createBlockBuilder(null, percentilesArrayBlock.getPositionCount());
for (int i = 0; i < percentilesArrayBlock.getPositionCount(); i++) {
BIGINT.writeLong(output, digest.getQuantile(DOUBLE.getDouble(percentilesArrayBlock, i)));
}
return output.build();
}
Aggregations